summaryrefslogtreecommitdiff
path: root/lib/libcurses
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2006-05-14 09:01:07 +0000
committerMarc Espie <espie@cvs.openbsd.org>2006-05-14 09:01:07 +0000
commit8ae05df04c7122306d1cf9d2eacde3fab73f75fb (patch)
treec58dd71fab96bdcf828de43045045410eba1790f /lib/libcurses
parent3bdf03d71d87d023dbd99463281307a29375e3ea (diff)
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@
Diffstat (limited to 'lib/libcurses')
-rw-r--r--lib/libcurses/base/keybound.c11
-rw-r--r--lib/libcurses/base/keyok.c38
2 files changed, 30 insertions, 19 deletions
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 <curses.priv.h>
+#include <limits.h>
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 <curses.priv.h>
+#include <limits.h>
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);
}