PR-108136 modula-2 meets cppcheck part 2
authorGaius Mulley <gaiusmod2@gmail.com>
Fri, 20 Jan 2023 23:39:35 +0000 (23:39 +0000)
committerGaius Mulley <gaiusmod2@gmail.com>
Fri, 20 Jan 2023 23:39:35 +0000 (23:39 +0000)
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 <gaiusmod2@gmail.com>
gcc/m2/gm2-libs/Args.mod
gcc/m2/gm2-libs/M2Dependent.mod
gcc/m2/mc-boot/GArgs.c
gcc/m2/mc-boot/GM2Dependent.c
gcc/m2/mc-boot/Gkeyc.c
gcc/m2/mc/keyc.mod
gcc/m2/pge-boot/GArgs.c
gcc/m2/pge-boot/GM2Dependent.c

index 30f76c6..fa14f8c 100644 (file)
@@ -62,7 +62,7 @@ BEGIN
    IF i < GetArgC ()
    THEN
       Source := GetArgV () ;
-      WHILE (Source^[i]^[j]#nul) AND (j<High) DO
+      WHILE (j<High) AND (Source^[i]^[j]#nul) DO
          a[j] := Source^[i]^[j] ;
          INC(j)
       END
index 72675eb..f343ac3 100644 (file)
@@ -203,7 +203,7 @@ BEGIN
    i := 0 ;
    high := HIGH (str) ;
    WHILE i < high DO
-      IF (str[i] = "\") AND (i < high)
+      IF (i < high) AND (str[i] = "\")
       THEN
          IF str[i+1] = "n"
          THEN
index 81955e8..bcb1b13 100644 (file)
@@ -83,7 +83,7 @@ extern "C" unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int
   if (i < (UnixArgs_GetArgC ()))
     {
       Source = static_cast<Args__T1> (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;
index b9c59cc..fb22f1b 100644 (file)
@@ -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')
             {
index 6f17ca5..e000bfe 100644 (file)
@@ -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;
index 5e1016d..a57103b 100644 (file)
@@ -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 ;
index 3c3f95b..69fbdd0 100644 (file)
@@ -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<Args__T1> (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;
index 368cf33..32c777c 100644 (file)
@@ -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')
             {