authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-10 14:20:22+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-13 05:58:41+01:00
log65092d6e4c33043fcd7025a1e8190dbeac943882
tree6d7650cb2f3f46c7fc51a2121873b522a6e33815
parent8e69ab8a31809f1e7e6fe8de67faa36b63219270

fix(libzigc): properly handle EOF in `ctype`

* EOF is defined as a negative integer, thus it doesn't fit in an `u8`!

1 files changed, 15 insertions(+), 15 deletions(-)

lib/c/ctype.zig+15-15
...@@ -55,10 +55,10 @@ comptime {...@@ -55,10 +55,10 @@ comptime {
55 }55 }
56}56}
5757
58// NOTE: If the input is not representable as an unsigned char or is not EOF the behaviour is undefined.58// NOTE: If the input is not representable as an unsigned char or is not EOF (which is a negative integer value) the behaviour is undefined.
5959
60fn isalnum(c: c_int) callconv(.c) c_int {60fn isalnum(c: c_int) callconv(.c) c_int {
61 return @intFromBool(std.ascii.isAlphanumeric(@intCast(c)));61 return @intFromBool(std.ascii.isAlphanumeric(@truncate(@as(c_uint, @bitCast(c))))); // @truncate instead of @intCast as we have to handle EOF
62}62}
6363
64fn __isalnum_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {64fn __isalnum_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -67,7 +67,7 @@ fn __isalnum_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -67,7 +67,7 @@ fn __isalnum_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
67}67}
6868
69fn isalpha(c: c_int) callconv(.c) c_int {69fn isalpha(c: c_int) callconv(.c) c_int {
70 return @intFromBool(std.ascii.isAlphabetic(@intCast(c)));70 return @intFromBool(std.ascii.isAlphabetic(@truncate(@as(c_uint, @bitCast(c)))));
71}71}
7272
73fn __isalpha_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {73fn __isalpha_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -85,7 +85,7 @@ fn __isblank_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -85,7 +85,7 @@ fn __isblank_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
85}85}
8686
87fn iscntrl(c: c_int) callconv(.c) c_int {87fn iscntrl(c: c_int) callconv(.c) c_int {
88 return @intFromBool(std.ascii.isControl(@intCast(c)));88 return @intFromBool(std.ascii.isControl(@truncate(@as(c_uint, @bitCast(c)))));
89}89}
9090
91fn __iscntrl_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {91fn __iscntrl_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -94,7 +94,7 @@ fn __iscntrl_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -94,7 +94,7 @@ fn __iscntrl_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
94}94}
9595
96fn isdigit(c: c_int) callconv(.c) c_int {96fn isdigit(c: c_int) callconv(.c) c_int {
97 return @intFromBool(std.ascii.isDigit(@intCast(c)));97 return @intFromBool(std.ascii.isDigit(@truncate(@as(c_uint, @bitCast(c)))));
98}98}
9999
100fn __isdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {100fn __isdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -103,7 +103,7 @@ fn __isdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -103,7 +103,7 @@ fn __isdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
103}103}
104104
105fn isgraph(c: c_int) callconv(.c) c_int {105fn isgraph(c: c_int) callconv(.c) c_int {
106 return @intFromBool(std.ascii.isGraphical(@intCast(c)));106 return @intFromBool(std.ascii.isGraphical(@truncate(@as(c_uint, @bitCast(c)))));
107}107}
108108
109fn __isgraph_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {109fn __isgraph_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -112,7 +112,7 @@ fn __isgraph_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -112,7 +112,7 @@ fn __isgraph_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
112}112}
113113
114fn islower(c: c_int) callconv(.c) c_int {114fn islower(c: c_int) callconv(.c) c_int {
115 return @intFromBool(std.ascii.isLower(@intCast(c)));115 return @intFromBool(std.ascii.isLower(@truncate(@as(c_uint, @bitCast(c)))));
116}116}
117117
118fn __islower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {118fn __islower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -121,7 +121,7 @@ fn __islower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -121,7 +121,7 @@ fn __islower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
121}121}
122122
123fn isprint(c: c_int) callconv(.c) c_int {123fn isprint(c: c_int) callconv(.c) c_int {
124 return @intFromBool(std.ascii.isPrint(@intCast(c)));124 return @intFromBool(std.ascii.isPrint(@truncate(@as(c_uint, @bitCast(c)))));
125}125}
126126
127fn __isprint_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {127fn __isprint_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -130,7 +130,7 @@ fn __isprint_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -130,7 +130,7 @@ fn __isprint_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
130}130}
131131
132fn ispunct(c: c_int) callconv(.c) c_int {132fn ispunct(c: c_int) callconv(.c) c_int {
133 return @intFromBool(std.ascii.isPunctuation(@intCast(c)));133 return @intFromBool(std.ascii.isPunctuation(@truncate(@as(c_uint, @bitCast(c)))));
134}134}
135135
136fn __ispunct_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {136fn __ispunct_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -139,7 +139,7 @@ fn __ispunct_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -139,7 +139,7 @@ fn __ispunct_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
139}139}
140140
141fn isspace(c: c_int) callconv(.c) c_int {141fn isspace(c: c_int) callconv(.c) c_int {
142 return @intFromBool(std.ascii.isWhitespace(@intCast(c)));142 return @intFromBool(std.ascii.isWhitespace(@truncate(@as(c_uint, @bitCast(c)))));
143}143}
144144
145fn __isspace_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {145fn __isspace_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -148,7 +148,7 @@ fn __isspace_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -148,7 +148,7 @@ fn __isspace_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
148}148}
149149
150fn isupper(c: c_int) callconv(.c) c_int {150fn isupper(c: c_int) callconv(.c) c_int {
151 return @intFromBool(std.ascii.isUpper(@intCast(c)));151 return @intFromBool(std.ascii.isUpper(@truncate(@as(c_uint, @bitCast(c)))));
152}152}
153153
154fn __isupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {154fn __isupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -157,7 +157,7 @@ fn __isupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -157,7 +157,7 @@ fn __isupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
157}157}
158158
159fn isxdigit(c: c_int) callconv(.c) c_int {159fn isxdigit(c: c_int) callconv(.c) c_int {
160 return @intFromBool(std.ascii.isHex(@intCast(c)));160 return @intFromBool(std.ascii.isHex(@truncate(@as(c_uint, @bitCast(c)))));
161}161}
162162
163fn __isxdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {163fn __isxdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -166,7 +166,7 @@ fn __isxdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -166,7 +166,7 @@ fn __isxdigit_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
166}166}
167167
168fn tolower(c: c_int) callconv(.c) c_int {168fn tolower(c: c_int) callconv(.c) c_int {
169 return std.ascii.toLower(@intCast(c));169 return std.ascii.toLower(@truncate(@as(c_uint, @bitCast(c))));
170}170}
171171
172fn __tolower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {172fn __tolower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -175,7 +175,7 @@ fn __tolower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -175,7 +175,7 @@ fn __tolower_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
175}175}
176176
177fn toupper(c: c_int) callconv(.c) c_int {177fn toupper(c: c_int) callconv(.c) c_int {
178 return std.ascii.toUpper(@intCast(c));178 return std.ascii.toUpper(@truncate(@as(c_uint, @bitCast(c))));
179}179}
180180
181fn __toupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {181fn __toupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
...@@ -184,7 +184,7 @@ fn __toupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {...@@ -184,7 +184,7 @@ fn __toupper_l(c: c_int, locale: *anyopaque) callconv(.c) c_int {
184}184}
185185
186fn isascii(c: c_int) callconv(.c) c_int {186fn isascii(c: c_int) callconv(.c) c_int {
187 return @intFromBool(std.ascii.isAscii(@intCast(c)));187 return @intFromBool(std.ascii.isAscii(@truncate(@as(c_uint, @bitCast(c)))));
188}188}
189189
190fn toascii(c: c_int) callconv(.c) c_int {190fn toascii(c: c_int) callconv(.c) c_int {