This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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] | |
On 07/17/2012 11:26 AM, Ralf Corsepius wrote:
> On 07/17/2012 07:21 PM, Ralf Corsepius wrote:
>> Hi,
>>
>> The patch below addresses a (minor) bug in readdir.c. It replaces a
>> (bogus) pointer->int cast with a pointer->intptr_t cast.
Rather than "fixing" the bogus pointer check, why not just nuke that
code altogether?
>
> +#include <stdint.h>
In other words, no need to drag this in...
> #include <dirent.h>
>
> extern int getdents (int fd, void *dp, int count);
> @@ -75,7 +76,7 @@ _DEFUN(readdir, (dirp),
> continue;
> }
> dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
and everything between here...
> - if ((int)dp & 03) { /* bogus pointer check */
> + if ((intptr_t)dp & 03) { /* bogus pointer check */
> #ifdef HAVE_DD_LOCK
> __lock_release_recursive(dirp->dd_lock);
> #endif
return NULL;
}
...and here is just stupid. POSIX already states that behavior is
undefined if you pass in a bogus pointer; and in a compliant program,
readdir should only ever be called on a valid pointer, making this check
look like nothing more than dead code. I see no need to bloat the code
with an attempt to gracefully deal with a bogus pointer.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |