diff options
| author | roy <roy@NetBSD.org> | 2020-06-21 15:05:23 +0000 |
|---|---|---|
| committer | roy <roy@NetBSD.org> | 2020-06-21 15:05:23 +0000 |
| commit | bc28c2d4ca6b42a110ff86d2016fb5455d994d84 (patch) | |
| tree | 7d13bdb34c8ad32f684f4788dafef4f79f85d4ce /lib/libterminfo | |
| parent | 410ad0cd41cc203df71ccd8e352a7b20b3f4941c (diff) | |
libterminfo: cast to uint16/32_t before conversion to preserve negativity
Otherwise the ABSENT_NUMERIC(-1) or CANCELLED_NUMERIC(-2) will be converted
incorrectly to size_t and then down to uint16/32_t.
Picked up by DIAGNOSTIC builds.
Thanks to Michael Forney for the fix for PR lib/52293.
Diffstat (limited to 'lib/libterminfo')
| -rw-r--r-- | lib/libterminfo/compile.c | 8 | ||||
| -rw-r--r-- | lib/libterminfo/term_private.h | 10 |
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/libterminfo/compile.c b/lib/libterminfo/compile.c index b991eb01b30..48ab0354dd1 100644 --- a/lib/libterminfo/compile.c +++ b/lib/libterminfo/compile.c @@ -1,4 +1,4 @@ -/* $NetBSD: compile.c,v 1.25 2020/04/05 12:31:02 roy Exp $ */ +/* $NetBSD: compile.c,v 1.26 2020/06/21 15:05:23 roy Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2020 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: compile.c,v 1.25 2020/04/05 12:31:02 roy Exp $"); +__RCSID("$NetBSD: compile.c,v 1.26 2020/06/21 15:05:23 roy Exp $"); #if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H #include <sys/endian.h> @@ -560,9 +560,9 @@ _ti_encode_buf_id_num(TBUF *tbuf, int ind, int num, size_t len) return 0; _ti_encode_buf_16(tbuf, ind); if (len == sizeof(uint32_t)) - _ti_encode_buf_32(tbuf, num); + _ti_encode_buf_32(tbuf, (uint32_t)num); else - _ti_encode_buf_16(tbuf, num); + _ti_encode_buf_16(tbuf, (uint16_t)num); tbuf->entries++; return 1; } diff --git a/lib/libterminfo/term_private.h b/lib/libterminfo/term_private.h index dbe81becaa8..887577cf8ca 100644 --- a/lib/libterminfo/term_private.h +++ b/lib/libterminfo/term_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: term_private.h,v 1.18 2020/03/29 21:46:22 roy Exp $ */ +/* $NetBSD: term_private.h,v 1.19 2020/06/21 15:05:23 roy Exp $ */ /* * Copyright (c) 2009, 2010, 2013, 2020 The NetBSD Foundation, Inc. @@ -276,14 +276,16 @@ _ti_encode_buf_count_str(TBUF *tbuf, const void *buf, size_t len) } static __inline void -_ti_encode_buf_num(TBUF *tbuf, size_t num, int rtype) +_ti_encode_buf_num(TBUF *tbuf, int num, int rtype) { if (rtype == TERMINFO_RTYPE_O1) { if (num > INT16_MAX) num = INT16_MAX; - _ti_encode_buf_16(tbuf, num); + _ti_encode_buf_16(tbuf, (uint16_t)num); } else { - _ti_encode_buf_32(tbuf, num); + if (num > INT32_MAX) + num = INT32_MAX; + _ti_encode_buf_32(tbuf, (uint32_t)num); } } |
