From: Wolfgang Stöggl Date: Tue, 19 Sep 2017 14:48:39 +0000 (+0200) Subject: Avoid using VLA in optparse.c under Windows (MSC) X-Git-Tag: v1.7.1~106^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=13b9c5b49ff6bc8ff7c617d30a94363b6fac7be8;p=thirdparty%2Frrdtool-1.x.git Avoid using VLA in optparse.c under Windows (MSC) - Fixes compilation errors, when building under Windows (e.g. VS2015): ..\src\optparse.c(195): error C2057: expected constant expression ..\src\optparse.c(195): error C2466: cannot allocate an array of constant size 0 ..\src\optparse.c(195): error C2133: 'optstring': unknown size - Variable length arrays are not currently supported in Visual Studio - Use malloc() instead of variable length array in case of MSC --- diff --git a/src/optparse.c b/src/optparse.c index 35391648..9040ba8b 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -1,4 +1,7 @@ #include +#ifdef _MSC_VER +#include /* for malloc(), free() */ +#endif #include "optparse.h" #define opterror(options, format, ...) \ @@ -192,7 +195,12 @@ long_fallback(struct optparse *options, const struct optparse_long *longopts, int *longindex) { +#ifdef _MSC_VER + /* Variable length arrays are not currently supported in Visual Studio */ + char *optstring = malloc(optstring_length(longopts)); +#else char optstring[optstring_length(longopts)]; +#endif optstring_from_long(longopts, optstring); int result = optparse(options, optstring); if (longindex != NULL) { @@ -202,6 +210,9 @@ long_fallback(struct optparse *options, if (longopts[i].shortname == options->optopt) *longindex = i; } +#ifdef _MSC_VER + free(optstring); +#endif return result; }