Re: segmentation fault in strtok_r()

From: Artie Gold (artiegold_at_austin.rr.com)
Date: 07/30/03


Date: Wed, 30 Jul 2003 19:27:45 GMT

Paul Pluzhnikov wrote:
> Artie Gold <artiegold@austin.rr.com> writes:
>
>
>>> The strtok_r() function works the same as the strtok()
>>> function, but instead of using a static buffer it uses a
>>> pointer to a user allocated char* pointer. This pointer,
>>> the ptrptr parameter, must be the same while parsing the
>>> same string.
>>
>>Have I gone brain-dead? :-(
>
>
> Not completely: you can still type :-)

Ah, merely severe cerebral flatulence.

>
> He did allocate the 'char*' pointer (on the stack) right here:
>
> char * trimLeadEndSpace( char * pCharArray )
> { ...
> char *pPTR = 0 , *ppPTR = 0 ;
> ^^^^^^^^^^^^^^^^^
>
> The ptrptr (from the man page) == &pPTR, and it is 'the same'
> while parsing the same string, so he's done nothing wrong WRT
> strtok_r(), which uses (and changes) the value of pPTR to keep
> track of where in the string to continue tokenizing ...
>
Of course. ;-/

--ag

-- 
Artie Gold -- Austin, Texas


Relevant Pages