From 1836d095f88ff83d9499c1e979362352a1fa400b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 21 Dec 2025 14:27:16 -0500 Subject: Minor fix for checking return values --- src/stdlib/intX.c.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/stdlib/intX.c.h') diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h index 0910c7f1..72dfe6ed 100644 --- a/src/stdlib/intX.c.h +++ b/src/stdlib/intX.c.h @@ -55,12 +55,12 @@ public void NAMESPACED(serialize)(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) { (void)info, (void)pointers; #if INTX_C_H__INT_BITS < 32 - fwrite(obj, sizeof(INT_T), 1, out); + if (fwrite(obj, sizeof(INT_T), 1, out) != sizeof(INT_T)) fail("Failed to write whole integer"); #else INT_T i = *(INT_T *)obj; UINT_T z = (UINT_T)((i << 1L) ^ (i >> (INTX_C_H__INT_BITS - 1L))); // Zigzag encode while (z >= 0x80L) { - fputc((uint8_t)(z | 0x80L), out); + if (fputc((uint8_t)(z | 0x80L), out) == EOF) fail("Failed to write full integer"); z >>= 7L; } fputc((uint8_t)z, out); @@ -71,11 +71,13 @@ public void NAMESPACED(deserialize)(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info) { (void)info, (void)pointers; #if INTX_C_H__INT_BITS < 32 - fread(outval, sizeof(INT_T), 1, in); + if (fread(outval, sizeof(INT_T), 1, in) != sizeof(INT_T)) fail("Failed to read full integer"); #else UINT_T z = 0; for (size_t shift = 0;; shift += 7) { - uint8_t byte = (uint8_t)fgetc(in); + int i = fgetc(in); + if (i == EOF) fail("Failed to read whole integer"); + uint8_t byte = (uint8_t)i; z |= ((UINT_T)(byte & 0x7F)) << shift; if ((byte & 0x80) == 0) break; } -- cgit v1.2.3 From 4a6c0438f9a2c82e834116e3e1bc110b8cae8432 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 23 Dec 2025 13:58:33 -0500 Subject: Big speedup my trimming down MAP_LIST macro and inlining some applications of it. --- src/stdlib/intX.c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/stdlib/intX.c.h') diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h index 72dfe6ed..03322e5b 100644 --- a/src/stdlib/intX.c.h +++ b/src/stdlib/intX.c.h @@ -98,7 +98,7 @@ Text_t NAMESPACED(as_text)(const void *i, bool colorize, const TypeInfo_t *info) (void)info; if (!i) return Text(NAME_STR); Text_t text = _int64_to_text((int64_t)(*(INT_T *)i)); - return colorize ? Texts(Text("\033[35m"), text, Text("\033[m")) : text; + return colorize ? Text$concat(Text("\033[35m"), text, Text("\033[m")) : text; } public Text_t NAMESPACED(value_as_text)(INT_T i) { return _int64_to_text((int64_t)i); } -- cgit v1.2.3 From cfce376f585e0cd0231e95843617f75bd65b6c07 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 28 Dec 2025 17:27:05 -0500 Subject: Change autoformatter to no longer allow single-line functions --- src/stdlib/intX.c.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/stdlib/intX.c.h') diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h index 03322e5b..3e6648f7 100644 --- a/src/stdlib/intX.c.h +++ b/src/stdlib/intX.c.h @@ -101,7 +101,9 @@ Text_t NAMESPACED(as_text)(const void *i, bool colorize, const TypeInfo_t *info) return colorize ? Text$concat(Text("\033[35m"), text, Text("\033[m")) : text; } public -Text_t NAMESPACED(value_as_text)(INT_T i) { return _int64_to_text((int64_t)i); } +Text_t NAMESPACED(value_as_text)(INT_T i) { + return _int64_to_text((int64_t)i); +} public PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInfo_t *info) { (void)info; @@ -117,7 +119,9 @@ CONSTFUNC bool NAMESPACED(is_between)(const INT_T x, const INT_T low, const INT_ return low <= x && x <= high; } public -CONSTFUNC INT_T NAMESPACED(clamped)(INT_T x, INT_T min, INT_T max) { return x < min ? min : (x > max ? max : x); } +CONSTFUNC INT_T NAMESPACED(clamped)(INT_T x, INT_T min, INT_T max) { + return x < min ? min : (x > max ? max : x); +} public Text_t NAMESPACED(hex)(INT_T i, Int_t digits_int, bool uppercase, bool prefix) { Int_t as_int = Int$from_int64((int64_t)i); -- cgit v1.2.3 From dbae987f1fb54da795185a03f4c00d56a639f8cd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 31 Dec 2025 15:13:32 -0500 Subject: Changed is_between() to be bidirectional --- src/stdlib/intX.c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/stdlib/intX.c.h') diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h index 3e6648f7..04c8ef3b 100644 --- a/src/stdlib/intX.c.h +++ b/src/stdlib/intX.c.h @@ -116,7 +116,7 @@ PUREFUNC bool NAMESPACED(equal)(const void *x, const void *y, const TypeInfo_t * } public CONSTFUNC bool NAMESPACED(is_between)(const INT_T x, const INT_T low, const INT_T high) { - return low <= x && x <= high; + return (low <= x && x <= high) || (high <= x && x <= low); } public CONSTFUNC INT_T NAMESPACED(clamped)(INT_T x, INT_T min, INT_T max) { -- cgit v1.2.3