mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Hex string formatter check incorrectly rejected slices.
This commit is contained in:
committed by
Christoffer Lerno
parent
fad87b294b
commit
59a1590955
@@ -9,6 +9,7 @@
|
||||
|
||||
### Fixes
|
||||
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.
|
||||
- Hex string formatter check incorrectly rejected slices.
|
||||
|
||||
### Stdlib changes
|
||||
|
||||
|
||||
@@ -3164,10 +3164,10 @@ static inline Type *type_flatten_no_export(Type *type)
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool type_flat_is_char_array(Type *type)
|
||||
static inline bool type_flat_is_char_array_slice(Type *type)
|
||||
{
|
||||
type = type_flatten(type);
|
||||
if (type->type_kind != TYPE_ARRAY) return false;
|
||||
if (type->type_kind != TYPE_ARRAY && type->type_kind != TYPE_SLICE) return false;
|
||||
switch (type->array.base->type_kind)
|
||||
{
|
||||
case TYPE_I8:
|
||||
@@ -3178,6 +3178,7 @@ static inline bool type_flat_is_char_array(Type *type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
INLINE Type *type_vector_type(Type *type)
|
||||
{
|
||||
Type *flatten = type_flatten(type);
|
||||
|
||||
@@ -2081,9 +2081,9 @@ NEXT_FLAG:
|
||||
goto NEXT;
|
||||
case 'H':
|
||||
case 'h':
|
||||
if (!type_flat_is_char_array(type))
|
||||
if (!type_flat_is_char_array_slice(type))
|
||||
{
|
||||
RETURN_SEMA_ERROR(vaargs[idx], "Expected a char array here.");
|
||||
RETURN_SEMA_ERROR(vaargs[idx], "Expected a char array or slice here.");
|
||||
}
|
||||
goto NEXT;
|
||||
default:
|
||||
|
||||
12
test/test_suite/statements/format_hex_array.c3
Normal file
12
test/test_suite/statements/format_hex_array.c3
Normal file
@@ -0,0 +1,12 @@
|
||||
import std::io;
|
||||
|
||||
macro convert_string_to_hex(String s)
|
||||
{
|
||||
io::printfn("%02hx", (char[])s);
|
||||
}
|
||||
|
||||
fn void main() {
|
||||
char[3] x = x"0305ff";
|
||||
io::printfn("%02h", x);
|
||||
convert_string_to_hex("colors");
|
||||
}
|
||||
Reference in New Issue
Block a user