Re: strtok and strtok_r
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Sun, 16 Sep 2007 17:59:17 +0000 (UTC)
In article <6JOdnW7Dx7Nq9XDbnZ2dnUVZ_gydnZ2d@xxxxxxxxxxx>,
Joe Wright <joewwright@xxxxxxxxxxx> wrote:
I don't want to check strlen for error. SIZE_MAX may well be valid.
Passing in a NULL should be a NOP in my view.
size_t strlen(const char *s) {
size_t r = 0;
if (s) while (*s++) ++r;
return r;
}
Then how will you distinguish between the string containing just
the terminating nul, and the null pointer?? strlen() is often
used to determine array indices; you don't want to be indexing
the NULL pointer (for one thing, the result of the indexing
might get you to a readable or writable memory location -- and yes,
there are real systems on which virtual addresses near 0 are
accessible.)
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
.
- References:
- strtok and strtok_r
- From: siddhu
- Re: strtok and strtok_r
- From: rafaelc
- Re: strtok and strtok_r
- From: Keith Thompson
- Re: strtok and strtok_r
- From: Joe Wright
- strtok and strtok_r
- Prev by Date: Re: strtok and strtok_r
- Next by Date: Re: strtok and strtok_r
- Previous by thread: Re: strtok and strtok_r
- Next by thread: Re: strtok and strtok_r
- Index(es):
Relevant Pages
|
Loading