Fix some usually disabled compiler warnings (#1286)

* Fixes from temporarily re-enabling more compiler warnings

* More edits suggested by cppcheck

* Fix hanging on append_yylval_string

* Fix FOR loop increment
This commit is contained in:
Sylvie
2024-01-18 14:47:20 -05:00
committed by GitHub
parent d179f3ed28
commit 66fd5a7062
13 changed files with 36 additions and 31 deletions

View File

@@ -243,7 +243,7 @@ bool yywrap(void)
// Avoid arithmetic overflow runtime error
uint32_t forValue = (uint32_t)contextStack->forValue +
(uint32_t)contextStack->forStep;
contextStack->forValue = forValue >= 0 ? (int32_t)forValue
contextStack->forValue = forValue <= INT32_MAX ? forValue
: -(int32_t)~forValue - 1;
struct Symbol *sym = sym_AddVar(contextStack->forName,
contextStack->forValue);

View File

@@ -1421,8 +1421,8 @@ static char const *readInterpolation(size_t depth)
}
#define append_yylval_string(c) do { \
char v = (c); /* Evaluate c exactly once in case it has side effects. */ \
if (i < sizeof(yylval.string)) \
/* Evaluate c exactly once in case it has side effects */ \
if (char v = (c); i < sizeof(yylval.string)) \
yylval.string[i++] = v; \
} while (0)

View File

@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
warnings = false;
break;
unsigned int maxValue;
unsigned long maxValue;
case 'X':
maxValue = strtoul(musl_optarg, &endptr, 0);

View File

@@ -265,7 +265,7 @@ static uint32_t getSymbolID(struct Symbol *sym)
return sym->ID;
}
static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, uint8_t *rpn,
static void writerpn(uint8_t *rpnexpr, uint32_t *rpnptr, const uint8_t *rpn,
uint32_t rpnlen)
{
char symName[512];

View File

@@ -372,22 +372,20 @@ void warning(enum WarningID id, char const *fmt, ...)
switch (warningState(id)) {
case WARNING_DISABLED:
return;
break;
case WARNING_ENABLED:
printDiag(fmt, args, "warning: ", ": [-W%s]\n ", flag);
break;
case WARNING_ERROR:
printDiag(fmt, args, "error: ", ": [-Werror=%s]\n ", flag);
va_end(args);
return;
break;
case WARNING_DEFAULT:
unreachable_();
// Not reached
case WARNING_ENABLED:
break;
}
printDiag(fmt, args, "warning: ", ": [-W%s]\n ", flag);
va_end(args);
}