Reputation: 759
I am using strstr()
to compare an XML response versus an expected response. On shorter tests, this has worked properly, but now on the larger strings I am seeing two buffers exactly equal one another, but strstr()
is failing to catch it.
The XML string response I am failing on is 502 bytes in size, so I'm expecting strstr()
to find an occurrence of a 502 byte string inside a 502 byte string.
Example:
if( strstr(msgPointer, xmlcheckstring) )
{
printf("Good response!\n");
}
else
{
printf("Bad response :(\n");
}
Where msgPointer
points to my receive buffer and xmlcheckstring
contains a constant string to check against. And again, this worked for smaller tests (~200 bytes in size).
I'm just curious if anyone has had any experience with this. Thanks,
Upvotes: 0
Views: 3516
Reputation: 42165
FreeBSD can be a useful source if you want to check the implementation of standard C functions.
Their version of strstr will look very similar to other standard library implementations and confirms there are no limitations that'd affect the relatively small strings you're dealing with.
Upvotes: 1
Reputation: 68023
If there is a limit, it's unlikely to be much below MAXINT
I'm going to have a guess that you're searching for a string in data that you've read from a TCP stream socket? If so, be aware that read()
can return less bytes than you've requested and you may need to call read()
multiple times to get the entire XML message that you're looking for...
Upvotes: 2