vcurses: add return value assertions using a semantic patch

The only relevant change in this patch is the curses.cocci file. All other
changes are just the result of applying that patch, with additional manual
polishing where coccinelle caused unwanted cstyle changes.

We explicitly ignore the return value of some curses functions through the IC()
macro:

* curs_set is known to be ok to fail for terminals which do have no capability
  to make the cursor invisible and

* all print-related functions, which have the unpleasent bug to return ERR when
  the cursor ends up outside the screen/window _after_ completing the print
  function.

For most other curses functions, we add AC() to check that they do not return
ERR.
parent af18af5b
......@@ -150,13 +150,13 @@ update(void)
(void)mvaddch(LINES - 2, k, '-');
for (i = 0, j = hist_low; i < hist_range; ++i, ++j) {
(void)mvaddch(LINES - 2, w * i, '+');
mvprintw(LINES - 1, w * i, "|1e%d", j);
IC(mvprintw(LINES - 1, w * i, "|1e%d", j));
}
if (end_of_file)
mvprintw(0, 0, "%*s", COLS - 1, "EOF");
IC(mvprintw(0, 0, "%*s", COLS - 1, "EOF"));
else
mvprintw(0, 0, "%*s", COLS - 1, ident);
IC(mvprintw(0, 0, "%*s", COLS - 1, ident));
/* count our flock */
memset(bm, 0, sizeof bm);
......@@ -178,14 +178,15 @@ update(void)
if (vsl_t0 > 0) {
VTIM_format(vsl_ts, t);
mvprintw(0, 0, "1:%u, n = %u, d = %g @ %s x %g",
scale, nhist, 1e-3 * ms_delay, t, timebend);
} else
mvprintw(0, 0, "1:%u, n = %u, d = %g",
scale, nhist, 1e-3 * ms_delay);
IC(mvprintw(0, 0, "1:%u, n = %u, d = %g @ %s x %g",
scale, nhist, 1e-3 * ms_delay, t, timebend));
} else {
IC(mvprintw(0, 0, "1:%u, n = %u, d = %g",
scale, nhist, 1e-3 * ms_delay));
}
for (j = 5; j < LINES - 2; j += 5)
mvprintw((LINES - 2) - j, 0, "%u_", j * scale);
IC(mvprintw((LINES - 2) - j, 0, "%u_", j * scale));
/* show them */
for (k = 0; k < n; ++k) {
......@@ -396,7 +397,7 @@ do_curses(void *arg)
#endif
case '\014': /* Ctrl-L */
case '\024': /* Ctrl-T */
redrawwin(stdscr);
AC(redrawwin(stdscr));
AC(refresh());
break;
case '\032': /* Ctrl-Z */
......
This diff is collapsed.
......@@ -257,7 +257,7 @@ do_curses(void *arg)
AC(noecho());
AC(nonl());
AC(intrflush(stdscr, FALSE));
(void)curs_set(0);
IC(curs_set(0));
AC(erase());
timeout(1000);
while (!VSIG_int && !VSIG_term && !VSIG_hup) {
......
// XXX can we reuse the pattern somehow without inheriting the metavariable?
@@
identifier curs =~ "^(curs_set|(w|mv|mvw|vw_)?printw)$";
expression list EL;
@@
-curs(EL);
+IC(curs(EL));
@@
identifier curs =~ "^(curs_set|(w|mv|mvw|vw_)?printw)$";
expression list EL;
@@
-(void)curs(EL);
+IC(curs(EL));
// ensure we undo AC() patching when we move patterns to IC()
@@
identifier curs =~ "^(curs_set|(w|mv|mvw|vw_)?printw)$";
expression list EL;
@@
-AC(curs(EL));
+IC(curs(EL));
@@
identifier curs =~ "^(endwin|(no)?cbreak|(no)?echo|intrflush|keypad|meta|nodelay|notimeout|(no)?nl|(no)?raw|w?erase|w?clear|w?clrtobot|w?clrtoeol|(w|wnout)?refresh|doupdate|redrawwin|wredrawln|beep|flash|delwin|mv(der)?win|syncok)$";
expression list EL;
@@
-curs(EL);
+AC(curs(EL));
@@
identifier curs =~ "^(endwin|(no)?cbreak|(no)?echo|intrflush|keypad|meta|nodelay|notimeout|(no)?nl|(no)?raw|w?erase|w?clear|w?clrtobot|w?clrtoeol|(w|wnout)?refresh|doupdate|redrawwin|wredrawln|beep|flash|delwin|mv(der)?win|syncok)$";
expression list EL;
@@
-(void)curs(EL);
+AC(curs(EL));
@@
identifier curs =~ "^(endwin|(no)?cbreak|(no)?echo|intrflush|keypad|meta|nodelay|notimeout|(no)?nl|(no)?raw|w?erase|w?clear|w?clrtobot|w?clrtoeol|(w|wnout)?refresh|doupdate|redrawwin|wredrawln|beep|flash|delwin|mv(der)?win|syncok)$";
expression list EL;
@@
-assert(curs(EL) != ERR);
+AC(curs(EL));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment