Jump to content

Erros Valgrind


ChewyMath
 Share

Recommended Posts

Boas,

Estive a testar a minha função que trabalha com strings no valgrind e deparei-me com uma novidade para mim.

==20080== Memcheck, a memory error detector
==20080== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==20080== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==20080== Command: ./a.out
==20080==
==20080== Conditional jump or move depends on uninitialised value(s)
==20080== at 0x402F914: strstr (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==20080== by 0x80486B8: filtraRep (in /home//Área de Trabalho//testes/a.out)
==20080== by 0x80488CF: main (in /home//Área de Trabalho//testes/a.out)
==20080==
==20080== Conditional jump or move depends on uninitialised value(s)
==20080== at 0x402CD37: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==20080== by 0x80486D1: filtraRep (in /home//Área de Trabalho//testes/a.out)
==20080== by 0x80488CF: main (in /home//Área de Trabalho//testes/a.out)
==20080==
* Nuno** Afonso** Nuno** Pedro** Afonso** Miguel** Miguel** Nuno*
==20080== Conditional jump or move depends on uninitialised value(s)
==20080== at 0x40956A5: vfprintf (vfprintf.c:1655)
==20080== by 0x409A81E: printf (printf.c:34)
==20080== by 0x4065934: (below main) (libc-start.c:260)
==20080==
# Nuno, Afonso, Pedro, Miguel,
==20080==
==20080== HEAP SUMMARY:
==20080==     in use at exit: 0 bytes in 0 blocks
==20080== total heap usage: 4 allocs, 4 frees, 74 bytes allocated
==20080==
==20080== All heap blocks were freed -- no leaks are possible
==20080==
==20080== For counts of detected and suppressed errors, rerun with: -v
==20080== Use --track-origins=yes to see where uninitialised values come from
==20080== ERROR SUMMARY: 7 errors from 3 contexts (suppressed: 0 from 0)

Penso que seja por estar a usar o seguinte código if( strstr(...) ) . Não sei até que ponto posso ignorar estes avisos.

char* filtraRep(char* stringFiltrada, char* stringCompleta){
char* apt;
char* sep = ",";
char* aux = NULL;
size_t len1 = 0;
size_t len2 = 0;
char *concat = NULL;
_Bool teste = 0;
for (apt = strtok(stringCompleta,sep); apt; apt = strtok(NULL,sep)){
    printf("*%s*",apt);
if(stringFiltrada != NULL){
    teste = !strstr(stringFiltrada, apt);
    if(teste){
        if(stringFiltrada != NULL)
        len1 = strlen (stringFiltrada);
        len2 = strlen (apt);
        concat = malloc(len1 + len2 + 2);

        memcpy(concat, stringFiltrada, len1);
        memcpy(concat+len1, apt, len2 + 1);
        memcpy(concat+len1+len2,sep,1);
        free(aux);
        }
}else{
len2 = strlen (apt);
concat = malloc(len1 + len2 + 2);
memcpy(concat, stringFiltrada, len1);
memcpy(concat+len1, apt, len2 + 1);
memcpy(concat+len1+len2,sep,1);
free(aux);
}
    stringFiltrada = concat;
    aux = concat;
}
return stringFiltrada;
}

Obrigado pela atenção.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.