I made this function:
void procesar_llamadaAFuncion(t_proceso *unProceso, char *sentencia){
char *nombreFuncion = sentencia;
char *nombreFuncionSinParentesis = NULL;
string_trim(&nombreFuncion);
nombreFuncionSinParentesis = malloc(sizeof(char)*(strlen(nombreFuncion)-2));
strncpy(nombreFuncionSinParentesis, nombreFuncion, strlen(nombreFuncion)-2);
puts(nombreFuncionSinParentesis);
push_stack(unProceso->pcb->seg_stack, nombreFuncionSinParentesis, unProceso->pcb->program_counter);
unProceso->pcb->program_counter = get_pos_funcion(unProceso->pcb->funciones, nombreFuncionSinParentesis);
free(nombreFuncion);
free(nombreFuncionSinParentesis);
It doesn't matter what t_proceso is, the problem is that this function receives an array of chars.
The array of chars that the function will receive its always "something()", what i am trying to do is to remove the two last characters "()" and then call the function push_stack().
The problem is that when I run Valgrind, i get this:
==17129== Invalid read of size 1
==17129== at 0x4C2BFD4: __GI_strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17129== by 0x50BFCEB: puts (ioputs.c:37)
==17129== by 0x403D30: procesar_llamadaAFuncion (proceso.c:455)
==17129== by 0x40313D: procesar_siguiente_instruccion (proceso.c:132)
==17129== by 0x404B1A: probarProcesos (test.c:83)
==17129== by 0x404C7F: main (test.c:111)
==17129== Address 0x5436da8 is 0 bytes after a block of size 8 alloc'd
==17129== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17129== by 0x403CDF: procesar_llamadaAFuncion (proceso.c:452)
==17129== by 0x40313D: procesar_siguiente_instruccion (proceso.c:132)
==17129== by 0x404B1A: probarProcesos (test.c:83)
==17129== by 0x404C7F: main (test.c:111)
I don't know what I am doing wrong, so any help will be appreciated.