This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [patch] Avoid bogus pointer->int cast
- From: Ralf Corsepius <ralf dot corsepius at rtems dot org>
- To: newlib at sourceware dot org
- Date: Tue, 17 Jul 2012 19:26:11 +0200
- Subject: Re: [patch] Avoid bogus pointer->int cast
- References: <50059F04.1090505@rtems.org>
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.
[pointer->int casts are invalid on many architectures.]
OK to commit? If nobody objects, I am going to commit this patch later
this week.
Ralf
Sorry, too fast on the "send"-button, missed to attach the patch ;)
Ralf
2012-07-12 Ralf Corsépius <ralf.corsepius@rtems.org>
* libc/posix/readdir.c: Include <stdint.h>.
Cast to intptr_t instead of int.
diff --git a/newlib/libc/posix/readdir.c b/newlib/libc/posix/readdir.c
index da07d5c..c9472f5 100644
--- a/newlib/libc/posix/readdir.c
+++ b/newlib/libc/posix/readdir.c
@@ -37,6 +37,7 @@
static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90";
#endif /* LIBC_SCCS and not lint */
+#include <stdint.h>
#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);
- 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