From 8ae05df04c7122306d1cf9d2eacde3fab73f75fb Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Sun, 14 May 2006 09:01:07 +0000 Subject: lint warns about some fishy type conversion. Indeed, some ints can be silently shortened to unsigned short. Since those functions can return errors, do not convert spurious parameters to the wrong values, but return an error code instead. Tested for ill effects without any noticeable problems. okay millert@, otto@ --- lib/libcurses/base/keybound.c | 11 +++++++++-- lib/libcurses/base/keyok.c | 38 +++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 19 deletions(-) (limited to 'lib/libcurses') diff --git a/lib/libcurses/base/keybound.c b/lib/libcurses/base/keybound.c index adee55cd0e4..91bdfb8700d 100644 --- a/lib/libcurses/base/keybound.c +++ b/lib/libcurses/base/keybound.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keybound.c,v 1.2 2001/01/22 18:01:36 millert Exp $ */ +/* $OpenBSD: keybound.c,v 1.3 2006/05/14 09:01:06 espie Exp $ */ /**************************************************************************** * Copyright (c) 1999,2000 Free Software Foundation, Inc. * @@ -33,6 +33,7 @@ ****************************************************************************/ #include +#include MODULE_ID("$From: keybound.c,v 1.3 2000/12/10 02:43:26 tom Exp $") @@ -44,5 +45,11 @@ MODULE_ID("$From: keybound.c,v 1.3 2000/12/10 02:43:26 tom Exp $") NCURSES_EXPORT(char *) keybound(int code, int count) { - return _nc_expand_try(SP->_key_ok, code, &count, 0); + unsigned short k; + + if (code < 0 || code > (int)USHRT_MAX) { + return NULL; + } else { + return _nc_expand_try(SP->_key_ok, (unsigned short)code, &count, 0); + } } diff --git a/lib/libcurses/base/keyok.c b/lib/libcurses/base/keyok.c index 5e4b5880e86..e486969237c 100644 --- a/lib/libcurses/base/keyok.c +++ b/lib/libcurses/base/keyok.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyok.c,v 1.3 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: keyok.c,v 1.4 2006/05/14 09:01:06 espie Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -33,6 +33,7 @@ ****************************************************************************/ #include +#include MODULE_ID("$From: keyok.c,v 1.5 2000/12/10 02:43:26 tom Exp $") @@ -54,22 +55,25 @@ keyok(int c, bool flag) char *s; T((T_CALLED("keyok(%d,%d)"), c, flag)); - if (flag) { - while ((s = _nc_expand_try(SP->_key_ok, c, &count, 0)) != 0 - && _nc_remove_key(&(SP->_key_ok), c)) { - _nc_add_to_try(&(SP->_keytry), s, c); - free(s); - code = OK; - count = 0; - } - } else { - while ((s = _nc_expand_try(SP->_keytry, c, &count, 0)) != 0 - && _nc_remove_key(&(SP->_keytry), c)) { - _nc_add_to_try(&(SP->_key_ok), s, c); - free(s); - code = OK; - count = 0; - } + if (c >= 0 && c <= (int)USHRT_MAX) { + unsigned short k = (unsigned short) c; + if (flag) { + while ((s = _nc_expand_try(SP->_key_ok, k, &count, 0)) != 0 + && _nc_remove_key(&(SP->_key_ok), k)) { + _nc_add_to_try(&(SP->_keytry), s, k); + free(s); + code = OK; + count = 0; + } + } else { + while ((s = _nc_expand_try(SP->_keytry, k, &count, 0)) != 0 + && _nc_remove_key(&(SP->_keytry), k)) { + _nc_add_to_try(&(SP->_key_ok), s, k); + free(s); + code = OK; + count = 0; + } + } } returnCode(code); } -- cgit v1.2.3