Explorar el Código

Fixed crash in SDL_startswith() when passed NULL strings

Fixes https://github.com/libsdl-org/SDL/issues/15451

(cherry picked from commit f3d7df54e2c06ba1921621d069984c599b572372)
Sam Lantinga hace 2 semanas
padre
commit
89eb50b25e
Se han modificado 1 ficheros con 2 adiciones y 1 borrados
  1. 2 1
      src/SDL_utils.c

+ 2 - 1
src/SDL_utils.c

@@ -111,7 +111,8 @@ void SDL_CalculateFraction(float x, int *numerator, int *denominator)
 
 
 bool SDL_startswith(const char *string, const char *prefix)
 bool SDL_startswith(const char *string, const char *prefix)
 {
 {
-    if (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0) {
+    if (string && prefix &&
+        SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0) {
         return true;
         return true;
     }
     }
     return false;
     return false;