Commit Graph

82 Commits

Author SHA1 Message Date
Ozkan Sezer
4b1296e5dd 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
add5711436 Fixed bug 3947 - replace strlcpy with memcpy in SDL_strdup() 2018-02-13 08:13:29 -08:00
Sam Lantinga
a9072159b2 Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga
eea9c57d52 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
13bf98643c Fixed compiler warning with mingw-w64 2017-09-04 22:14:57 -07:00
Sam Lantinga
2f632ba2c6 Added SDL_wcscmp() 2017-08-13 20:37:49 -07:00
Sam Lantinga
1ba7e20948 More fixes for the SDL_scanf code 2017-08-12 00:01:24 -07:00
Sam Lantinga
118d289bbb 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
23b242bba7 Fixed whitespace code style. 2017-05-29 00:51:38 -04:00
Ryan C. Gordon
bf09ce5fce stdlib: added SDL_utf8strlen(). 2017-05-29 03:01:05 -04:00
Ryan C. Gordon
32ada55b55 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
83184dca24 Fixed building with mingw32 2017-01-18 11:57:27 -08:00
Sam Lantinga
d77ab77a7a Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga
4b6138f947 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
5e1151257d Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
Sam Lantinga
8a080aef5c Define _GNU_SOURCE when building SDL 2016-11-11 13:14:00 -08:00
Ryan C. Gordon
a9042792d7 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
255c182471 Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Ryan C. Gordon
e15870eb7b 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
78f2198e6c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Ryan C. Gordon
bf02bb2582 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
fe14da0992 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
edfa425a67 Fixed crash with SDL_SetError(NULL) 2014-06-07 17:31:50 -07:00
Sam Lantinga
667b15f3c8 Added annotations to help code analysis tools
CR: Bruce Dawson
2014-06-04 10:56:56 -07:00
Yuri Kunde Schlesner
4927ba7549 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.
2014-05-10 21:48:46 -03:00
Sam Lantinga
dba255c1e5 Fixed bug 2374 - Update copyright for 2014...
Is it that time already??
2014-02-02 00:53:27 -08:00
Ryan C. Gordon
03d5719413 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.
2013-11-24 23:56:17 -05:00
Ryan C. Gordon
572834c79a Patched stdlib changes to compile on Windows. 2013-12-09 13:30:35 -05:00
Ryan C. Gordon
df9f367941 Added SDL_vsscanf(). 2013-11-24 23:35:38 -05:00
Sam Lantinga
337e4a4f6c 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
47b4f56927 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
3452a7d968 Fixed SDL printf output for 0x%.8x 2013-07-23 12:44:14 -07:00
Ryan C. Gordon
ee3cbb1fa6 Fixed some compiler warnings that Visual Studio reported. 2013-07-20 19:51:51 -04:00
Philipp Wiesemann
8b105773a0 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
4c4dbd43a4 Fixed mingw32 build 2013-07-06 00:15:01 -07:00
Sam Lantinga
719799241f Fixed build errors on Mac OS X 2013-07-06 00:06:44 -07:00
Sam Lantinga
69bede6d35 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
9c6d6e4423 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
e3041182ff Fixed Windows build 2013-05-24 03:29:31 -07:00
Sam Lantinga
9ab99a4157 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
1a2d04cab5 Fixed another infinite recursion accident in stdlib. 2013-04-05 16:34:59 -04:00
Ryan C. Gordon
ccf4a46f60 Fixed infinite recursion (thanks, Rainer!). 2013-04-03 10:36:15 -04:00
Ryan C. Gordon
1fa34e72be 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
019c60c1e8 Happy New Year! 2013-02-15 08:47:44 -08:00
Sam Lantinga
129f163eeb Fixed bug in SDL_strcasecmp() with strings of different sizes 2012-12-22 16:52:33 -08:00
Sam Lantinga
b3d60cfcbb Removed executable bit from source files 2012-09-27 14:35:28 -07:00
Sam Lantinga
e256711bb9 Happy New Year! 2011-12-31 09:28:07 -05:00
Sam Lantinga
6371c44a9e Lots of fixes importing SDL source wholesale into a new iOS project 2011-10-31 05:56:58 -04:00
Sam Lantinga
6d456a4116 Added SDL_GetScancodeFromName() and SDL_GetKeyFromName() 2011-10-24 21:34:54 -04:00
Sam Lantinga
6196aa221e SDL 1.3 is now under the zlib license. 2011-04-08 13:03:26 -07:00