public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* size_t cast in libssp
@ 2010-10-05 9:54 angie
2010-10-05 10:06 ` Andreas Schwab
0 siblings, 1 reply; 2+ messages in thread
From: angie @ 2010-10-05 9:54 UTC (permalink / raw)
To: gcc-bugs
After some casual analysis, I noticed that libssp (in gets-chk.c) we
were doing:
if (slen >= (size_t) INT_MAX)
return gets (s);
if (slen <= 8192)
buf = alloca (slen + 1);
else
buf = malloc (slen + 1);
if (buf == NULL)
return gets (s);
What's the reason behind casting with size_t for INT_MAX, it seems to
be a design
error, there is no guarantee that INT_MAX is a valid size_t. If we
want to limit it
to size_t, we'd instead want a macro finding the minimum of INT_MAX
and SIZE_MAX,
thereby rendering the whole cast unnecessary and potentially badly
thought out.
Please get back to me at this address regarding this so that we may
discuss future changes
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: size_t cast in libssp
2010-10-05 9:54 size_t cast in libssp angie
@ 2010-10-05 10:06 ` Andreas Schwab
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2010-10-05 10:06 UTC (permalink / raw)
To: angie; +Cc: gcc-bugs
<angie@auth.se> writes:
> What's the reason behind casting with size_t for INT_MAX, it seems to
> be a design
> error, there is no guarantee that INT_MAX is a valid size_t. If we
> want to limit it
> to size_t, we'd instead want a macro finding the minimum of INT_MAX
> and SIZE_MAX,
If INT_MAX > SIZE_MAX then (size_t)INT_MAX == SIZE_MAX, ie. this is the
minimum either way.
Andreas.
--
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-10-05 10:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-05 9:54 size_t cast in libssp angie
2010-10-05 10:06 ` Andreas Schwab
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 read-only IMAP folder(s) and NNTP newsgroup(s).