Commit graph

88 commits

Author SHA1 Message Date
Ozkan Sezer
e37d95f937 SDL_vsnprintf: implement precision for the integral value printers. 2018-09-27 00:32:15 +03:00
Ozkan Sezer
d7099fbf16 SDL_string.c: added comments to three SDL_FormatInfo members. 2018-09-26 20:47:34 +03:00
Ozkan Sezer
fcc9b1cd3c SDL_vsnprintf: when '.' is specified, take precision as 0 if it is < 0. 2018-09-26 17:11:40 +03:00
Ozkan Sezer
a52fce6463 SDL_vsnprintf: string printer now honors the precision. (bug #4263.) 2018-09-26 10:40:02 +03:00
Ozkan Sezer
f86cde1073 SDL_vsnprintf: %.* and %* now parse precision and width. (bug #4263.) 2018-09-26 10:38:40 +03:00
Sam Lantinga
db39b4811f 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
2018-08-09 16:00:17 -07:00
Ozkan Sezer
6f33890b09 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.
2018-05-10 09:02:39 +03:00
Sam Lantinga
12d8a48c9e Fixed bug 3947 - replace strlcpy with memcpy in SDL_strdup() 2018-02-13 08:13:29 -08:00
Sam Lantinga
346af016a5 Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga
4d7a2db434 Added functions to query and set the SDL memory allocation functions:
SDL_GetMemoryFunctions()
    SDL_SetMemoryFunctions()
    SDL_GetNumAllocations()
2017-10-12 13:44:28 -07:00
Sam Lantinga
acf5b23fc8 Fixed compiler warning with mingw-w64 2017-09-04 22:14:57 -07:00
Sam Lantinga
bb037eaa61 Added SDL_wcscmp() 2017-08-13 20:37:49 -07:00
Sam Lantinga
2c1a763b32 More fixes for the SDL_scanf code 2017-08-12 00:01:24 -07:00
Sam Lantinga
34dac84de4 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?
2017-08-11 19:36:12 -07:00
Ryan C. Gordon
eee7f7062f Fixed whitespace code style.
--HG--
extra : histedit_source : fa3b73fb933e94008249907e1beb7700132f81b5
2017-05-29 00:51:38 -04:00
Ryan C. Gordon
d202066528 stdlib: added SDL_utf8strlen().
--HG--
extra : histedit_source : 3ef78f0c18ad1f096882e5e079119fe0b3fef6db%2Cd98e52df919c701f80b47d989028227d060e2ecb
2017-05-29 03:01:05 -04:00
Ryan C. Gordon
e0bd890446 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().
2017-02-14 02:49:08 -05:00
Sam Lantinga
101fc7428b Fixed building with mingw32 2017-01-18 11:57:27 -08:00
Sam Lantinga
1b24bfad38 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga
c2ab4c5a76 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.
2016-12-31 16:14:51 -08:00
Sam Lantinga
dae32409e9 Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
Sam Lantinga
c5767b9997 Define _GNU_SOURCE when building SDL 2016-11-11 13:14:00 -08:00
Ryan C. Gordon
3070ead2b3 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."
2016-10-04 14:25:31 -04:00
Sam Lantinga
7ee8dda270 Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Ryan C. Gordon
d84b85b5c4 Make sure we have the vsscanf() prototype (thanks, Ozkan!).
issue seen with glibc-2.8.

Fixes Bugzilla #2721.
2015-05-28 14:34:38 -04:00
Sam Lantinga
56b58afdbe Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Ryan C. Gordon
db239776a8 Clang static analysis builds should use C runtime directly.
This is a little macro magic to use malloc() directly instead of SDL_malloc(),
 etc, so static analysis tests that know about the C runtime can function
 properly, and understand that we are dealing with heap allocations, etc.

This changed our static analysis report from 5 outstanding bugs to 30.

5x as many bugs were hidden by SDL_malloc() not being recognized as malloc()
 by the static analyzer!
2015-01-05 01:41:42 -05:00
Sam Lantinga
6ace4262ba Fixed bug 2596 - SDL_SetError fails on on NULL on systems with vsnprintf
sfalexrog

On systems with vsnprintf call SDL_SetError fails when passed a NULL as an argument. SDL's implementation checks for NULL (as seen in the commit: https://hg.libsdl.org/SDL/rev/5ba49d7a39a0), but system implementation may crash.
2014-06-21 11:52:53 -07:00
Sam Lantinga
b5f085ab73 Fixed crash with SDL_SetError(NULL) 2014-06-07 17:31:50 -07:00
Sam Lantinga
53d9d2c232 Added annotations to help code analysis tools
CR: Bruce Dawson
2014-06-04 10:56:56 -07:00
Yuri Kunde Schlesner
9483e21015 Align pointer in SDL_memset before doing Uint32 loop
Some more recent compilers emit SSE aligned store instructions for the loop,
causing crashes if the destination buffer isn't aligned on a 32-bit boundary.
This would also crash on platforms like ARM that require aligned stores.

This fixes a crash inside SDL_FillRect that happens with the official x64 mingw
build.

--HG--
extra : rebase_source : afd0f856fd814e7345bd0c7d20ddac3ba0422813
2014-05-10 21:48:46 -03:00
Sam Lantinga
d7940a513e Fixed bug 2374 - Update copyright for 2014...
Is it that time already??
2014-02-02 00:53:27 -08:00
Ryan C. Gordon
82edee6971 Make internal SDL sources include SDL_internal.h instead of SDL_config.h
The new header will include SDL_config.h, but allows for other global stuff.

--HG--
extra : rebase_source : ddf4a4c0dc2c554b98c82700798f343cd91b16e3
2013-11-24 23:56:17 -05:00
Ryan C. Gordon
1e82be1804 Patched stdlib changes to compile on Windows.
--HG--
extra : rebase_source : a782472e239edc31e70be994953d4da5a55edd95
2013-12-09 13:30:35 -05:00
Ryan C. Gordon
3003efb88d Added SDL_vsscanf().
--HG--
extra : rebase_source : 088d093790a7ed95d73c307523587e95c8356f4b
2013-11-24 23:35:38 -05:00
Sam Lantinga
f8e51377ab Fixed bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
pjz

SDL_ltoa(-2147483648,s,10) only returns "-" because there is a bug in the code:

    if ( value < 0 ) {
        *bufp++ = '-';
        value = -value;
    }

but -(-2147483648) is still -2147483648 (0x80000000) as signed int (or long), so the following loop doesn't run at all. Similar bug are also in SDL_lltoa.

BTW, there is no sanity check for radix.
2013-12-11 21:17:24 -08:00
Sam Lantinga
e74da38529 Fixed bug 2082 - SDL stdlib implementation does not force upper case for %X format specifier
norfanin

When SDL_vsnprintf handles the %x format specifier, a boolean is set to signal forced lower case. It also should be able to signal forced upper case for the %X specifier. A boolean is not sufficient anymore. The attached patch adds an enum for the three cases: lower, upper and no change.
2013-09-05 06:59:34 -07:00
Sam Lantinga
a7954b42d0 Fixed SDL printf output for 0x%.8x 2013-07-23 12:44:14 -07:00
Ryan C. Gordon
30b6bedb57 Fixed some compiler warnings that Visual Studio reported. 2013-07-20 19:51:51 -04:00
Philipp Wiesemann
e96e39d53b Removed not needed variable and work in standard library.
Found by Cppcheck (that variable's value was never used).
2013-07-20 21:35:26 +02:00
Sam Lantinga
8ad9316ca3 Fixed mingw32 build 2013-07-06 00:15:01 -07:00
Sam Lantinga
ed07a40c62 Fixed build errors on Mac OS X 2013-07-06 00:06:44 -07:00
Sam Lantinga
cfd541e89c Removed the inline functions from SDL_stdinc.h
Having the SDL functions inline is causing build issues, and in the case of malloc(), etc. causing malloc/free mismatches, if the application build environment differs from the SDL build environment.

In the interest of safety and consistency, the functions will always be in the SDL library and will only be redirected to the C library there, if they are available.

See the following threads on the SDL mailing list for the gruesome details:
* SDL_stdinc.h inlines problematic when application not compiled in exact same feature environment
* Error compiling program against SDL2 with -std=c++11 g++ flag
2013-07-05 23:57:19 -07:00
Sam Lantinga
b3ec1b660b Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0 2013-05-27 16:18:11 -07:00
Sam Lantinga
f423813732 Fixed Windows build 2013-05-24 03:29:31 -07:00
Sam Lantinga
03210bff7e Added the beginning of automated tests for the standard C library routines.
Implemented more SDL_snprintf format specifiers.
2013-05-24 03:23:21 -07:00
Ryan C. Gordon
280675858c Fixed another infinite recursion accident in stdlib. 2013-04-05 16:34:59 -04:00
Ryan C. Gordon
6bcac2ad67 Fixed infinite recursion (thanks, Rainer!). 2013-04-03 10:36:15 -04:00
Ryan C. Gordon
7e934f8f75 Improvements to stdlib.
All SDL_* functions are always available as real symbols, so you can always
link against them as a stable ABI. By default, however, all the things that
might have dithered down to macros in your application are now force-inlined,
to give you the same effect as before and theoretically better performance,
but still solve the classic macro problems.

Elsewhere, we provide real functions for these things that simply wrap the
inline functions, in case one needs to have a real function available.

Also: this exposed bugs: SDL_abs() does something different if you had the
macro vs the libc function, SDL_memcpy() returns a void* in the function
but not the macro, etc.
2013-03-15 01:01:20 -04:00
Sam Lantinga
95dcfa4c28 Happy New Year! 2013-02-15 08:47:44 -08:00