Closed LutzenH closed 2 years ago
Hello 👋! I think I found a small bug in utf8ncat when the function is executed with size_t n being 0. The function will still write all remaining bytes to the dst buffer.
utf8ncat
size_t n
0
dst
for example:
utf8_int8_t dst[12] = { 'h', 'e', 'l', 'l', 'o', '\0' }; const utf8_int8_t* src = "world"; utf8ncat(dst, src, 0); // dst will be { 'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd', '\0', '\0' };
If I am not mistaken it is because size_t being unsigned which causes the following --n to wraparound:
size_t
--n
https://github.com/sheredom/utf8.h/blob/89f6a439f7e0acf5b07ecb924911ea74de63c1ce/utf8.h#L631
I presume this is not defined behavior and that this is a bug.
Good find! Hopefully fixed in #98.
Hello 👋! I think I found a small bug in
utf8ncat
when the function is executed withsize_t n
being0
. The function will still write all remaining bytes to thedst
buffer.for example:
If I am not mistaken it is because
size_t
being unsigned which causes the following--n
to wraparound:https://github.com/sheredom/utf8.h/blob/89f6a439f7e0acf5b07ecb924911ea74de63c1ce/utf8.h#L631
I presume this is not defined behavior and that this is a bug.