Re: Comment on trim string function please
- From: "Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx>
- Date: Sun, 13 Jul 2008 15:20:03 GMT
CBFalconer <cbfalconer@xxxxxxxxx> wrote in message
news:4879374E.53E97D90@xxxxxxxxxxxx
Bill Reid wrote:
<badc0de4@xxxxxxxxx> wrote:... snip ...
Bill Reid wrote:
char *remove_beg_end_non_text(char *text) {
char *beg;
size_t length;
for (beg = text; *beg != '\0'; beg++)
if (!isspace(*beg)) break;
(spaces added for legibility above)
BUG: missing cast
I've not been following why the cast is important; is this some
type of "error" that has never actually occured on the planet
Earth but MIGHT happen in the unpredictable future?
Serious bug. isspace(int) requires the integer value of an
unsigned char. Repeat, unsigned.
Repetition is not clarification. By declaration, and all available
"official" documentation, isspace(int) requires a signed integer value...
If the char type on any machine
is signed isspace can receive a negative value, and quite likely
blowup.
On my machine, "char" is "signed char" by default, at least
according to SOME of the documentation. Nothing is "blowing
up". Why so?
That's why the argument to isspace should receive an
explicit cast. The only negative value those functions can receive
is EOF.
Sure you're not conflating "strings" with "streams"?
The cast can be avoided when the integer output of getc() is
passed, because getc returns the appropriately cast value in the
first place.
How do you think the characters wound up in a string in the first
place?
But you are getting those chars from a string, and
whether a raw char is signed or unsigned is always undefined.
I appear to "getting" a signed 8-bit integer value from my string,
with no problems, yet you think it is critically important to cast
it to an unsigned integer value, for a function that takes a signed
integer value as an argument, in order to perform a look-up of
certain integer values. Nope, still not getting it...
---
William Ernest Reid
.
- Follow-Ups:
- Re: Comment on trim string function please
- From: Eric Sosman
- Re: Comment on trim string function please
- From: santosh
- Re: Comment on trim string function please
- References:
- Comment on trim string function please
- From: swengineer001@xxxxxxxxx
- Re: Comment on trim string function please
- From: Jens Thoms Toerring
- Re: Comment on trim string function please
- From: Bill Reid
- Re: Comment on trim string function please
- From: Willem
- Re: Comment on trim string function please
- From: Bill Reid
- Re: Comment on trim string function please
- From: Bill Reid
- Re: Comment on trim string function please
- From: CBFalconer
- Comment on trim string function please
- Prev by Date: Re: comparison between signed and unsigned
- Next by Date: Re: Comment on trim string function please
- Previous by thread: Re: Comment on trim string function please
- Next by thread: Re: Comment on trim string function please
- Index(es):
Relevant Pages
|