ChewyMath Posted April 10, 2014 Report Share Posted April 10, 2014 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 More sharing options...
HappyHippyHippo Posted April 10, 2014 Report Share Posted April 10, 2014 apresenta o código que foi testado IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
ChewyMath Posted April 10, 2014 Author Report Share Posted April 10, 2014 adicionei ao post original. Não tenham medo por favor 😁 Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 10, 2014 Report Share Posted April 10, 2014 faz esta alteração : char* apt = NULL; IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
ChewyMath Posted April 10, 2014 Author Report Share Posted April 10, 2014 faz esta alteração : char* apt = NULL; nop continua igual. Exactamente o mesmo erro. Link to comment Share on other sites More sharing options...
ChewyMath Posted April 10, 2014 Author Report Share Posted April 10, 2014 Encontrei um problema vagamente parecido mas penso que nao tem nada a ver http://stackoverflow.com/questions/13709419/c-valgrind-conditional-jump-or-move-depends-on-uninitialised-values Aceitam-se sugestões. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 10, 2014 Report Share Posted April 10, 2014 resposta no link apresentado: If you run valgrind with --track-origins=yes, it'll tell you the conflicting variable and where it was allocated. IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
ChewyMath Posted April 10, 2014 Author Report Share Posted April 10, 2014 (edited) Peço desculpa estava a passar as flags de forma errada ao valgrind 😛 Não é muito útil pois devolve o mesmo relatório(igual ao do post original) Edited April 10, 2014 by ChewyMath Link to comment Share on other sites More sharing options...
ChewyMath Posted April 29, 2014 Author Report Share Posted April 29, 2014 Boas, Venho deixar a solução da minha dúvida , e passa apenas por fazer memset() depois no malloc(), ou então usar calloc(). PS: e claro os apontadores tem de estar todos inicializados a NULL. Obrigado 😉 1 Report Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now