Module Name: src Committed By: roy Date: Sun Jun 21 15:05:23 UTC 2020
Modified Files: src/lib/libterminfo: compile.c term_private.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/lib/libterminfo/compile.c cvs rdiff -u -r1.18 -r1.19 src/lib/libterminfo/term_private.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libterminfo/compile.c diff -u src/lib/libterminfo/compile.c:1.25 src/lib/libterminfo/compile.c:1.26 --- src/lib/libterminfo/compile.c:1.25 Sun Apr 5 12:31:02 2020 +++ src/lib/libterminfo/compile.c Sun Jun 21 15:05:23 2020 @@ -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 in 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; } Index: src/lib/libterminfo/term_private.h diff -u src/lib/libterminfo/term_private.h:1.18 src/lib/libterminfo/term_private.h:1.19 --- src/lib/libterminfo/term_private.h:1.18 Sun Mar 29 21:46:22 2020 +++ src/lib/libterminfo/term_private.h Sun Jun 21 15:05:23 2020 @@ -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, con } 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); } }