Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf8ncat - size wraparound bug #97

Closed
LutzenH opened this issue Feb 17, 2022 · 1 comment 路 Fixed by #98
Closed

utf8ncat - size wraparound bug #97

LutzenH opened this issue Feb 17, 2022 · 1 comment 路 Fixed by #98

Comments

@LutzenH
Copy link

LutzenH commented Feb 17, 2022

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.

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:

utf8.h/utf8.h

Line 631 in 89f6a43

} while (('\0' != *src) && (0 != --n));

I presume this is not defined behavior and that this is a bug.

@sheredom
Copy link
Owner

Good find! Hopefully fixed in #98.

sheredom added a commit that referenced this issue Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants