From 4ab9deb96cff2cee146a3f9607f369d0d0e87b00 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Tue, 29 Nov 2016 11:51:16 +0700 Subject: [PATCH] Avoid using Variable Length Arrays (which are refused by clang) --- Source/Game.h | 1 + Source/main.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/Game.h b/Source/Game.h index 102f026..c531c02 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -249,5 +249,6 @@ const int commandLineOptionsNumber = 8; extern const option::Descriptor usage[12]; extern option::Option commandLineOptions[commandLineOptionsNumber]; +extern option::Option* commandLineOptionsBuffer; #endif diff --git a/Source/main.cpp b/Source/main.cpp index 1e78908..33a7b37 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -517,6 +517,8 @@ void CleanUp (void) { LOGFUNC; + delete[] commandLineOptionsBuffer; + SDL_Quit(); #ifndef __MINGW32__ // FIXME: Temporary workaround for GL-8 #define GL_FUNC(ret,fn,params,call,rt) p##fn = NULL; @@ -526,7 +528,6 @@ void CleanUp (void) // the context is destroyed and libGL unloaded by SDL_Quit(). pglDeleteTextures = glDeleteTextures_doNothing; #endif // __MINGW32__ - } // -------------------------------------------------------------------------- @@ -651,6 +652,7 @@ const option::Descriptor usage[] = }; option::Option commandLineOptions[commandLineOptionsNumber]; +option::Option* commandLineOptionsBuffer; int main(int argc, char **argv) { @@ -660,21 +662,24 @@ int main(int argc, char **argv) std::cerr << "Found incorrect command line option number" << std::endl; return 1; } - option::Option buffer[stats.buffer_max]; - option::Parser parse(true, usage, argc, argv, commandLineOptions, buffer); + commandLineOptionsBuffer = new option::Option[stats.buffer_max]; + option::Parser parse(true, usage, argc, argv, commandLineOptions, commandLineOptionsBuffer); if (parse.error()) { + delete[] commandLineOptionsBuffer; return 1; } if (commandLineOptions[HELP]) { option::printUsage(std::cout, usage); + delete[] commandLineOptionsBuffer; return 0; } if (option::Option* opt = commandLineOptions[UNKNOWN]) { std::cerr << "Unknown option: " << opt->name << "\n"; option::printUsage(std::cerr, usage); + delete[] commandLineOptionsBuffer; return 1; } @@ -689,8 +694,10 @@ int main(int argc, char **argv) { newGame(); - if (!SetUp ()) + if (!SetUp ()) { + delete[] commandLineOptionsBuffer; return 42; + } bool gameDone = false; bool gameFocused = true; -- 2.39.5