[Bugme-new] [Bug 42042] New: strchr(3) and memchr(3) should explain behaviour when character 'c' is '\0'.
bugzilla-daemon at bugzilla.kernel.org
bugzilla-daemon at bugzilla.kernel.org
Tue Aug 30 06:18:13 PDT 2011
https://bugzilla.kernel.org/show_bug.cgi?id=42042
Summary: strchr(3) and memchr(3) should explain behaviour when
character 'c' is '\0'.
Product: Documentation
Version: unspecified
Platform: All
OS/Version: Linux
Tree: Mainline
Status: NEW
Severity: normal
Priority: P1
Component: man-pages
AssignedTo: documentation_man-pages at kernel-bugs.osdl.org
ReportedBy: jamesodhunt at gmail.com
Regression: No
PROBLEM
-------
strchr(3) and memchr(3) do not explain the behaviour if the character to search
for is specified as a null character ('\0'). According to my copy of Harbison
and Steele, since the terminator is considered part of the string, a call such
as:
strchr("hello", '\0')
... will return the address of the terminating null in the specified string.
RATIONALE
---------
strchr(3) and memchr(3) are inconsistent with index(3) which states:
"The terminating NULL character is considered to be a part of the strings."
Adding such a note to strchr(3) and memchr(3) is also important since it is not
unreasonable to assume that strchr() will return NULL in this scenario. This
leads to code like the following which is guaranteed to fail should
get_a_char() return '\0':
char string[] = "hello, world";
int c = get_a_char();
if (! strchr(string, c))
fprintf(stderr, "failed to find character in string\n");
SUGGESTED UPDATE
----------------
I'd suggest adding something like the following to strchr(3) and memchr(3):
If 'c' is '\0' (the terminating null character), strchr() will return the
address of the terminating null character in 's'.
--
Configure bugmail: https://bugzilla.kernel.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the Bugme-new
mailing list