libmodplug icon indicating copy to clipboard operation
libmodplug copied to clipboard

Fix UB when calling cctype functions

Open glebm opened this issue 1 year ago • 4 comments

Calling cctype functions, such as isspace, with negative values is undefined behaviour.

While glibc allows it, it crashes on uClibc compiled without UCLIBC_HAS_CTYPE_SIGNED.

Fixes the undefined behaviour by casting all arguments to cctype functions to unsigned char.

glebm avatar Dec 21 '22 11:12 glebm

@Konstanty Any chance you can merge this please? It's been tested by the OpenDingux community and it does resolve a few playback issues. Thanks

glebm avatar Jan 08 '23 09:01 glebm

This looks OK, though I think this library still tries to target C++98. I would recommend C-style casts instead. (@Konstanty @sezero please correct me if I am wrong.)

AliceLR avatar Jan 24 '23 23:01 AliceLR

static_cast is in C++98 https://en.cppreference.com/w/cpp/language/static_cast

glebm avatar Jan 25 '23 01:01 glebm

You're right, nevermind!

AliceLR avatar Jan 25 '23 02:01 AliceLR