Previous Thread
Next Thread
Print Thread
instr #29823 26 Jul 07 03:48 AM
Joined: Jun 2001
Posts: 153
O
OmniLedger - Tom Reynolds Offline OP
Member
OP Offline
Member
O
Joined: Jun 2001
Posts: 153
Hi Jack
This code would have previously returned 0 now returns the search start point ie 2.

MAP1 IN'LINE,S,100
MAP1 ST'VAR,S,1

IN'LINE = ""
ST'VAR = "+"
SEARCH'POS = 2
ST'POS = INSTR(SEARCH'POS,IN'LINE,ST'VAR)
PRINT "ST'POS=", ST'POS

Re: instr #29824 03 Aug 07 08:02 AM
Joined: Jun 2001
Posts: 11,645
J
Jack McGregor Online Content
Member
Online Content
Member
J
Joined: Jun 2001
Posts: 11,645
Hi Barry,

Sorry about the delay on this one - you managed to slip it past my sophisticated radar by posting two messages on the same date. (Apparently my radar was tuned to spotting either a single message, or the dozen or so which is typical for some hyperactive correspondents on this forum!)

And thank you for the bug report. It's probably not a common case (of specifying a starting search position which is beyond the end of the string), but it was a nasty bug that needed to be fixed.

It got introduced in 5.0.989 when I "optimized" the instr() operation for the simplest and most common case of a one character key. The problem was that the standard library routine I used - memchr() - treats the length argument as unsigned, but in the case you present, I was passing it a negative number, causing it to potentially search through a lot of memory. The case you presented was actually a near best case, since by chance, the string args are arranged on the stack so that the key follows the search string, and thus it was quickly found. (If you had set the starting position to 3 instead of 2, you'd get a surprising and unpredictable result.)

It is fixed in 5.0.994.2, which I'll post in the various forms shortly. (You'll be able to retrieve them via the Update Center or directly from the http://www.microsabio.net/dist/50rel directories for each platform.)

Re: instr #29825 03 Aug 07 10:20 AM
Joined: Jun 2001
Posts: 153
O
OmniLedger - Tom Reynolds Offline OP
Member
OP Offline
Member
O
Joined: Jun 2001
Posts: 153
Looks ok. Thanks.


Moderated by  Jack McGregor, Ty Griffin 

Powered by UBB.threads™ PHP Forum Software 7.7.3