#845172 manpages-dev: no function protypes in example from mbstowcs(3)

#845172#5
Date:
2016-11-21 03:20:59 UTC
From:
To:
Dear Maintainer,

In example from man mbstowcs there is an error. If we compile it, we get the following output:

$ gcc example.c
example.c: In function ‘main’:
example.c:67:21: warning: implicit declaration of function ‘iswalpha’ [-Wimplicit-function-declaration]
                if (!iswalpha(*wp))
                     ^~~~~~~~
example.c:72:24: warning: implicit declaration of function ‘iswupper’ [-Wimplicit-function-declaration]
                    if (iswupper(*wp))
                        ^~~~~~~~
example.c:75:24: warning: implicit declaration of function ‘iswlower’ [-Wimplicit-function-declaration]
                    if (iswlower(*wp))
                        ^~~~~~~~

Now we add "#include <wctype.h>" to the beginning of this example and the warning disappears.

But there is another trouble. If we compile with "-Wconversion" gcc option, we get this output:

$ gcc -Wconversion example.c
example.c: In function ‘main’:
example.c:68:30: warning: conversion to ‘wint_t {aka unsigned int}’ from ‘wchar_t {aka int}’ may change the sign of the result [-Wsign-conversion]
                if (!iswalpha(*wp))
                              ^
example.c:72:29: warning: conversion to ‘wint_t {aka unsigned int}’ from ‘wchar_t {aka int}’ may change the sign of the result [-Wsign-conversion]
                if (iswalpha(*wp)) {
                             ^
example.c:73:33: warning: conversion to ‘wint_t {aka unsigned int}’ from ‘wchar_t {aka int}’ may change the sign of the result [-Wsign-conversion]
                    if (iswupper(*wp))
                                 ^
example.c:76:33: warning: conversion to ‘wint_t {aka unsigned int}’ from ‘wchar_t {aka int}’ may change the sign of the result [-Wsign-conversion]
                    if (iswlower(*wp))
                                 ^

#845172#10
Date:
2016-11-21 12:05:24 UTC
From:
To:
Upstream maintainer here.

I added the missing include.

But I am unsure what to do about the other point (regarding gcc
-Wconversion). There is an analogous situation with islower() and
similar functions, where the solution is described by an update I
recently added for the upcoming upstream release

       The standards require that the argument c for these  functions  is
       either  EOF  or a value that is representable in the type unsigned
       char.  If the argument c is of type  char,  it  must  be  cast  to
       unsigned char, as in the following example:

           char c;
           ...
           res = toupper((unsigned char) c);

       This  is necessary because char may be the equivalent signed char,
       in which case a byte where the  top  bit  is  set  would  be  sign
       extended  when converting to int, yielding a value that is outside
       the range of unsigned char.

However, we don't have a similar solution for iswlower(), because
there is no "(unsigned wchar_t)" cast. And casting to (wint_t) seems
incorrect to me, because if wchar_t is a signed type smaller than
wint_t, then sign extension could occur.

I could be wrong, but it seems like an implementation bug that one of
these types is signed and the other is unsigned.

Cheers,

Michael

#845172#15
Date:
2016-11-21 12:05:24 UTC
From:
To:
Upstream maintainer here.

I added the missing include.

But I am unsure what to do about the other point (regarding gcc
-Wconversion). There is an analogous situation with islower() and
similar functions, where the solution is described by an update I
recently added for the upcoming upstream release

       The standards require that the argument c for these  functions  is
       either  EOF  or a value that is representable in the type unsigned
       char.  If the argument c is of type  char,  it  must  be  cast  to
       unsigned char, as in the following example:

           char c;
           ...
           res = toupper((unsigned char) c);

       This  is necessary because char may be the equivalent signed char,
       in which case a byte where the  top  bit  is  set  would  be  sign
       extended  when converting to int, yielding a value that is outside
       the range of unsigned char.

However, we don't have a similar solution for iswlower(), because
there is no "(unsigned wchar_t)" cast. And casting to (wint_t) seems
incorrect to me, because if wchar_t is a signed type smaller than
wint_t, then sign extension could occur.

I could be wrong, but it seems like an implementation bug that one of
these types is signed and the other is unsigned.

Cheers,

Michael

#845172#20
Date:
2022-01-26 19:02:07 UTC
From:
To:
Confirmed to be present in man-pages-4.09 (first packaged in Debian in
4.09-1), hence this bug could be closed accordingly.

I share that feeling. However, IMO the actual bug was the missing
include which had been fixed, so I still think this bug could just be closed.

Cheers,
Flo

#845172#25
Date:
2024-05-17 11:25:36 UTC
From:
To:

tamtam