[cfe-dev] -fcatch-undefined-behavior false positive with readdir()?
joe at alacatialabs.com
Wed Sep 26 07:40:47 PDT 2012
On Wed, Sep 26, 2012 at 10:29 AM, Sean McBride <sean at rogue-research.com> wrote:
> Hi all,
> The following C code works without -fcatch-undefined-behavior, and worked with it too, until a few weeks ago when it was given new smarts:
> #include <dirent.h>
> #include <stdio.h>
> int main (void)
> 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);
> return 0;
> $ clang --version
> clang version 3.2 (trunk 164470)
> $ clang -Weverything -fcatch-undefined-behavior test.c
> (no output)
> $ ./a.out
> Illegal instruction: 4
> Several colleagues have reviewed the code, and so I'm guess I'm asking if I should file a bug, or have missed something subtle here.
Just a hunch: is d->d_name an unaligned pointer? We ran into a similar
issue with gethostbyname.
-- Joe Ranieri
More information about the cfe-dev