|
From: Eric C. <Eri...@gi...> - 2021-09-03 19:46:50
|
Hi,
I have a simple test and valgrind seems to not see the error:
cat fread.cc && clang++ -o fread fread.cc && valgrind ./fread
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv){
int lA {1};
FILE * f = fopen ( argv[0] , "rb" );
fread(&lA,2*sizeof(int),1,f);
std::cout << "Hello: "<< lA << std::endl;
return 0;
}
==16241== Memcheck, a memory error detector
==16241== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16241== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==16241== Command: ./fread
==16241==
Hello: 1179403647
==16241==
==16241== HEAP SUMMARY:
==16241== in use at exit: 472 bytes in 1 blocks
==16241== total heap usage: 4 allocs, 3 frees, 78,296 bytes allocated
==16241==
==16241== LEAK SUMMARY:
==16241== definitely lost: 0 bytes in 0 blocks
==16241== indirectly lost: 0 bytes in 0 blocks
==16241== possibly lost: 0 bytes in 0 blocks
==16241== still reachable: 472 bytes in 1 blocks
==16241== suppressed: 0 bytes in 0 blocks
==16241== Rerun with --leak-check=full to see details of leaked memory
==16241==
==16241== For lists of detected and suppressed errors, rerun with: -s
==16241== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
We just discovered this error that we got into our code since many
years... and even if we use valgrind it didn't detected it...
Is there any command line options I can add to valgrind to make it
detect the error?
Thanks,
Eric
--
Eric Chamberland, ing., M. Ing
Professionnel de recherche
GIREF/Université Laval
(418) 656-2131 poste 41 22 42
|
|
From: John R. <jr...@bi...> - 2021-09-03 22:53:28
|
On 9/3/21 12:31 PM, Eric Chamberland wrote:
> Hi,
>
> I have a simple test and valgrind seems to not see the error:
>
> cat fread.cc && clang++ -o fread fread.cc && valgrind ./fread
> #include <iostream>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char ** argv){
> int lA {1};
> FILE * f = fopen ( argv[0] , "rb" );
> fread(&lA,2*sizeof(int),1,f);
> std::cout << "Hello: "<< lA << std::endl;
> return 0;
> }
This report is interesting only because it is a bad example:
it does not specify what is the supposed error.
If you don't say what you believe it is, then how are valgrind developers to know?
Besides, the "memcheck error" is covered in the valgrind FAQ.
Look it up in paragraph "4.6. Why doesn't Memcheck find ..."
The second and third errors are the logic errors of not checking
the return value of fopen and fread.
The fourth error is not documenting the expected invocation command line.
The fifth error is not checking argc.
The sixth error is not documenting the expected format of the input file.
Are you sure that you really are a programmer?
|
|
From: Eric C. <Eri...@gi...> - 2021-09-08 03:46:55
|
Hi John,
On 2021-09-03 6:53 p.m., John Reiser wrote:
> On 9/3/21 12:31 PM, Eric Chamberland wrote:
>> Hi,
>>
>> I have a simple test and valgrind seems to not see the error:
>>
>> cat fread.cc && clang++ -o fread fread.cc && valgrind ./fread
>> #include <iostream>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main(int argc, char ** argv){
>> int lA {1};
>> FILE * f = fopen ( argv[0] , "rb" );
>> fread(&lA,2*sizeof(int),1,f);
>> std::cout << "Hello: "<< lA << std::endl;
>> return 0;
>> }
>
> This report is interesting only because it is a bad example:
> it does not specify what is the supposed error.
> If you don't say what you believe it is, then how are valgrind
> developers to know?
Yes, indeed, sorry for not giving a good example!
>
> Besides, the "memcheck error" is covered in the valgrind FAQ.
> Look it up in paragraph "4.6. Why doesn't Memcheck find ..."
Ok, thanks, the answer was there :
https://valgrind.org/docs/manual/faq.html#faq.overruns
> The second and third errors are the logic errors of not checking
> the return value of fopen and fread.
> The fourth error is not documenting the expected invocation command line.
> The fifth error is not checking argc.
> The sixth error is not documenting the expected format of the input file.
> Are you sure that you really are a programmer?
I am happy with your answer, no need to dive into this: you helped
someone! :)
Thanks again John!
Eric
>
>
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
--
Eric Chamberland, ing., M. Ing
Professionnel de recherche
GIREF/Université Laval
(418) 656-2131 poste 41 22 42
|