-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
The function strlcpy_is_not_posix receives a size argument that comes from strlen(), which does not include the null terminator ('\0') in its count:
Line 78 in 7dc53a4
| strlcpy_is_not_posix(copy, str, len2); |
Line 44 in 7dc53a4
| unsigned int strlcpy_is_not_posix(char *dest, char *src, unsigned int size) |
However, strlcpy_is_not_posix then copies up to size - 1 characters, assuming room is needed for the null terminator. Since size already equals the actual length of the string (excluding \0), subtracting 1 causes the last character of the string to be omitted — resulting in malformed XPM lines:
Line 53 in 7dc53a4
| while (src[i] != '\0' && i < (size - 1)) |
This leads to a crash when calling mlx_xpm_to_image.
I'm guessing this happens to remove the '\n' characters of every line, but well-formed XPM data should not have those characters to begin with.
Removing the "- 1" solves the problem, but if stripping a potential newline is intentional, manually checking and replacing a final \n with \0 only if it exists could do it.
Other solution would be just using the original strlcpy.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels