[cfe-dev] -fcatch-undefined-behavior false positive with readdir()?
Sean McBride
sean at rogue-research.com
Wed Sep 26 12:56:21 PDT 2012
Richard,
It prints 8, for every iteration of the loop. I guess that's correct since the first field of the struct is a uint64_t.
Sean
On Wed, 26 Sep 2012 12:49:38 -0700, Richard Smith said:
>Can you try adding
>
> printf ("%p %zd\\n", d, _Alignof(*d));
>
>before the line which fails? Is the pointer correctly aligned?
>
>On Wed, Sep 26, 2012 at 12:38 PM, Sean McBride <sean at rogue-research.com>wrote:
>
>> On Wed, 26 Sep 2012 10:40:47 -0400, Joe Ranieri said:
>>
>> >> DIR* dir = opendir("/usr/lib");
>> >> if (dir)
>> >> {
>> >> struct dirent* d = NULL;
>> >> while ((d = readdir(dir)) != NULL)
>> >> {
>> >> const char* local = d->d_name; // bam!
>> >> printf ("%s\n", local);
>> >> }
>> >> closedir(dir);
>> >> }
>> >>
>> >
>> > *SNIP*
>> >
>> >Just a hunch: is d->d_name an unaligned pointer? We ran into a similar
>> >issue with gethostbyname.
>>
>> Joe,
>>
>> Thanks for your reply. But I'm afraid I don't follow. Unaligned with
>> respect to what? The 'struct dirent' is declared by the system basically
>> like so:
>>
>> #pragma pack()
>> struct dirent {
>> uint64_t d_ino;
>> uint64_t d_seekoff;
>> uint16_t d_reclen;
>> uint16_t d_namlen;
>> uint8_t d_type;
>> char d_name[1024];
>> }
>>
>> Note the 'pragma pack'; is that the alignment you're referring to? On my
>> system, I don't see any pragma pack with gethostbyname()'s 'struct
>> hostent', what problem did you have with it?
>>
>> I just tried something else: it's not just the d_name field, but accessing
>> any field triggers the SIGILL.
More information about the cfe-dev
mailing list