tlf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to figure out a cppcheck warning


From: Nate Bargmann
Subject: Trying to figure out a cppcheck warning
Date: Sat, 23 Jan 2021 20:43:59 -0600

I've been working through the code base with the cppcheck GUI
program--remarkably few issues, actually--and have hit one in qtc_log.c
that has me a bit stumped.  For reference start at line 198, the
definition of the store_qtc() function:

https://github.com/Tlf/tlf/blob/c677a3b72ba5536753b053f84634e99fa37a351a/src/qtc_log.c#L198

The cppcheck warning is:

Line 225: Either the condition 'tempi==20000' is redundant or the array 
'qsoflags_for_qtc[20000]' is accessed at index 20000, which is out of bounds.

and a pair of notes:

Line 230: Assuming that condition 'tempi==20000' is not redundant
Line 225: Array index out of bounds

Here is the relevant part of the function:

214     if (direction == SEND) {
215         /* find maximum sent QTC block serial */
216         g_strlcpy(temps, loglineptr + 50, 5);  // get serial of qtc block
217         tempi = atoi(temps);
218         if (tempi > nr_qtcsent) {
219             nr_qtcsent = tempi;
220         }
221 
222         /* mark corresponding qso line as used for QTC */
223         g_strlcpy(temps, loglineptr + 12, 5);  // qso nr in qso list
224         tempi = atoi(temps) - 1;
225         qsoflags_for_qtc[tempi] = 1;
226 
227         /* find first unused QSO number for QTCs */
228         if (tempi == next_qtc_qso && tempi < MAX_QSOS) {
229             while (qsoflags_for_qtc[tempi++] == 1) {
230                 if (tempi == MAX_QSOS)
231                     break;
232                 next_qtc_qso = tempi;
233             }
234         }
235     }

Now, it's quite possible that cppcheck is getting tripped up in some
manner.  That said, I do think the array index and assignment on line
225 should be protected to assure the array index does not exceed
MAX_QSOS, i.e. tempi be tested after its assignment by atoi().

It appears that Ervin and Tom have touched that file the most so I'm
reluctant to mess with it (I don't understand the QTC you WAE guys do!).

I'll do a pull request for the other warnings to let everyone take a
look.

73, Nate

-- 

"The optimist proclaims that we live in the best of all
possible worlds.  The pessimist fears this is true."

Web: https://www.n0nb.us
Projects: https://github.com/N0NB
GPG fingerprint: 82D6 4F6B 0E67 CD41 F689 BBA6 FB2C 5130 D55A 8819

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]