24 Commits

Author SHA1 Message Date
8b29a707ab Fix guf_id_pool integer portability 2025-12-23 14:11:06 +01:00
dfd2f0e4da Fix guf_str uninit 2025-12-23 14:11:06 +01:00
6bf47f0ca6 Refactor to use portable minimum-width integers.
The signed and unsigned fixed-width integers (int32_t, uint32_t etc.) are optional
in C99 (and above). Use the non-optional minimum-width integers (int_fast32_t, uint_fast32_t and int_least32_t, uint_least32_t etc.) instead.

To simulate unsigned wrap-around, use the GUF_UWRAP macros in guf_common.h

cf. https://en.cppreference.com/w/c/types/integer (last-retrieved: 2025-05-18)
2025-12-23 14:11:06 +01:00
b7e3eec2c1 Add unsigned integer wrapping functions 2025-12-23 14:11:06 +01:00
1a5a32d9b9 Prevent more potential int promotion bugs 2025-12-23 14:11:06 +01:00
7b2334a668 Fix potential int-promotion bugs in ckdint
Expressions like
(uin16_t)a * (uint16_t)b * (uint16_t)c
might be promoted to (signed) int (in that example, on platforms where sizeof(int) > sizeof(uint16_t)),
and therefore lead to undefined behaviour on overflow.

The above expression can be fixed as
1u * (uint16_t)a * (uint16_t)b * (uint16_t)c
(The 1u makes sure a, b, and c would be promoted to unsigned int (instead of int) on platforms where sizeof(int) > sizeof(uint16_t))

cf. https://stackoverflow.com/questions/27001604/32-bit-unsigned-multiply-on-64-bit-causing-undefined-behavior
2025-12-23 14:11:05 +01:00
9cec01cc50 Add guf_alloc_tracker 2025-12-23 14:11:05 +01:00
52d9f2c859 Add checked mul arithmetic 2025-12-23 14:11:05 +01:00
4111f54159 Add checked arithmetic 2025-12-23 14:11:05 +01:00
111023b7b1 Add guf_tok test 2025-12-23 14:11:05 +01:00
e923775769 Fix guf_str bugs and add tests 2025-12-23 14:11:05 +01:00
e1bc585f68 Use SIZE_MAX instead of SIZE_T_MAX 2025-12-23 14:11:05 +01:00
25cf7f17b7 Fix dict asserts 2025-12-23 14:11:05 +01:00
c8ffde8c19 Fix warnings in release 2025-12-23 14:11:05 +01:00
18f4496204 Fix GUF_DICT_64_BIT_IDX and guf_dict_max_capacity() 2025-12-23 14:11:05 +01:00
5d8fa1cc62 Fix allocation overflow for guf_dbuf and guf_dict
(Implement GUF_ALLOC_MAX_BYTES and GUF_ALLOC_MAX_CAPACITY).
2025-12-23 14:11:05 +01:00
81ab99ff15 Implement guf_str 2025-12-23 14:11:05 +01:00
7e348e74bc Change linalg mat_inverse.
Still not sure whether it's better to calculate
rref[pivot_row][col] * (rref[row][pivot_col] / pivot_val) (option 1)
vs.
rref[pivot_row][col] * rref[row][pivot_col] / pivot_val   (option 2)

(i.e.  a * b / c vs. "a * (b/c))

in terms of floating point error.

But I think option 1 (current commit) is better, since the scale factor
(rref[row][pivot_col] / pivot_val) is always <= 1 here (I think).
2025-12-23 14:11:05 +01:00
ac9fa9f9ce Add quaternion operations 2025-12-23 14:11:05 +01:00
2bf683906b Add more dict tests 2025-12-23 14:11:04 +01:00
8197a5f45f Add dict_erase tests 2025-12-23 14:11:04 +01:00
467f9be00a Refactor 2025-12-23 14:11:04 +01:00
947041838e Add tokeniser 2025-12-23 14:11:04 +01:00
ead8bd8914 Work on utf-8 2025-12-23 14:11:04 +01:00