Commit 2c62a90
common: cast arguments to character classification functions to unsigned char
We get failures of this type on the cygwin CI machine:
15:28:20 common.c: In function `bt_common_string_is_printable`:
15:28:20 common.c:786:16: error: array subscript has type `char` [-Werror=char-subscripts]
15:28:20 786 | if (!isprint(*ch) && *ch != '\n' && *ch != '\r' &&
15:28:20 | ^~~
This error only pops up on some platforms that have isprint implemented
using a lookup table. This table is indexed using `*ch`, which is a
char. And because char is signed on some platforms, gcc warns that this
is dangerous: we could access the array with a negative index, which
would yield unexpected results.
This is on purpose in newlib (the libc used by cygwin, apparently), see
this comment:
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/ctype.h;h=a0009af17485acc3d70586a0051269a7a9c350d5;hb=HEAD#l78
The Linux man page for isprint also mentions it:
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 of 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.
Add casts to unsigned char to fix the various instances of this error.
Change-Id: Ice2305490997f595c6f5140a8be2abaa7fd1d8f6
Signed-off-by: Simon Marchi <[email protected]>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3194
Reviewed-by: Philippe Proulx <[email protected]>
CI-Build: Michael Jeanson <[email protected]>
Tested-by: jenkins <[email protected]>
(cherry picked from commit 994cd34)1 parent 6559432 commit 2c62a90
6 files changed
+7
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
783 | 783 | | |
784 | 784 | | |
785 | 785 | | |
786 | | - | |
| 786 | + | |
787 | 787 | | |
788 | 788 | | |
789 | 789 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
138 | 138 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
776 | | - | |
| 776 | + | |
777 | 777 | | |
778 | 778 | | |
779 | 779 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
642 | | - | |
| 642 | + | |
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
0 commit comments