Bug 206176 - Non-null-terminated arrays in descriptions of strn* and wcsn* functions
Summary: Non-null-terminated arrays in descriptions of strn* and wcsn* functions
Status: New
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2016-01-12 22:34 UTC by Alexander Cherepanov
Modified: 2018-04-10 18:57 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Cherepanov 2016-01-12 22:34:12 UTC
The strn* and wcsn* functions take an argument limiting the size of processed parts of arrays. The C standard cautiously and consistently talks about arrays instead of strings in such cases and (hence) doesn't require arguments to be null-terminated strings in all cases.

OTOH FreeBSD man pages don't make this distinction and don't usually make remarks to that effect.

Take for example strcmp and strncmp. The description of strcmp in C11,

"The strcmp function compares the string pointed to by s1 to the string pointed to by s2."

It talks about "the string pointed to by s1" as expected.

Then, the description of strncmp -- C11,

"The strncmp function compares not more than n characters (characters that follow a null character are not compared) from the array pointed to by s1 to the array pointed to by s2."

Here, it talks about "the array pointed to by s1" instead of strings.

In the next paragraph it talks about "the possibly null-terminated array pointed to by s1" (please note "possibly").

The man page[1] for strncmp is silent on such details.

The same for strncat[2].

The question for non-C11 function like strncasecmp[3], strndup[4], strnstr[5] is moot but IMHO it's better to be consistent with C11.

Implementations are mostly ok, only documentation is wrong.

[1] https://svnweb.freebsd.org/base/head/lib/libc/string/strcmp.3?revision=251069&view=markup#l51
[2] https://svnweb.freebsd.org/base/head/lib/libc/string/strcat.3?revision=262890&view=markup#l51
[3] https://svnweb.freebsd.org/base/head/lib/libc/string/strcasecmp.3?revision=266865&view=markup#l55
[4] https://svnweb.freebsd.org/base/head/lib/libc/string/strdup.3?revision=251069&view=markup#l63
[5] https://svnweb.freebsd.org/base/head/lib/libc/string/strstr.3?revision=251069&view=markup#l77