- Package:
- manpages-dev
- Source:
- manpages
- Submitter:
- Igor Liferenko
- Date:
- 2024-05-17 11:27:04 UTC
- Severity:
- normal
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))
^
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
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
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
tamtam