From 5c4122be854c135a1f66f2db68ec9cde6d5993dc Mon Sep 17 00:00:00 2001 From: Gaius Mulley Date: Fri, 20 Jan 2023 23:39:35 +0000 Subject: [PATCH] PR-108136 modula-2 meets cppcheck part 2 R-108136 modula-2 meets cppcheck part 2 This patch addresses the style warnings mentioned in the PR. The array high style fixes to mc/keyc.mod and gm2-libs/M2Dependent.mod provoke a rebuild of pge and mc. gcc/m2/ChangeLog: * gm2-libs/Args.mod (GetArg): Check index before accessing array. * gm2-libs/M2Dependent.mod (toCString): Check index before accessing array. * mc-boot/GArgs.c: Rebuilt. * mc-boot/GM2Dependent.c: Rebuilt. * mc-boot/Gkeyc.c: Rebuilt. * mc/keyc.mod (seenUIntMin): Initialize once. (seenUIntMax): Initialize once. (checkLimits): Only test seenUIntMin and seenUIntMax once. * pge-boot/GArgs.c: Rebuilt. * pge-boot/GM2Dependent.c: Rebuilt. Signed-off-by: Gaius Mulley --- gcc/m2/gm2-libs/Args.mod | 2 +- gcc/m2/gm2-libs/M2Dependent.mod | 2 +- gcc/m2/mc-boot/GArgs.c | 2 +- gcc/m2/mc-boot/GM2Dependent.c | 2 +- gcc/m2/mc-boot/Gkeyc.c | 4 +--- gcc/m2/mc/keyc.mod | 6 ++---- gcc/m2/pge-boot/GArgs.c | 2 +- gcc/m2/pge-boot/GM2Dependent.c | 2 +- 8 files changed, 9 insertions(+), 13 deletions(-) diff --git a/gcc/m2/gm2-libs/Args.mod b/gcc/m2/gm2-libs/Args.mod index 30f76c6..fa14f8c 100644 --- a/gcc/m2/gm2-libs/Args.mod +++ b/gcc/m2/gm2-libs/Args.mod @@ -62,7 +62,7 @@ BEGIN IF i < GetArgC () THEN Source := GetArgV () ; - WHILE (Source^[i]^[j]#nul) AND (j (UnixArgs_GetArgV ()); - while (((*(*Source).array[i]).array[j] != ASCII_nul) && (j < High)) + while ((j < High) && ((*(*Source).array[i]).array[j] != ASCII_nul)) { a[j] = (*(*Source).array[i]).array[j]; j += 1; diff --git a/gcc/m2/mc-boot/GM2Dependent.c b/gcc/m2/mc-boot/GM2Dependent.c index b9c59cc..fb22f1b 100644 --- a/gcc/m2/mc-boot/GM2Dependent.c +++ b/gcc/m2/mc-boot/GM2Dependent.c @@ -457,7 +457,7 @@ static void toCString (char *str, unsigned int _str_high) high = _str_high; while (i < high) { - if ((str[i] == '\\') && (i < high)) + if ((i < high) && (str[i] == '\\')) { if (str[i+1] == 'n') { diff --git a/gcc/m2/mc-boot/Gkeyc.c b/gcc/m2/mc-boot/Gkeyc.c index 6f17ca5..e000bfe 100644 --- a/gcc/m2/mc-boot/Gkeyc.c +++ b/gcc/m2/mc-boot/Gkeyc.c @@ -600,7 +600,7 @@ static void checkAbs (mcPretty_pretty p) static void checkLimits (mcPretty_pretty p) { - if ((((((((((((((seenMemcpy || seenIntMin) || seenUIntMin) || seenLongMin) || seenULongMin) || seenCharMin) || seenUCharMin) || seenUIntMin) || seenIntMax) || seenUIntMax) || seenLongMax) || seenULongMax) || seenCharMax) || seenUCharMax) || seenUIntMax) + if ((((((((((((seenMemcpy || seenIntMin) || seenUIntMin) || seenLongMin) || seenULongMin) || seenCharMin) || seenUCharMin) || seenIntMax) || seenUIntMax) || seenLongMax) || seenULongMax) || seenCharMax) || seenUCharMax) /* OR seenUIntMax */ { checkGccConfigSystem (p); if (! (mcOptions_getGccConfigSystem ())) @@ -1067,14 +1067,12 @@ static void init (void) seenULongMin = FALSE; seenCharMin = FALSE; seenUCharMin = FALSE; - seenUIntMin = FALSE; seenIntMax = FALSE; seenUIntMax = FALSE; seenLongMax = FALSE; seenULongMax = FALSE; seenCharMax = FALSE; seenUCharMax = FALSE; - seenUIntMax = FALSE; seenLabs = FALSE; seenAbs = FALSE; seenFabs = FALSE; diff --git a/gcc/m2/mc/keyc.mod b/gcc/m2/mc/keyc.mod index 5e1016d..a57103b 100644 --- a/gcc/m2/mc/keyc.mod +++ b/gcc/m2/mc/keyc.mod @@ -457,9 +457,9 @@ PROCEDURE checkLimits (p: pretty) ; BEGIN IF seenMemcpy OR seenIntMin OR seenUIntMin OR seenLongMin OR seenULongMin OR seenCharMin OR - seenUCharMin OR seenUIntMin OR seenIntMax OR + seenUCharMin OR (* seenUIntMin OR *) seenIntMax OR seenUIntMax OR seenLongMax OR seenULongMax OR - seenCharMax OR seenUCharMax OR seenUIntMax + seenCharMax OR seenUCharMax (* OR seenUIntMax *) THEN checkGccConfigSystem (p); IF NOT getGccConfigSystem () @@ -1118,14 +1118,12 @@ BEGIN seenULongMin := FALSE ; seenCharMin := FALSE ; seenUCharMin := FALSE ; - seenUIntMin := FALSE ; seenIntMax := FALSE ; seenUIntMax := FALSE ; seenLongMax := FALSE ; seenULongMax := FALSE ; seenCharMax := FALSE ; seenUCharMax := FALSE ; - seenUIntMax := FALSE ; seenLabs := FALSE ; seenAbs := FALSE ; seenFabs := FALSE ; diff --git a/gcc/m2/pge-boot/GArgs.c b/gcc/m2/pge-boot/GArgs.c index 3c3f95b..69fbdd0 100644 --- a/gcc/m2/pge-boot/GArgs.c +++ b/gcc/m2/pge-boot/GArgs.c @@ -81,7 +81,7 @@ extern "C" unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int if (i < (UnixArgs_GetArgC ())) { Source = static_cast (UnixArgs_GetArgV ()); - while (((*(*Source).array[i]).array[j] != ASCII_nul) && (j < High)) + while ((j < High) && ((*(*Source).array[i]).array[j] != ASCII_nul)) { a[j] = (*(*Source).array[i]).array[j]; j += 1; diff --git a/gcc/m2/pge-boot/GM2Dependent.c b/gcc/m2/pge-boot/GM2Dependent.c index 368cf33..32c777c 100644 --- a/gcc/m2/pge-boot/GM2Dependent.c +++ b/gcc/m2/pge-boot/GM2Dependent.c @@ -458,7 +458,7 @@ static void toCString (char *str, unsigned int _str_high) high = _str_high; while (i < high) { - if ((str[i] == '\\') && (i < high)) + if ((i < high) && (str[i] == '\\')) { if (str[i+1] == 'n') { -- 2.7.4