[patch] Avoid bogus pointer->int cast
Eric Blake
eblake@redhat.com
Fri Jul 20 16:56:00 GMT 2012
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20120720/e7c6d043/attachment.sig>
More information about the Newlib
mailing list