src/stdlib


Log

Author Commit Date CI Message
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
Sam Lantinga 880842cf 2016-12-31T16:14:51 Fixed bug 3531 - internal SDL_vsnprintf implementation access memory outside given buffer ranges Tristan The internal SDL_vsnprintf implementation accesses memory outside buffer. The bug existed also inside the format (%) processing, which was fixed with Bug 3441. But there is still an invalid access, if we do not have any format inside the source string and the destination string is shorter than the format string. You can use any string for this test, as long it is longer than the buffer. Example: va_list argList; char buffer[4]; SDL_vsnprintf(buffer, sizeof(buffer), "Testing", argList); The bug is located on the 'else' branch of the format char test: while (*fmt) { if (*fmt == '%') { ... } else { if (left > 1) { *text = *fmt; --left; } ++fmt; ++text; } } if (left > 0) { *text = '\0'; } As you can see that text is always incremented, even when left is already one. When then on the last lines, *text is assigned the NULL char, the pointer is located outside bounds.
Ryan C. Gordon 232ae688 2016-11-23T17:20:28 Still more compiler warning fixes for various platforms.
Sam Lantinga 57d01d7d 2016-11-13T22:57:41 Patch from Sylvain to fix clang warnings
Sam Lantinga 74e1dd4c 2016-11-11T13:14:00 Define _GNU_SOURCE when building SDL
Sam Lantinga 79f6ba5a 2016-11-11T03:18:16 Fixed signed/unsigned comparison warnings in Visual Studio
Sam Lantinga 40b571c9 2016-11-06T10:01:08 Fixed bug 3468 - _allshr in SDL_stdlib.c is not working properly Mark Pizzolato On Windows with Visual Studio, when building SDL as a static library using the x86 (32bit) mode, several intrinsic operations are implemented in code in SDL_stdlib.c. One of these, _allshr() is not properly implemented and fails for some input. As a result, some operations on 64bit data elements (long long) don't always work. I classified this bug as a blocker since things absolutely don't work when the affected code is invoked. The affected code is only invoked when SDL is compiled in x86 mode on Visual Studio when building a SDL as a static library. This build environment isn't common, and hence the bug hasn't been noticed previously. I reopened #2537 and mentioned this problem and provided a fix. That fix is provided again here along with test code which could be added to some of the SDL test code. This test code verifies that the x86 intrinsic routines produce the same results as the native x64 instructions which these routines emulate under the Microsoft compiler. The point of the tests is to make sure that Visual Studio x86 code produces the same results as Visual Studio x64 code. Some of the arguments (or boundary conditions) may produce different results on other compiler environments, so the tests really shouldn't be run on all compilers. The test driver only actually exercised code when the compiler defines _MSC_VER, so the driver can generically be invoked without issue.
Sam Lantinga 8109b137 2016-10-17T21:47:33 Partial fix for bug 3092 - Statically link sdl2 with /MT for msvc Mike Linford I'm also having trouble statically linking SDL2 on Visual Studio 2015 with /MT. My symptom is that memcpy is being defined twice.
Sam Lantinga 9db5e9aa 2016-10-10T02:58:29 Made #if defined(X) consistent
Sam Lantinga 6dedbc43 2016-10-10T02:58:12 Make sure we have iconv.h before building with it
Sam Lantinga 73f2c541 2016-10-07T16:44:42 Fixed bug 2885 - SDL_stdinc.h doesn't need to include iconv.h Ryan C. Gordon We still include iconv.h in SDL_stdinc.h, probably because this header might have referenced the native iconv functions and types directly. Since these are hidden behind a stable ABI now and never just a #define for the system iconv, we shouldn't need this header included from a public SDL header anymore, slowing down external apps compiles and pulling tons of stuff into the namespace.
Ryan C. Gordon 46f44f66 2016-10-04T14:25:31 Fixed potential buffer overflow in SDL_vsnprintf() (thanks, Taylor!). Fixes Bugzilla #3441. "When using internal SDL_vsnprintf(), and source string length is greater than destination, the final NULL char will be written beyond destination size. Primary issue that is SDL_strlcpy returns length of source string (SDL_PrintString()), not how much is written to destination. The destination ptr is then incremented by this length before the sanity check is done. Destination string is properly terminated, but an extra NULL char will be written beyond destination buffer length. Patch used internally is attached which fixes primary issue with SDL_strlcpy() in SDL_PrintString() and adjusts sanity checks to increment destination ptr safely."
Sam Lantinga 5333deab 2016-03-11T08:30:18 Quick fix for qsort off-by-one error.
Ryan C. Gordon 32c70cc5 2016-02-21T13:07:14 stdlib: Restored previous qsort() implementation; the licensing is resolved. Thanks to Gareth McCaughan for changing his code to the zlib license on our behalf!
Ryan C. Gordon 09ae4df5 2016-02-15T03:37:01 Another attempt to fix Windows build.
Ryan C. Gordon 18f74c6e 2016-02-15T03:21:26 Patched to compile on Visual Studio.
Ryan C. Gordon 014956ac 2016-02-15T03:16:46 Replaced SDL_qsort with public domain code from PDCLib: http://pdclib.e43.eu/
Sam Lantinga e2fd1c0f 2016-01-02T11:17:06 Backed out commit 80ce90dbc266, this causes Visual Studio build failure on buildbot
Sam Lantinga ac444cd3 2016-01-02T10:25:53 Fixed bug 3092 - Statically link sdl2 with /MT for msvc Martin Gerhardy According to https://msdn.microsoft.com/de-de/library/2kzt1wy3%28v=vs.120%29.aspx when one is using /MT for msvc compilations the libcmt.lib is already linked to the binary. This lib includes the symbol that is now guarded (see attached patch) by the #ifndef _MT.
Sam Lantinga 42065e78 2016-01-02T10:10:34 Updated copyright to 2016
Philipp Wiesemann 0e45984f 2015-06-21T17:33:46 Fixed crash if initialization of EGL failed but was tried again later. The internal function SDL_EGL_LoadLibrary() did not delete and remove a mostly uninitialized data structure if loading the library first failed. A later try to use EGL then skipped initialization and assumed it was previously successful because the data structure now already existed. This led to at least one crash in the internal function SDL_EGL_ChooseConfig() because a NULL pointer was dereferenced to make a call to eglBindAPI().
Ryan C. Gordon d98cfe14 2015-06-07T20:00:20 Let's assume that if VS2005 and VS2010 do it, VS2008 probably does, too.
Ryan C. Gordon 753f95c5 2015-06-07T19:58:42 VS2005 tweaks (thanks, Ozkan!). Fixes Bugzilla #2895. His notes: The following trivial changes make SDL2 tree (mostly) compatible with Visual Studio 2005: * SDL_stdlib.c: Similar to VS2010 and newer, VS2005 also generates memcpy(), (it also generates memset(), see below), so propagate the #if condition to cover VS2005. * SDL_pixels.c (SDL_CalculateGammaRamp): VS2005 generates a memset() call for gamma==0 case, so replace the if loop with SDL_memset(). * SDL_windowsvideo.h: Include msctf.h only with VS2008 and newer, otherwise include SDL_msctf.h * SDL_windowskeyboard.c: Adjust the #ifdefs so that SDL_msctf.h inclusion is always recognized correctly.