lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


At 15:16 -0300 on 02-05-00, Roberto Ierusalimschy wrote:

 > With my PowerMac Lua 4.0 I have discovered something that seems like
 > a bug in "strfind".

It is a bug, and a silly one :-(  In my machine, you can get the bug with
the following little chunk:

  a = "abc  "
  print(strlen(a), strfind(a, "\0", strlen(a)-2, 1))

To fix it, you have to change one single line in lstrlib.c:

  408c408
  <     const char *s2 = memfind(s+init, l1, p, l2);
  ---
  >     const char *s2 = memfind(s+init, l1-init, p, l2);

(In words, when you start the search with an offset, you must subtract the
offset from the total length of the subject.)

It will be fixed in next version.

-- Roberto

I'll try that fix later today, but there's still one strange thing about my example that I don't understand. If I insert a copy of the line

   print(strlen(s), strfind(s, "4E AC", 276, 1))

just after the three long lines where the s string is given its initial value, and run the script, I get

   294 nil
   294 337 341

The contents of the s string should be the same in both of the strfind's, but the bug here only bites after the conversion from hex to binary and back to hex.

If I re-run (dofile) my script without exiting the Lua interpreter, I now get

   294 337 341
   294 337 341

Are there one more bug involved?

/Jon

---------------------------------------------------------------------------
Jon Kleiser / ADB-seksjonen / USIT / University of Oslo / Norway
Mail: Jon.Kleiser@usit.uio.no / Tel: +47-22 85 28 04 / Fax: +47-22 85 29 70
---------------------------------------------------------------------------