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 {
5555 }
5656}
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
6060fn 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
6262}
6363
6464fn __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 {
6767}
6868
6969fn 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)))));
7171}
7272
7373fn __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 {
8585}
8686
8787fn 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)))));
8989}
9090
9191fn __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 {
9494}
9595
9696fn 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)))));
9898}
9999
100100fn __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 {
103103}
104104
105105fn 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)))));
107107}
108108
109109fn __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 {
112112}
113113
114114fn 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)))));
116116}
117117
118118fn __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 {
121121}
122122
123123fn 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)))));
125125}
126126
127127fn __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 {
130130}
131131
132132fn 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)))));
134134}
135135
136136fn __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 {
139139}
140140
141141fn 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)))));
143143}
144144
145145fn __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 {
148148}
149149
150150fn 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)))));
152152}
153153
154154fn __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 {
157157}
158158
159159fn 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)))));
161161}
162162
163163fn __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 {
166166}
167167
168168fn 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))));
170170}
171171
172172fn __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 {
175175}
176176
177177fn 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))));
179179}
180180
181181fn __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 {
184184}
185185
186186fn 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)))));
188188}
189189
190190fn toascii(c: c_int) callconv(.c) c_int {