Re: size_t problems
CBFalconer <cbfalconer@yah oo.comwrites:
By never passing it a pointer to a string longer than INT_MAX
characters. This tends to be easier than, for example, guaranteeing
that 'x + y' will never overflow.
The declaration may or may not be broken, depending on what happens at
run time. The problem is that, apparently, the programmer knows it's
safe, but the compiler doesn't have enough information to prove it.
The ideal solution is to declare s as a size_t, and to make whatever
other code changes follow from that, but that's not always practical.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
CBFalconer <cbfalconer@yah oo.comwrites:
jacob navia wrote:
... snip ...
>
Yes it is. How can you guarantee that strlen never returns a value
that exceeds the capacity of an int?
... snip ...
>>
>int s = strlen(str) is NOT broken.
>int s = strlen(str) is NOT broken.
Yes it is. How can you guarantee that strlen never returns a value
that exceeds the capacity of an int?
characters. This tends to be easier than, for example, guaranteeing
that 'x + y' will never overflow.
The declaration may or may not be broken, depending on what happens at
run time. The problem is that, apparently, the programmer knows it's
safe, but the compiler doesn't have enough information to prove it.
The ideal solution is to declare s as a size_t, and to make whatever
other code changes follow from that, but that's not always practical.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment