src/stdlib


Log

Author Commit Date CI Message
Sam Lantinga 120c76c8 2022-01-03T09:40:00 Updated copyright for 2022
Sam Lantinga ab6d0d4d 2021-12-28T15:58:15 Fixed undefined behavior in SDL_memset() (thanks andrewrk!) Fixes https://github.com/libsdl-org/SDL/issues/5147
Ozkan Sezer 840339c4 2021-12-18T14:01:02 SDL_utf8strlcpy: store trailing_bytes explicity as unsigned type.
Ozkan Sezer 507d4bcd 2021-12-18T14:01:02 SDL_utf8strlen: run bit-test explicitly on unsigned char
Ozkan Sezer a2b13e58 2021-12-02T02:28:24 SDL_iconv_string: avoid memory leak if realloc() fails.
Ozkan Sezer f14a8bfa 2021-12-01T21:33:02 fix whitespace.
Ozkan Sezer b71bfdaa 2021-12-01T20:50:40 SDL_iconv.c (encodings): mark "WCHAR_T" as ENCODING_UTF16LE for OS/2 too whcar_t is unsigned short in os/2, like windows
Misa 3bf7994f 2021-09-27T14:38:12 Add and use `SDL_FALLTHROUGH` for fallthroughs Case fallthrough warnings can be suppressed using the __fallthrough__ compiler attribute. Unfortunately, not all compilers have this attribute, or even have __has_attribute to check if they have the __fallthrough__ attribute. [[fallthrough]] is also available in C++17 and the next C2x, but not everyone uses C++17 or C2x. So define the SDL_FALLTHROUGH macro to deal with those problems - if we are using C++17 or C2x, it expands to [[fallthrough]]; else if the compiler has __has_attribute and has the __fallthrough__ attribute, then it expands to __attribute__((__fallthrough__)); else it expands to an empty statement, with a /* fallthrough */ comment (it's a do {} while (0) statement, because users of this macro need to use a semicolon, because [[fallthrough]] and __attribute__((__fallthrough__)) require a semicolon). Clang before Clang 10 and GCC before GCC 7 have problems with using __attribute__ as a sole statement and warn about a "declaration not declaring anything", so fall back to using the /* fallthrough */ comment if we are using those older compiler versions. Applications using SDL are also free to use this macro (because it is defined in begin_code.h). All existing /* fallthrough */ comments have been replaced with this macro. Some of them were unnecessary because they were the last case in a switch; using SDL_FALLTHROUGH in those cases would result in a compile error on compilers that support __fallthrough__, for having a __attribute__((__fallthrough__)) statement that didn't immediately precede a case label.
Sam Lantinga abc12a83 2021-11-11T15:58:44 Revert "Add and use `SDL_FALLTHROUGH` for fallthroughs" This reverts commit 66a08aa3914a98667f212e79b4f0b9453203d656. This causes problems with older compilers: https://github.com/libsdl-org/SDL/pull/4791#issuecomment-966630997
Misa 66a08aa3 2021-09-27T14:38:12 Add and use `SDL_FALLTHROUGH` for fallthroughs Case fallthrough warnings can be suppressed using the __fallthrough__ compiler attribute. Unfortunately, not all compilers have this attribute, or even have __has_attribute to check if they have the __fallthrough__ attribute. [[fallthrough]] is also available in C++17 and the next C2x, but not everyone uses C++17 or C2x. So define the SDL_FALLTHROUGH macro to deal with those problems - if we are using C++17 or C2x, it expands to [[fallthrough]]; else if the compiler has __has_attribute and has the __fallthrough__ attribute, then it expands to __attribute__((__fallthrough__)); else it expands to an empty statement, with a /* fallthrough */ comment (it's a do {} while (0) statement, because users of this macro need to use a semicolon, because [[fallthrough]] and __attribute__((__fallthrough__)) require a semicolon). Applications using SDL are also free to use this macro (because it is defined in begin_code.h). All existing /* fallthrough */ comments have been replaced with this macro. Some of them were unnecessary because they were the last case in a switch; using SDL_FALLTHROUGH in those cases would result in a compile error on compilers that support __fallthrough__, for having a __attribute__((__fallthrough__)) statement that didn't immediately precede a case label.
Sam Lantinga dc4c7d95 2021-11-10T09:48:49 Fixed infinite loop in SDL_vsnprintf() if the format string is too large for the output buffer Fixes https://github.com/libsdl-org/SDL/issues/4940
Sylvain e8731933 2021-11-09T13:32:28 Fixed warning: macro is not used
Sam Lantinga 5b646cd1 2021-11-07T22:58:44 Build hidapi code into SDL as a new public API This prevents conflicts with hidapi linked with applications, as well as allowing applications to make use of HIDAPI on Android and other platforms that might not normally have an implementation available.
Ryan C. Gordon 3acb1725 2021-11-07T12:26:39 stdlib: SDL_snprintf now adds decimal places for ("%f", 0.0). This patch was from @Markvy (thanks!). Fixes #4795.
Ozkan Sezer 6407d4b0 2021-11-05T17:10:02 remove unnecessary parentheses from SDL_abs()
Kevin Colour 6cbee063 2021-11-05T01:17:29 include: Swap parameter names in atan2 functions
Ozkan Sezer 3ea35fe5 2021-10-04T21:32:00 fix SDL_atoi() fixes https://github.com/libsdl-org/SDL/issues/4811
Sam Lantinga 4ec259a7 2021-09-22T19:06:11 Fixed building on Visual Studio 2013 and older
Cameron Cawley 25a614bc 2021-09-14T20:37:35 Add SDL_asprintf and SDL_vasprintf
Sam Lantinga 79b0aae8 2021-09-22T11:42:10 The return value of SDL_snprintf is the number of characters that would have been written. Fixes https://github.com/libsdl-org/SDL/issues/4762
Sam Lantinga a91ab883 2021-08-06T12:28:03 Fixed building on Windows with cmake, ninja, and clang
Jessica Clarke 8f38ba4d 2021-07-29T18:02:47 Fix casts that should be using uintptr_t This is needed to support CHERI, and thus Arm's experimental Morello prototype, where pointers are implemented using unforgeable capabilities that include bounds and permissions metadata to provide fine-grained spatial and referential memory safety, as well as revocation by sweeping memory to provide heap temporal memory safety. On most systems (anything with a flat memory hierarchy rather than using segment-based addressing), size_t and uintptr_t are the same type. However, on CHERI, size_t is just an integer offset, whereas uintptr_t is still a capability as described above. Casting a pointer to size_t will strip the metadata and validity tag, and casting from size_t to a pointer will result in a null-derived capability whose validity tag is not set, and thus cannot be dereferenced without faulting. The audio and cursor casts were harmless as they intend to stuff an integer into a pointer, but using uintptr_t is the idiomatic way to do that and silences our compiler warnings (which our build tool makes fatal by default as they often indicate real problems). The iconv and egl casts were true positives as SDL_iconv_t and iconv_t are pointer types, as is NativeDisplayType on most OSes, so this would have trapped at run time when using the round-tripped pointers. The gles2 casts were also harmless; the OpenGL API defines this argument to be a pointer type (and uses the argument name "pointer"), but it in fact represents an integer offset, so like audio and cursor the additional idiomatic cast is needed to silence the warning.
Ankith 559be8aa 2021-03-15T15:18:10 fix invalid out of bounds UTF8 handling
Ozkan Sezer 1957ffd2 2021-03-14T11:04:28 fixed a typo in SDL_ceilf()
Cacodemon345 dacf6cfb 2021-03-11T12:03:22 Fix compilation with iconv on FreeBSD
Ozkan Sezer a2fbc452 2021-02-15T03:02:32 replace i386 checks with __i386__
Misa 3da58b47 2021-02-13T15:11:40 Fix errors with fallback impls of SDL_isxdigit() and SDL_ispunct() SDL_isxdigit() should only accept A-Fa-f, not A-Za-z (it shouldn't use SDL_isalpha()). SDL_ispunct() shouldn't accept spaces (it should use SDL_isgraph() instead).
Misa dfe219ec 2021-02-13T11:21:19 Add all missing "is characteristic" stdlib functions SDL has been missing a bunch of these 'isX' functions for some time, where X is some characteristic of a given character. This commit adds the rest of them to the SDL stdlib, so now we have: - SDL_isalpha() - SDL_isalnum() - SDL_isblank() - SDL_iscntrl() - SDL_isxdigit() - SDL_ispunct() - SDL_isprint() - SDL_isgraph()
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
Ozkan Sezer 8a32ee24 2020-12-30T01:00:24 removed MSVC strtok_s use from SDL_strtokr(). no other ??_s are used elsewhere in SDL_stdinc. besides, C11 has a strtok_s with a different signature.
Sam Lantinga 93ccdee8 2020-12-23T13:47:49 Fixed bug 5404 - stdlib: Added SDL_round, SDL_roundf, SDL_lround and SDL_lroundf Cameron Cawley stdlib: Added SDL_round, SDL_roundf, SDL_lround and SDL_lroundf The default implementation is based on the one used in the Windows RT video driver.
Sam Lantinga cb361896 2020-12-09T07:16:22 Fixed bug 5235 - All internal sources should include SDL_assert.h Ryan C. Gordon We should really stick this in SDL_internal.h or something so it's always available.
Sam Lantinga f487d63a 2020-12-03T18:16:56 Fixed crash when printing NULL wide character string
Sam Lantinga 46a84478 2020-11-24T12:43:01 Added SDL_wcscasecmp() and SDL_wcsncasecmp()
Ryan C. Gordon 55e59a4f 2020-11-16T18:48:13 crc32: Fixed include path.
Sam Lantinga 71e32f5e 2020-11-16T15:00:15 Added SDL_crc32()
Sam Lantinga 8b29aadd 2020-11-12T14:34:11 Fixed warning when building on Windows
Ryan C. Gordon e410b34f 2020-07-24T22:24:03 stdlib: Corrected implementation of SDL_wcsncmp. It was a copy/paste of SDL_strcmp, apparently, not SDL_strncmp, so it ignored the maxlen parameter. Thanks to Jack Powell for pointing this out!
Sam Lantinga 31916f11 2020-05-27T09:22:12 Fixed compiler warning building on FreeBSD
Ryan C. Gordon b0a20a15 2020-05-05T12:48:55 stdlib: Fixed compiler warnings about int vs size_t.
Sam Lantinga 8b60d39c 2020-05-02T14:43:17 Fixed bug 5112 - CMake won't compile in VS2019 dark_sylinc Trying to build SDL with VS2019 using CMake will encounter a linking error More specifically: 1>SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL
Sam Lantinga 1d879787 2020-04-13T13:24:56 Fixed implicit linkage to ftol2() on Windows
Ryan C. Gordon d292f6bd 2020-04-10T12:17:14 stdlib: Add SDL_trunc and SDL_truncf
Sam Lantinga 342f62ca 2020-03-10T16:29:28 Fixed bug 5022 - SDL_iconv_string can get stuck in an infinite loop when encountering invalid characters ciremo6483 In `SDL_iconv_string` the `while (inbytesleft > 0)` loop can end up in a state where it never terminates because the library `iconv` function called from `SDL_iconv` doesn't consume any bytes. This happened when a `WCHAR_T` input string was being converted to `UTF-8` but contained invalid characters. It would first It would first skip a few bytes due to `case SDL_ICONV_EILSEQ` but when there were 3 bytes remaining of `inbytesleft` `iconv` just didn't consume anything more (but didn't throw an error either). It just so happens that the Microsoft Classic IntelliMouse `product_string` contains such invalid characters (`"Microsoft? Classic IntelliMouse?"`), meaning the function would get stuck with said mouse plugged in. A fix for this would be to check if `inbytesleft` was unchanged after an iteration and in that case either decrement the counter like when `SDL_ICONV_EILSEQ` is returned or simply break the loop.
Sam Lantinga aa384ad0 2020-03-02T15:21:07 Fixed bug 5001 - Feature request: SDL_isupper & SDL_islower
Sam Lantinga a8780c6a 2020-01-16T20:49:25 Updated copyright date for 2020
Sam Lantinga 65096446 2019-11-20T16:42:50 Improved XInput VID/PID detection and added SDL_wcsstr() and SDL_wcsncmp()
Ozkan Sezer eb8f14bb 2019-11-20T20:40:50 added SDL_strtokr() as a replacement for POSIX strtok_r (bug #4046.)
Ozkan Sezer fea3c8bd 2019-10-31T17:10:02 SDL_qsort.c: sync comments with version 1.15 from mainstream
Sylvain Becker b458d7a2 2019-10-30T15:13:55 Readability: remove redundant cast to the same type
Ryan C. Gordon 4001e6b3 2019-09-26T13:44:49 stdlib: Patched to compile.
Ryan C. Gordon 987aa311 2019-09-26T12:55:05 stdlib: Try to coerce VS2019 to not replace some loops with memset() calls. Fixes (?) Bugzilla #4759.
Ozkan Sezer 2ea0ec62 2019-07-31T00:07:15 better readability..
Ozkan Sezer 5f04ed5f 2019-07-31T00:06:50 SDL_iconv_string: add (char*) casts before SDL_malloc() calls.
Cameron Cawley e7b514d8 2019-01-13T23:36:31 riscos: Fix iconv warnings
Sam Lantinga 5e13087b 2019-01-04T22:01:14 Updated copyright for 2019
Ozkan Sezer d3fa42b8 2018-11-18T19:28:20 os/2 bits for SDL_malloc.c -- from libffi
Sam Lantinga 9e8e0fb7 2018-09-28T20:48:18 Fixed bug 4283 - SDL's version of memset is different from libc's janisozaur memset's documentation reads: * The memset() function shall copy c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s. (http://pubs.opengroup.org/onlinepubs/9699919799/functions/memset.html) * Sets the first count characters of dest to the character c. (https://msdn.microsoft.com/en-us/library/1fdeehz6.aspx) * write a byte to a byte string (https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/memset.3.html) The highlight here is they all mean a single _byte_, even though memset receives a parameter of type int, which can hold more data than a single byte. SDL's implementation of memset, however, does not clear any of the higher bits, causing an erroneous behaviour when passed an argument bigger than 0xff.
Ozkan Sezer 31596f23 2018-09-29T01:24:10 SDL_vsnprintf: implemented '+' flag for signed integers printing. it is, of course, ignored for %u, %x, %o and %p.
Ozkan Sezer 49803c86 2018-09-29T00:51:24 SDL_vsnprintf: fix numerics if both zero-padding and a field are given. it used to place zeroes between the sign and the number. (space-padding from within SDL_PrintString() seems OK: spaces are added before sign.) also fixed the maxlen handling if the number has a sign.
Ozkan Sezer bb5516ac 2018-09-27T09:37:36 SDL_vsnprintf() updates for zero-padding: - remove force-enabling of pad_zeroes for %u for compatibility (was added in https://hg.libsdl.org/SDL/rev/701f4a25df89) - ignore pad_zeroes for %s and %S - ignore pad_zeroes for %d, %i and %u if a precision is given
Ozkan Sezer 6eeb8593 2018-09-27T01:10:50 SDL_string.c (SDL_PrintString): avoid MSVC signed/unsigned mismatch warning
Ozkan Sezer 5342ae2b 2018-09-27T01:00:50 SDL_string.c (SDL_IntPrecisionAdjust): avoid MSVC generating a memset()
Ozkan Sezer d2131ac1 2018-09-27T00:32:15 SDL_vsnprintf: implement precision for the integral value printers.
Ozkan Sezer ffc19ee2 2018-09-26T20:47:34 SDL_string.c: added comments to three SDL_FormatInfo members.
Ozkan Sezer 8743e975 2018-09-26T17:11:40 SDL_vsnprintf: when '.' is specified, take precision as 0 if it is < 0.
Ozkan Sezer 69ab8541 2018-09-26T10:40:02 SDL_vsnprintf: string printer now honors the precision. (bug #4263.)
Ozkan Sezer d0e9a364 2018-09-26T10:38:40 SDL_vsnprintf: %.* and %* now parse precision and width. (bug #4263.)
Sam Lantinga 5febdfce 2018-09-24T11:49:25 Fixed whitespace
Sam Lantinga d2042e1e 2018-08-09T16:00:17 Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms. Added SDL_GameControllerRumble() and SDL_JoystickRumble() for simple force feedback outside of the SDL haptics API
Ozkan Sezer f45f33bd 2018-08-05T10:01:01 SDL_expf: return SDL_exp() instead of SDL_uclibc_exp() for consistency.
Ethan Lee b4fe7412 2018-08-04T11:52:46 SDL_exp
Ozkan Sezer 652d59fb 2018-05-10T09:02:39 make sure SDL_vsnprintf() nul terminates if it is using _vsnprintf The change makes sure that SDL_vsnprintf() nul terminates if it is using _vsnprintf() for the job. I made this patch for Watcom, whose _vsnprintf() doesn't guarantee nul termination. The preprocessor check can be extended to windows in general too, if required. Closes bug #3769.
Sam Lantinga 3b4c2fdf 2018-02-13T08:13:29 Fixed bug 3947 - replace strlcpy with memcpy in SDL_strdup()
Ethan Lee 11c348b4 2018-01-17T11:53:09 SDL_log10
Sam Lantinga e3cc5b2c 2018-01-03T10:03:25 Updated copyright for 2018
Sam Lantinga bcdf8b91 2017-11-04T17:35:03 Added SDL_fmod() and SDL_fmodf()
Sam Lantinga 34502143 2017-11-04T15:34:14 Added float versions of SDL's math functions
Sam Lantinga 758156a7 2017-11-04T09:37:29 Fixed bug 3917 - Android, issues with getManifestEnvironmentVariable We're going to push the manifest environment variables from the Java side instead of continually querying for them from the native side.
Sam Lantinga 8fd0c22a 2017-10-24T00:17:07 Added the ability to set SDL hints from AndroidManifest.xml (thanks Rachel!) This is especially useful for things like the accelerometer hint which could be needed before application main().
Sam Lantinga fc60db86 2017-10-12T17:17:09 Fixed compiler warning
Sam Lantinga 21cd2df6 2017-10-12T14:02:24 Fixed compiler warning
Sam Lantinga 9c580e14 2017-10-12T13:44:28 Added functions to query and set the SDL memory allocation functions: SDL_GetMemoryFunctions() SDL_SetMemoryFunctions() SDL_GetNumAllocations()
Ozkan Sezer bef0fec1 2017-10-12T14:28:05 make sure that SDL_malloc(0) or SDL_calloc(0,x) doesn't return NULL.
Sam Lantinga 19114b03 2017-09-10T12:42:38 Fixed bug 3813 - gcc7 fallthrough warnings in SDL_iconv.c and SDL_pixels.c
Sam Lantinga 8ed16ea4 2017-09-10T10:43:04 Fixed compile warning
Sam Lantinga 1b2492ed 2017-09-08T15:08:03 Fixed 64-bit build warning
Sam Lantinga c1fd0fbb 2017-09-04T22:14:57 Fixed compiler warning with mingw-w64
Ryan C. Gordon ae667da6 2017-08-29T15:52:49 Fixed a bunch of compiler warnings.
Ryan C. Gordon 620f5342 2017-08-29T00:36:17 stdlib: An implementation of SDL_scalbn using ldexp() (thanks, Ozkan!). Fixes Bugzilla #3767.
Sam Lantinga fcf83e79 2017-08-21T16:30:24 Fixed bug 3768 - provide a quick copysign() solution for watcom Ozkan Sezer The following patch provides a quick copysign solution for Watcom/x86
Sam Lantinga f1829d95 2017-08-13T20:37:49 Added SDL_wcscmp()
Sam Lantinga affab6ad 2017-08-12T00:01:24 More fixes for the SDL_scanf code
Sam Lantinga b5ea3c6d 2017-08-11T21:30:06 Fixed bug 3284 - minor correction for SDL_setenv on _WIN32__ platform Coriiander Here is a minor correction for a non-breaking mistake in SDL_setenv for __WIN32__ platform. See below for details. FILE: "SDL/src/stdlib/SDL_getenv.c" FUNCTION: (__WIN32__ platform) int SDL_setenv(const char *name, const char *value, int overwrite) CODE: if (!overwrite) { char ch = 0; const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch)); if (len > 0) { return 0; /* asked not to overwrite existing value. */ } } WHAT'S WRONG: The 3th argument to GetEnvironmentVariable (being DWORD nSize) must be the number of characters, not the number of bytes. SDL currently passes "the size of 1 char", rather "1". While it is non-breaking (1=1 after all), it is incorrect. Furthermore there is no need to specify the 2nd and 3th arguments at all. CORRECTION 1: (corrected argument_ if (!overwrite) { char ch = 0; const size_t len = GetEnvironmentVariableA(name, &ch, 1); if (len > 0) { return 0; /* asked not to overwrite existing value. */ } } CORRECTION 2: (stripped of unneeded code) if (!overwrite) { if (GetEnvironmentVariableA(name, NULL, 0) > 0) { return 0; /* asked not to overwrite existing value. */ } }
Sam Lantinga 441d9ba2 2017-08-11T19:36:12 Fixed bug 3341 - SDL_sscanf() problem e_pluschauskas Why does SDL_sscanf() always returns the number of format specifiers and doesn't implements standard C library behavior?
Ryan C. Gordon d4086e4a 2017-05-29T03:01:05 stdlib: added SDL_utf8strlen().
Ryan C. Gordon 29a047df 2017-05-29T00:51:38 Fixed whitespace code style.
Ryan C. Gordon c93bca48 2017-02-14T02:49:08 stdlib: Fixed crash on SDL_snprintf("%s", NULL). Like other C runtimes, it should probably produce the string "(null)". This bug probably only affected Windows, as most platforms use their standard C runtime's snprintf().
Sam Lantinga 5cb1ca55 2017-01-18T11:57:27 Fixed building with mingw32
Sam Lantinga 45b774e3 2017-01-01T18:33:28 Updated copyright for 2017