From 00daf6295e1e057cd35b85dc976548387b545fb6 Mon Sep 17 00:00:00 2001 From: NY00123 Date: Sat, 4 Apr 2020 19:41:58 +0000 Subject: [PATCH] SW: Fix a few memory access errors related to demo support From-SVN: r8797 --- source/sw/src/demo.cpp | 3 +++ source/sw/src/game.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/sw/src/demo.cpp b/source/sw/src/demo.cpp index 1aacf6ff6..2b6cde3ed 100644 --- a/source/sw/src/demo.cpp +++ b/source/sw/src/demo.cpp @@ -363,6 +363,9 @@ DemoTerm(void) if (DemoSyncTest||DemoSyncRecord) { + if (DemoSyncFile == NULL) + return; + fclose(DemoSyncFile); DemoSyncFile = NULL; } diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 25fdbcc51..252383a43 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -606,11 +606,13 @@ void LoadDemoRun(void) if (fin) { memset(DemoName,'\0',sizeof(DemoName)); - for (i = 0; TRUE; i++) + for (i = 0; i < ARRAY_SSIZE(DemoName); i++) { if (fscanf(fin, "%s", DemoName[i]) == EOF) break; } + if (i == ARRAY_SSIZE(DemoName)) + initputs("WARNING: demos.run is too long, ignoring remaining files\n"); fclose(fin); } @@ -621,11 +623,13 @@ void LoadDemoRun(void) { fgets(ds, 6, fin); sscanf(ds,"%d",&DemoTextYstart); - for (i = 0; TRUE; i++) + for (i = 0; i < ARRAY_SSIZE(DemoText); i++) { if (fgets(DemoText[i], SIZ(DemoText[0])-1, fin) == NULL) break; } + if (i == ARRAY_SSIZE(DemoText)) + initputs("WARNING: demotxt.run is too long, trimming the text\n"); fclose(fin); }