fix a bug

This commit is contained in:
blueloveTH 2025-04-20 23:41:18 +08:00
parent f5c67576aa
commit 6c25f6b1de
2 changed files with 2 additions and 1 deletions

View File

@ -896,7 +896,7 @@ static bool color32_from_hex_STATIC(int argc, py_Ref argv) {
c11_color32 color; c11_color32 color;
int res; int res;
if(hex.size == 7) { if(hex.size == 7) {
res = scanf(hex.data, "#%2hhx%2hhx%2hhx", &color.r, &color.g, &color.b); res = sscanf(hex.data, "#%2hhx%2hhx%2hhx", &color.r, &color.g, &color.b);
if(res != 3) return ValueError("invalid hex color format"); if(res != 3) return ValueError("invalid hex color format");
color.a = 255; color.a = 255;
} else { } else {

View File

@ -12,6 +12,7 @@ assert a.with_a(255).a == 255 and a.with_a(255).g == a.g
assert a.to_hex() == '#64c8ff78' assert a.to_hex() == '#64c8ff78'
assert color32.from_hex('#64c8ff78') == a assert color32.from_hex('#64c8ff78') == a
assert color32.from_hex('#64c8ff') == a.with_a(255)
assert rgb(100, 200, 255) != a assert rgb(100, 200, 255) != a
assert rgba(100, 200, 255, 120 / 255) == a assert rgba(100, 200, 255, 120 / 255) == a