From: James Prestwood <prestwoj at gmail.com>
To: ell at lists.01.org
Subject: [PATCH 2/2] missing: use PTRDIFF_MAX instead of -1
Date: Fri, 10 Jun 2022 10:11:32 -0700 [thread overview]
Message-ID: <20220610171132.334641-2-prestwoj@gmail.com> (raw)
In-Reply-To: 20220610171132.334641-1-prestwoj@gmail.com
[-- 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
reply other threads:[~2022-06-10 17:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220610171132.334641-2-prestwoj@gmail.com \
--to=unknown@example.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.