Wed Jul 22 15:58:09 2009 UTC ()
Don't depend on side effects inside an assert
From Michael Cook mcook at bbn dot com


(christos)
diff -r1.30 -r1.31 src/lib/libedit/tty.c

cvs diff -r1.30 -r1.31 src/lib/libedit/tty.c (expand / switch to unified diff)

--- src/lib/libedit/tty.c 2009/02/16 00:15:45 1.30
+++ src/lib/libedit/tty.c 2009/07/22 15:58:09 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tty.c,v 1.30 2009/02/16 00:15:45 christos Exp $ */ 1/* $NetBSD: tty.c,v 1.31 2009/07/22 15:58:09 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: tty.c,v 1.30 2009/02/16 00:15:45 christos Exp $"); 40__RCSID("$NetBSD: tty.c,v 1.31 2009/07/22 15:58:09 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * tty.c: tty interface stuff 45 * tty.c: tty interface stuff
46 */ 46 */
47#include <assert.h> 47#include <assert.h>
48#include <errno.h> 48#include <errno.h>
49#include "tty.h" 49#include "tty.h"
50#include "el.h" 50#include "el.h"
51 51
52typedef struct ttymodes_t { 52typedef struct ttymodes_t {
53 const char *m_name; 53 const char *m_name;
@@ -1275,27 +1275,28 @@ tty_stty(EditLine *el, int argc __attrib @@ -1275,27 +1275,28 @@ tty_stty(EditLine *el, int argc __attrib
1275 strcmp(m->m_name, d)) == 0 && 1275 strcmp(m->m_name, d)) == 0 &&
1276 (p == NULL || m->m_type == MD_CHAR)) 1276 (p == NULL || m->m_type == MD_CHAR))
1277 break; 1277 break;
1278 1278
1279 if (!m->m_name) { 1279 if (!m->m_name) {
1280 (void) fprintf(el->el_errfile, 1280 (void) fprintf(el->el_errfile,
1281 "%s: Invalid argument `%s'.\n", name, d); 1281 "%s: Invalid argument `%s'.\n", name, d);
1282 return (-1); 1282 return (-1);
1283 } 1283 }
1284 if (p) { 1284 if (p) {
1285 int c = ffs((int)m->m_value); 1285 int c = ffs((int)m->m_value);
1286 int v = *++p ? parse__escape((const char **) &p) : 1286 int v = *++p ? parse__escape((const char **) &p) :
1287 el->el_tty.t_vdisable; 1287 el->el_tty.t_vdisable;
1288 assert(c-- != 0); 1288 assert(c != 0);
 1289 c--;
1289 c = tty__getcharindex(c); 1290 c = tty__getcharindex(c);
1290 assert(c != -1); 1291 assert(c != -1);
1291 tios->c_cc[c] = v; 1292 tios->c_cc[c] = v;
1292 continue; 1293 continue;
1293 } 1294 }
1294 switch (x) { 1295 switch (x) {
1295 case '+': 1296 case '+':
1296 el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value; 1297 el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;
1297 el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value; 1298 el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
1298 break; 1299 break;
1299 case '-': 1300 case '-':
1300 el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value; 1301 el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
1301 el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value; 1302 el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value;