Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   string routines go to never never land on unix (http://www.velocityreviews.com/forums/t315822-string-routines-go-to-never-never-land-on-unix.html)

Kevin 10-17-2003 04:44 PM

string routines go to never never land on unix
 
I have a routine that is copying chunks of a super large string into a
new order. It is acting as a message translator. For certain source
messages, the string routines seem to stop, and the cpu utilization
goes to 99%. When I attach to the process, the program is always on
either strchr or strlen.

Here is a snippet of code demonstrating these symptoms:

/* Look for space in input to break line upon*/
pcSrcCharLoc = pcAdjustedInput;
while (pcSrcCharLoc < pcAdjustedInput + lWidthData)
{
pcSpacePointer = strchr(pcSrcCharLoc, ' ');
tLocOfSpace = pcSpacePointer - pcSrcCharLoc;

... processing of string between pcSrcCharLoc and pcSpacePointer
- a sprintf of pcSrcCharLoc onto pcDestCharLoc for length tLocOfSpace
plus some logging wrapped in if's.

pcSrcCharLoc += tLocOfSpace;
}

pcAdjustedInput is a pointer to a string of the field being copied,
which has had extra spaces removed. The pointer was alloc'd by the
routine that copied the string removing the spaces. The string is
null terminated. LWidthData is the strlen of pcAdjustedInput.

What will happen is on the first run through, the first substring (a
word) is processed, and then the program stops on the next strchr, and
the CPU utilization goes to 99%.

Any hints, ideas, or someone pointing out the obvious would be greatly
appreciated.

Thanks
Kevin

Christopher Benson-Manica 10-17-2003 05:05 PM

Re: string routines go to never never land on unix
 
Kevin <kefraser@rocketmail.com> spoke thus:

> Here is a snippet of code demonstrating these symptoms:


> /* Look for space in input to break line upon*/
> pcSrcCharLoc = pcAdjustedInput;
> while (pcSrcCharLoc < pcAdjustedInput + lWidthData)
> {
> pcSpacePointer = strchr(pcSrcCharLoc, ' ');
> tLocOfSpace = pcSpacePointer - pcSrcCharLoc;


> pcSrcCharLoc += tLocOfSpace;
> }


If I'm not mistaken, you're stuck on the first space in the input.
pcSrcCharLoc+tLocOfSpace puts pcSrcCharLoc right at the space, and so
strchr(pcSrcCharLoc, '') is pcSrcCharLoc.

pcSrcCharLoc += tLocOfSpace+1;

would fix things, I imagine...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.

Irrwahn Grausewitz 10-17-2003 05:52 PM

Re: string routines go to never never land on unix
 
Christopher Benson-Manica <ataru@nospam.cyberspace.org> wrote:

>Kevin <kefraser@rocketmail.com> spoke thus:
>
>> pcSrcCharLoc = pcAdjustedInput;
>> while (pcSrcCharLoc < pcAdjustedInput + lWidthData)
>> {
>> pcSpacePointer = strchr(pcSrcCharLoc, ' ');
>> tLocOfSpace = pcSpacePointer - pcSrcCharLoc;

>
>> pcSrcCharLoc += tLocOfSpace;
>> }

>
>If I'm not mistaken, you're stuck on the first space in the input.
>pcSrcCharLoc+tLocOfSpace puts pcSrcCharLoc right at the space, and so
>strchr(pcSrcCharLoc, '') is pcSrcCharLoc.

^' ' (just to pick nit ;-)
>
>pcSrcCharLoc += tLocOfSpace+1;
>
>would fix things, I imagine...


most probably, yes; alternatively you can write:

pcSrcCharLoc = pcSpacePointer + 1;

--
Irrwahn
(irrwahn33@freenet.de)

Christopher Benson-Manica 10-17-2003 05:56 PM

Re: string routines go to never never land on unix
 
Irrwahn Grausewitz <irrwahn33@freenet.de> spoke thus:


>>strchr(pcSrcCharLoc, '') is pcSrcCharLoc.

> ^' ' (just to pick nit ;-)


Well, if I've graduated from "Sir, you are completely wrong, please shut up
now" to "Sir, you forgot a space, please shut up now", I'm improving...
Hopefully it isn't temporary ;-(

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.

Irrwahn Grausewitz 10-17-2003 06:07 PM

Re: string routines go to never never land on unix
 
Christopher Benson-Manica <ataru@nospam.cyberspace.org> wrote:

>Well, if I've graduated from "Sir, you are completely wrong, please shut up
>now" to "Sir, you forgot a space, please shut up now", I'm improving...
>Hopefully it isn't temporary ;-(


Relax, same to me. 8^}
--
Irrwahn
(irrwahn33@freenet.de)


All times are GMT. The time now is 03:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.