Posted By: Morris
Odd behavior by strmid() - 08/26/20 11:53
strmid() does not return what I would sensibly expect when running into the end of the string; instead, it returns the last character before the end (going back before the 'first' parameter). This is observed with Zorro 2.25.7. Code in point:
The real life case for this involved parsing a configuration file, where running mid on the end of the string should have returned just '\0'.
Am I wrong in assuming this might be a bug?
Code
void main() { string test = "abc\0def"; printf("\ntest='%s'", test); // Prints 'abc' -- as expected string mid = strmid(test, 0, 2); printf("\nmid='%s'", mid); // Prints 'ab' -- as expected string mid = strmid(test, 2, 2); printf("\nmid='%s'", mid); // Prints 'c' -- as expected string mid = strmid(test, 3, 2); printf("\nmid='%s'", mid); // Prints 'c' -- that appears wrong. Should yield an empty string string mid = strmid(test, 4, 2); printf("\nmid='%s'", mid); // Prints 'c' -- that definitely appears wrong. Should print an empty string or 'de' }
The real life case for this involved parsing a configuration file, where running mid on the end of the string should have returned just '\0'.
Am I wrong in assuming this might be a bug?