* [PATCH 2/2] missing: use PTRDIFF_MAX instead of -1
@ 2022-06-10 17:11 James Prestwood
0 siblings, 0 replies; only message in thread
From: James Prestwood @ 2022-06-10 17:11 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]
On musl-gcc the compiler complains that the size passed to
memchr (-1) is larger than the object size (size_t). Looking
at the values its limiting size_t to a max size of a signed
integer (0x7FFF....) and we are passing 0xFFFFF....
Since this size is quite large its not expected that anyone
will ever need to use memchr with a buffer this big.
Limiting the size to a signed integer max value should be just
fine.
Instead, use PTRDIFF_MAX rather than -1. Below is the warning
produced in upstream:
In file included from ell/pem.c:45:
In function 'rawmemchr',
inlined from 'pem_load_buffer' at ell/pem.c:227:21:
ell/missing.h:76:16: error: 'memchr' specified bound
18446744073709551615 may exceed maximum object size
9223372036854775807 [-Werror=stringop-overread]
76 | return memchr(s, c, (size_t) -1);
---
ell/missing.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ell/missing.h b/ell/missing.h
index 2a3e647..11d6a8e 100644
--- a/ell/missing.h
+++ b/ell/missing.h
@@ -73,7 +73,7 @@ static inline void *rawmemchr(const void *s, int c)
{
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wstringop-overflow=\"")
- return memchr(s, c, (size_t) -1);
+ return memchr(s, c, PTRDIFF_MAX);
_Pragma("GCC diagnostic pop")
}
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-10 17:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 17:11 [PATCH 2/2] missing: use PTRDIFF_MAX instead of -1 James Prestwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).