× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Thu, 11 Nov 2004 Rick.Chevalier@xxxxxxxxxxxxxxx wrote:

> Currently I'm trying to use the C strstr function but it keeps giving me
> a pointer value when the search string doesn't exist in the user space.
> I have listed the associated code below.

strstr() searches until it either finds the string you're looking for, or
until it finds a x'00' character.

This means that if you have a x'00' byte in your user space, the search
may stop early.

If you don't have a x'00' in the user space, the search may keep going
beyond the end of the space into other areas of memory, and eventually
find something that matches!

Not only that, but your prototype for strstr is wrong.  You're passing the
arguments by reference, and they need to be passed by VALUE!

The best way to search a user space, IMHO, is to use memchr() followed
memcmp() in a loop.  memchr() searches memory for a single character --
the first character in your string.  memcmp() compares memory to see if it
contains a string.  So you write a loop...  for each character that
memchr() finds, you perform a memcmp().  If it doesn't match, you keep
going seaerching with memchr() again.  If it does match...  well, you've
found the string and can stop searching...

This was discussed in some depth (including code) in the following thread
on the iSeries Network forums:
http://www.iseriesnetwork.com/Forums/Thread.cfm?CFApp=54&Message_ID=142481

That link does require a membership to the iSeries Network, but a free
"Associate" membership will work.

Good luck!


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.