Other assorted problems in jupp

Bug #1348614 reported by dcb on 2014-07-25
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
jupp
Undecided
Unassigned

Bug Description

1.

[scrn.c:307]: (style) Redundant condition: If c == -1, the comparison c < 32 is
always true.

           if (c == -1 || c < 32 || (c >= 0x7F && c < 0xA0)) {

2.

[tty.c:399]: (error) Array 'speeds[26]' accessed at index 28, which is out of bounds.

        if (bbaud == speeds[x]) {

3.

[w.c:84]: (style) Clarify calculation precedence for '%' and '?'.

    w->hh = tmp / (w->t->h - w->t->wind) + (tmp % (w->t->h - w->t->wind) ? 1 : 0);

I got all three of these problems by running cppcheck, a static analysis checker.

Thorsten Glaser (mirabilos) wrote :

Thanks. Fixes for all three committed, although #3 is perfectly clear use of the ternary operator IMO (but terrible for “division with rounding up”, so I replaced the code).

I’m developing on MirBSD against GCC 3.4 (heavily patched), so I appreciate reports from newer/other compilers and static or even dynamic analysers. (I do occasionally try clang scan-build on my code, and build on e.g. GNU/Linux with recent GCC, but not continuously.)

I dropped the comparison in #1 entirely (probably historic) and changed the loop in #2 to use mksh’s NELEM macro, since the size of the speeds[] array is compile-time dynamic and dependent on the host OS.

Feel free to re-check CVS HEAD (or the inofficial mirror on github).

Changed in jupp:
status: New → Fix Committed
dcb (dcb314) wrote :

>I appreciate reports from newer/other compilers and static or even dynamic analysers.

My usual compiler pair are

gcc -g -O2 -Wall -Wlogical-op -Wtype-limits

and

clang -g -O2 -Wall

For static analysis, cppcheck --enable=all

For dynamic analysis, valgrind.

Any code that gets through those four filters and works fine
is usually good enough to ship.

Thorsten Glaser (mirabilos) wrote :

Fixed in jupp28

Changed in jupp:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers