Details

[Home]

Issue of the Standard # S0022

Brief

Standard defines the first parameter of strnlen() function as 'string', but such definition reduces the applicability of the function. It looks valid to define the first parameter as 'array of char'.

Detailed Description

Standard defines the parameter ‘s’ as string, which should always be zero-terminated. However, the specification of other similar functions (for example, strncpy) define the parameter as array of char, i.e. it may be not zero-terminated.

Problem location(s) in the standard

Linux Standard Base Core Specification 3.1, Chapter 13. Base Libraries, 13.5. Interface Definitions for libc, description of function strnlen.

Possible consequences

The application developer may have to implement the function for determining the length of fixed-size string that can be applied not only for strings but also for arrays of char. Such implementation will not be common and will be less effective than strnlen().

Possible solutions

State that the parameter ‘s’ is array of char instead of string. This requirement should be valid because «strnlen() looks only at the first maxlen characters at s and never beyond s + maxlen».

Accepted

LSB Bugzilla, 1329

Status

Fixed in LSB 3.2

[Home]