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]

Re: [patch] Avoid bogus pointer->int cast


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

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