Hello Nico Huber,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/32085
to review the following change.
Change subject: libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN ......................................................................
libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN
Our current limits.h only provides (U)INT_MAX constants. This patch adds most others expected by POSIX. Since some of these may be different depending on architecture (e.g. 'long' is 32-bit on x86 and 64-bit on arm64), provide a definition that will automatically figure out the right value for the data model the compiler is using (as long as it's using two's complement for signed integers, which I think we can assume these days).
Change-Id: I1124a41279abd4f53d208270e392e590ca8eaada Signed-off-by: Julius Werner jwerner@chromium.org --- M payloads/libpayload/include/limits.h 1 file changed, 15 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/85/32085/1
diff --git a/payloads/libpayload/include/limits.h b/payloads/libpayload/include/limits.h index 2fecf23..4238e0e 100644 --- a/payloads/libpayload/include/limits.h +++ b/payloads/libpayload/include/limits.h @@ -40,7 +40,20 @@ # endif #endif
-#define UINT_MAX (unsigned int)0xffffffff -#define INT_MAX (unsigned int)0x7fffffff +#define USHRT_MAX ((unsigned short int)~0U) +#define SHRT_MIN ((short int)(USHRT_MAX & ~(USHRT_MAX >> 1))) +#define SHRT_MAX ((short int)(USHRT_MAX >> 1)) + +#define UINT_MAX ((unsigned int)~0U) +#define INT_MIN ((int)(UINT_MAX & ~(UINT_MAX >> 1))) +#define INT_MAX ((int)(UINT_MAX >> 1)) + +#define ULONG_MAX ((unsigned long int)~0UL) +#define LONG_MIN ((long int)(ULONG_MAX & ~(ULONG_MAX >> 1))) +#define LONG_MAX ((long int)(ULONG_MAX >> 1)) + +#define ULLONG_MAX ((unsigned long long int)~0UL) +#define LLONG_MIN ((long long int)(ULLONG_MAX & ~(ULLONG_MAX >> 1))) +#define LLONG_MAX ((long long int)(ULLONG_MAX >> 1))
#endif
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32085 )
Change subject: libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN ......................................................................
Patch Set 1:
Confirmed the new values on arm64 (where long is 64-bit):
TEST: USHRT_MAX is 65535 TEST: SHRT_MIN is -32768, SHRT_MAX is 32767 TEST: UINT_MAX is 4294967295 TEST: INT_MIN is -2147483648, INT_MAX is 2147483647 TEST: ULONG_MAX is 18446744073709551615 TEST: LONG_MIN is -9223372036854775808, LONG_MAX is 9223372036854775807 TEST: ULLONG_MAX is 18446744073709551615 TEST: LLONG_MIN is -9223372036854775808, LLONG_MAX is 9223372036854775807
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32085 )
Change subject: libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN ......................................................................
Patch Set 1: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/32085 )
Change subject: libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN ......................................................................
libpayload: limits.h: Provide reliable definitions for all XXX_MAX/MIN
Our current limits.h only provides (U)INT_MAX constants. This patch adds most others expected by POSIX. Since some of these may be different depending on architecture (e.g. 'long' is 32-bit on x86 and 64-bit on arm64), provide a definition that will automatically figure out the right value for the data model the compiler is using (as long as it's using two's complement for signed integers, which I think we can assume these days).
Change-Id: I1124a41279abd4f53d208270e392e590ca8eaada Signed-off-by: Julius Werner jwerner@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/32085 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Patrick Georgi pgeorgi@google.com --- M payloads/libpayload/include/limits.h 1 file changed, 15 insertions(+), 2 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Georgi: Looks good to me, approved
diff --git a/payloads/libpayload/include/limits.h b/payloads/libpayload/include/limits.h index 2fecf23..4238e0e 100644 --- a/payloads/libpayload/include/limits.h +++ b/payloads/libpayload/include/limits.h @@ -40,7 +40,20 @@ # endif #endif
-#define UINT_MAX (unsigned int)0xffffffff -#define INT_MAX (unsigned int)0x7fffffff +#define USHRT_MAX ((unsigned short int)~0U) +#define SHRT_MIN ((short int)(USHRT_MAX & ~(USHRT_MAX >> 1))) +#define SHRT_MAX ((short int)(USHRT_MAX >> 1)) + +#define UINT_MAX ((unsigned int)~0U) +#define INT_MIN ((int)(UINT_MAX & ~(UINT_MAX >> 1))) +#define INT_MAX ((int)(UINT_MAX >> 1)) + +#define ULONG_MAX ((unsigned long int)~0UL) +#define LONG_MIN ((long int)(ULONG_MAX & ~(ULONG_MAX >> 1))) +#define LONG_MAX ((long int)(ULONG_MAX >> 1)) + +#define ULLONG_MAX ((unsigned long long int)~0UL) +#define LLONG_MIN ((long long int)(ULLONG_MAX & ~(ULLONG_MAX >> 1))) +#define LLONG_MAX ((long long int)(ULLONG_MAX >> 1))
#endif