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 <gaiusmod2@gmail.com>
This commit is contained in:
Gaius Mulley 2023-01-20 23:39:35 +00:00
parent 0c193cabe1
commit 5c4122be85
8 changed files with 9 additions and 13 deletions

View 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

View 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

View 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;

View 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')
{

View 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;

View 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 ;

View 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;

View 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')
{