瀏覽代碼

snake: check allocated memory before use

Anonymous Maarten 10 月之前
父節點
當前提交
590e1196d0
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      examples/game/01-snake/snake.c

+ 3 - 0
examples/game/01-snake/snake.c

@@ -310,6 +310,9 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
     }
 
     AppState *as = SDL_calloc(1, sizeof(AppState));
+    if (!as) {
+        return SDL_APP_FAILURE;
+    }
 
     *appstate = as;