string routines go to never never land on unix

K

Kevin

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
 
C

Christopher Benson-Manica

Kevin said:
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...
 
I

Irrwahn Grausewitz

Christopher Benson-Manica said:
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;
 
C

Christopher Benson-Manica

^' ' (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 ;-(
 
I

Irrwahn Grausewitz

Christopher Benson-Manica said:
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^}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,220
Latest member
AugustinaJ

Latest Threads

Top