Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libterminfo terminfo: Clamp numeric bounds to storage no...



details:   https://anonhg.NetBSD.org/src/rev/b680386d82d6
branches:  trunk
changeset: 1008639:b680386d82d6
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Mar 29 18:32:45 2020 +0000

description:
terminfo: Clamp numeric bounds to storage not API.

While here, fix decoding of numeric -1 stored in uint16_t to still be -1.

diffstat:

 lib/libterminfo/term_private.h |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (74 lines):

diff -r 5fa182f38dd4 -r b680386d82d6 lib/libterminfo/term_private.h
--- a/lib/libterminfo/term_private.h    Sun Mar 29 17:50:23 2020 +0000
+++ b/lib/libterminfo/term_private.h    Sun Mar 29 18:32:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term_private.h,v 1.15 2020/03/28 15:23:33 roy Exp $ */
+/* $NetBSD: term_private.h,v 1.16 2020/03/29 18:32:45 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2013, 2020 The NetBSD Foundation, Inc.
@@ -188,7 +188,7 @@
 static __inline int
 _ti_decode_16(const char **cap)
 {
-       int num = le16dec(*cap);
+       int num = (int16_t)le16dec(*cap);
 
        *cap += sizeof(uint16_t);
        return num;
@@ -197,7 +197,7 @@
 static __inline int
 _ti_decode_32(const char **cap)
 {
-       int num = le32dec(*cap);
+       int num = (int32_t)le32dec(*cap);
 
        *cap += sizeof(uint32_t);
        return num;
@@ -216,7 +216,7 @@
 static __inline void
 _ti_encode_16(char **cap, size_t num)
 {
-       _DIAGASSERT(num <= USHRT_MAX);
+       _DIAGASSERT(num <= UINT16_MAX);
        le16enc(*cap, (uint16_t)num);
        *cap += sizeof(uint16_t);
 }
@@ -224,7 +224,7 @@
 static __inline void
 _ti_encode_32(char **cap, size_t num)
 {
-       _DIAGASSERT(num <= UINT_MAX);
+       _DIAGASSERT(num <= UINT32_MAX);
        le32enc(*cap, (uint32_t)num);
        *cap += sizeof(uint32_t);
 }
@@ -248,7 +248,7 @@
 static __inline void
 _ti_encode_buf_16(TBUF *tbuf, size_t num)
 {
-       _DIAGASSERT(num <= USHRT_MAX);
+       _DIAGASSERT(num <= UINT16_MAX);
        le16enc(tbuf->buf + tbuf->bufpos, (uint16_t)num);
        tbuf->bufpos += sizeof(uint16_t);
 }
@@ -256,7 +256,7 @@
 static __inline void
 _ti_encode_buf_32(TBUF *tbuf, size_t num)
 {
-       _DIAGASSERT(num <= UINT_MAX);
+       _DIAGASSERT(num <= UINT32_MAX);
        le32enc(tbuf->buf + tbuf->bufpos, (uint32_t)num);
        tbuf->bufpos += sizeof(uint32_t);
 }
@@ -273,8 +273,8 @@
 _ti_encode_buf_num(TBUF *tbuf, size_t num, int rtype)
 {
        if (rtype == TERMINFO_RTYPE_O1) {
-               if (num > SHRT_MAX)
-                       num = SHRT_MAX;
+               if (num > INT16_MAX)
+                       num = INT16_MAX;
                _ti_encode_buf_16(tbuf, num);
        } else {
                _ti_encode_buf_32(tbuf, num);



Home | Main Index | Thread Index | Old Index