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: Fix SIZE_MAX, remove SIZE_MIN


Mark Mitchell wrote:
Newlib's <stdint.h> defines SIZE_MAX as a signed quantity equivalent
to LONG_MAX.  This is incorrect; SIZE_MAX is supposed to be the
maximum value of a size_t and, as such, should be equilvalent to
ULONG_MAX.  Furthermore, <stdint.h> defines SIZE_MIN, which is not a
macro specified by the C standard, and, as such, pollutes the user's
namespace.

Here's a patch to fix these problems, as well as creating a new test
case for the SIZE_MAX definition.

Tested on arm-none-eabi. OK to apply?


Ok, thanks.


-- Jeff J.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2008-04-26 Mark Mitchell <mark@codesourcery.com>

	* libc/include/stdint.h (SIZE_MIN): Remove.
	(SIZE_MAX): Define.
	* testsuite/newlib.stdlib/stdlib.exp: New.
	* testsuite/newlib.stdlib/size_max.c: Likewise.

Index: newlib/libc/include/stdint.h
===================================================================
--- newlib/libc/include/stdint.h (revision 205913)
+++ newlib/libc/include/stdint.h (working copy)
@@ -348,8 +348,7 @@ typedef unsigned long uintptr_t;
#endif
/* This must match size_t in stddef.h, currently long unsigned int */
-#define SIZE_MIN (-__STDINT_EXP(LONG_MAX) - 1L)
-#define SIZE_MAX __STDINT_EXP(LONG_MAX)
+#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
/* This must match sig_atomic_t in <signal.h> (currently int) */
#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
Index: newlib/testsuite/newlib.stdlib/size_max.c
===================================================================
--- newlib/testsuite/newlib.stdlib/size_max.c (revision 0)
+++ newlib/testsuite/newlib.stdlib/size_max.c (revision 0)
@@ -0,0 +1,18 @@
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+int main () {
+ size_t s;
+
+ s = SIZE_MAX;
+ /* If SIZE_MAX is truncated when assigning to "s", then SIZE_MAX is
+ too big. */
+ if (s != SIZE_MAX)
+ abort ();
+ /* If SIZE_MAX + 1 is not zero, then SIZE_MAX is not big enough. */
+ if (++s != 0)
+ abort ();
+
+ return 0;
+}
Index: newlib/testsuite/newlib.stdlib/stdlib.exp
===================================================================
--- newlib/testsuite/newlib.stdlib/stdlib.exp (revision 0)
+++ newlib/testsuite/newlib.stdlib/stdlib.exp (revision 0)
@@ -0,0 +1,10 @@
+# Copyright (C) 2008 by CodeSourcery, Inc. All rights reserved.
+#
+# Permission to use, copy, modify, and distribute this software
+# is freely granted, provided that this notice is preserved.
+
+load_lib passfail.exp
+
+set exclude_list [list "atexit.c"]
+
+newlib_pass_fail_all -x $exclude_list


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