From 986fe9a65bc0bd7f0400bd8e122d826b54e55e53 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 23 Apr 2023 19:35:16 -0500 Subject: [PATCH] Address issues in samples detected by new lint checks. The only actual behavior change is in Ackermann.cc, which previously reported incorrectly high recursion depths for some calculations. --- C.Samples/Desktop.Samples/Reversi.cc | 7 +++---- C.Samples/Graphic.Samples/Spiral.cc | 1 - C.Samples/Text.Samples/Ackermann.cc | 5 ++++- C.Samples/Text.Samples/ErrorTrap.cc | 4 +++- C.Samples/Text.Samples/Trace.cc | 4 +++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/C.Samples/Desktop.Samples/Reversi.cc b/C.Samples/Desktop.Samples/Reversi.cc index bd6b334..249a9ae 100644 --- a/C.Samples/Desktop.Samples/Reversi.cc +++ b/C.Samples/Desktop.Samples/Reversi.cc @@ -1047,8 +1047,7 @@ printf ("%c%d ", (char) (move % 10 - 1 + 'A'), 9 - move / 10); ****************************************************************/ void DrawMoves (void) { -GrafPortPtr port, p2; /* graphics ports */ -CtlRecHndl ctl; /* for finding scroll bar */ +GrafPortPtr port; /* graphics port */ Rect r; /* rectangle for drawing colors */ int i, n; /* index variables */ @@ -1437,7 +1436,7 @@ if ((part > 4) && (part < 9)) { /* if the part is not the slide switch... */ if ( ((Even(topMove) + movesInWindow + 1) / 2) > (Even(movesMade) + 1) / 2 ) { topMove = Even (movesMade) - movesInWindow; - if (! (topMove >> 16) & 0x0001) + if (! (topMove >> 15) & 0x0001) topMove++; } } @@ -1451,7 +1450,7 @@ if ((part > 4) && (part < 9)) { /* if the part is not the slide switch... */ else if (part == 129) { /* reposition based on new thumb loc. */ topMove = GetCtlValue (vScrollHandle) * 2 / charHeight +1; - if (! (topMove >> 16) & 0x0001) + if (! (topMove >> 15) & 0x0001) topMove++; updateMoves = true; DrawMoves (); diff --git a/C.Samples/Graphic.Samples/Spiral.cc b/C.Samples/Graphic.Samples/Spiral.cc index 02dbab7..8e4f93e 100644 --- a/C.Samples/Graphic.Samples/Spiral.cc +++ b/C.Samples/Graphic.Samples/Spiral.cc @@ -23,7 +23,6 @@ int main (void) { float r, theta, rot; int color = 1; -int stopFlag; Rect rect; GetPortRect(&rect); diff --git a/C.Samples/Text.Samples/Ackermann.cc b/C.Samples/Text.Samples/Ackermann.cc index fbd31c9..e4971a0 100644 --- a/C.Samples/Text.Samples/Ackermann.cc +++ b/C.Samples/Text.Samples/Ackermann.cc @@ -38,6 +38,8 @@ int a, m, n, depth, maxdepth; int Ackermann (int m, int n) { +int result; + depth++; if (depth > maxdepth) maxdepth = depth; @@ -45,8 +47,9 @@ if (m == 0) return (n + 1); if (n == 0) return (Ackermann (m-1, 1)); -return (Ackermann (m-1, Ackermann (m, n-1))); +result = Ackermann (m-1, Ackermann (m, n-1)); depth--; +return result; } diff --git a/C.Samples/Text.Samples/ErrorTrap.cc b/C.Samples/Text.Samples/ErrorTrap.cc index 8cf4185..0dac3e1 100644 --- a/C.Samples/Text.Samples/ErrorTrap.cc +++ b/C.Samples/Text.Samples/ErrorTrap.cc @@ -54,7 +54,9 @@ static void BadFunction (void) { char ch [8000]; /* this array is too large for */ -} /* the default run-time stack */ + /* the default run-time stack */ +(void)ch; /* dummy use of ch to avoid lint msg */ +} /**************************************************************** diff --git a/C.Samples/Text.Samples/Trace.cc b/C.Samples/Text.Samples/Trace.cc index cd04fb4..93e0453 100644 --- a/C.Samples/Text.Samples/Trace.cc +++ b/C.Samples/Text.Samples/Trace.cc @@ -32,7 +32,9 @@ static void Fail (void) { char ch [8000]; /* this array is too large for */ -} /* the default run-time stack */ + /* the default run-time stack */ +(void)ch; /* dummy use of ch to avoid lint msg */ +} /****************************************************************