This is my code that is generating a false violation when compiled with mudflap
and the following options
export MUDFLAP_OPTIONS='-mode-check -viol-segv -backtrace=4 -verbose-violations
-check-initialization'
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
struct dirent **namelist;
struct stat statinfo;
int n=0, i;
n=scandir("/d/ttt/",&namelist,NULL,alphasort);
if(n<0)
{
printf("ERROR scandir: %s\n", strerror(errno));
return 0;
}
else
{
printf("n %d\n", n);
}
while(n--)
{
printf("namelist[%d]->d_name '%s'\n", n, namelist[n]->d_name);
memset(&statinfo, 0, sizeof(statinfo));
stat(namelist[n]->d_name,&statinfo);
free(namelist[n]);
}
free(namelist);
return 0;
}
And here is the false violation reported
*******
mudflap violation 1 (check/read): time=1206741830.906553 ptr=0x80cf0db size=10
pc=0xb7dec8ad location=`(stat path)'
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__mf_check+0x3d) [0xb7dec8ad]
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__mfwrap_stat+0x136)
[0xb7df2a46]
./scandir(main+0x3f2) [0x8048d8e]
Nearby object 1: checked region begins 11B into and ends 20B into
mudflap object 0x80cf110: name=`malloc region'
bounds=[0x80cf0d0,0x80cf0e7] size=24 area=heap check=1r/0w liveness=1
alloc time=1206741830.906135 pc=0xb7dec2fd
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__mf_register+0x3d)
[0xb7dec2fd]
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__wrap_malloc+0xe0)
[0xb7ded7c0]
/lib/libc.so.6(scandir+0x8f) [0xb7d43541]
./scandir(main+0x97) [0x8048a33]
Nearby object 2: checked region begins 2008B after and ends 2017B after
mudflap dead object 0x80ce948: name=`malloc region'
bounds=[0x80cd8e8,0x80ce903] size=4124 area=heap check=0r/0w liveness=0
alloc time=1206741830.905913 pc=0xb7dec2fd
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__mf_register+0x3d)
[0xb7dec2fd]
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__wrap_malloc+0xe0)
[0xb7ded7c0]
/lib/libc.so.6 [0xb7d43031]
/lib/libc.so.6(opendir+0x5d) [0xb7d430f6]
dealloc time=1206741830.906347 pc=0xb7dec2a6
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__mf_unregister+0x36)
[0xb7dec2a6]
/opt/miro_gcc/usr/local/lib/libmudflap.so.0(__real_free+0x80)
[0xb7ded090]
/lib/libc.so.6(closedir+0x24) [0xb7d4314c]
/lib/libc.so.6(scandir+0x139) [0xb7d435eb]
number of nearby objects: 2
Segmentation fault (core dumped)
--
Summary: Mudflap false violation
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: eugen at familiamorjolic dot ro
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35749