Hello,
I found out that str_cmp's behaviour does not match its documentation. The
difference is when the length of the two strings is not equal:
http://trac.helenos.org/browser/mainline/uspace/lib/c/generic/str.c#L427
The documentation says that:
The strings are considered equal iff they consist of the same
characters *on the minimum of their lengths*.
That is, str_cmp("hello", "hello world") should be 0 according to
documentation, but it is -1 in the current implementation as the if (c1 == 0
|| c2 == 0) is last condition of the three.
Now my topic for discussion is whether we should fix the implementation or the
documentation. I quickly looked at some usages of this function and it seems
that portions of the codebase depend on the current implementation when
checking equality of strings as str_cmp(a, b) == 0 (or !str_cmp(a, b)).
In any case, do we a str_equal function that checks that both length and
common prefix of strings is equal? If not, I propose we add one explicitly
promising the length comparison in its documentation. We can then fix the code
that checks if the strings are equal using this function instead of str_cmp.
Regards,
Martin Sucha
_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/cgi-bin/listinfo/helenos-devel