I believe I've stumbled across a bug in one of the newlib header files (the ones from the most recent SDK). I was trying to compile GIFLIB, where one of the files has the following bit of code:
#ifndef SIZE_MAX
#define SIZE_MAX UINTPTR_MAX
#endif
It compiled fine when using clib2, but when using newlib I got the following error when SIZE_MAX was referenced:
In file included from openbsd-reallocarray.c:8:
openbsd-reallocarray.c: In function 'openbsd_reallocarray':
openbsd-reallocarray.c:25:19: error: 'ULONG_MAX' undeclared (first use in this function)
nmemb > 0 && SIZE_MAX / nmemb < size) {
^~~~~~~~
openbsd-reallocarray.c:25:19: note: 'ULONG_MAX' is defined in header '<limits.h>'; did you forget to '#include <limits.h>'?
openbsd-reallocarray.c:10:1:
+#include <limits.h>
The file indeed does not include <limits.h>, but it does include <stdint.h>. The clib2 version of <stdint.h> contains the following:
#ifndef _LIMITS_H
#include <limits.h>
#endif /* _LIMITS_H */
So <stdint.h> includes <limits.h>, and everything works fine. The newlib version of <stdint.h>, however, contains the following:
#if defined(__GNUC__) && \
( (__GNUC__ >= 4) || \
( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) )
/* gcc > 3.2 implicitly defines the values we are interested */
#define __STDINT_EXP(x) __##x##__
#else
#define __STDINT_EXP(x) x
#include <limits.h>
#endif
In other words, <limits.h> is included only if the version of GCC is 3.2 or earlier. That seems odd, which makes me think that "#include <limits.h>" should come
after the #endif, not before it.
I made this change, and was able to build GIFLIB without error. I recompiled a number of my other projects, and nothing seems to have been broken by the change. But the flow of system headers can be complex and difficult to follow, so I thought I'd see if others can confirm that this is a bug, or explain why it isn't.