This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linux getdents.c is not aliasing safe


> I'm not sure that it's valid C99 - my impression is that it isn't, and
> the only valid way would be to have a function return the DIRENT_TYPE
> by value - but it's valid GNU C and it fixes the bug I was chasing. 

I'm not sure either.  I don't have a copy of C99 to consult, and my
weasel-wording skills were getting rusty 10 years ago after getting to know
all the corners C89.  But I think it is valid.  Last I knew, aliasing is
still kosher as long as it's through variables of the same type.  The code
now has aliasing only through variables of a single pointer type: the
union.  The uses of the union are kosher as far as I understand it, because
only one variant is ever used at a time: the first variant is read from,
and then that memory is completely clobbered by writing to the second
variant.  The only thing that's questionable is the memmove, and it's
memmove for pete's sake so I don't know how much more explicitly you could
say you are doing aliasing.  

Anyway, bottom line is that what we really care to ensure is that we can
reasonably expect it to work in GNU C for at least long enough that we
would be aware of any possible change in the semantics by the time such a
compiler got released.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]