Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: add assertions for input handling



details:   https://anonhg.NetBSD.org/src/rev/39745438c9a3
branches:  trunk
changeset: 1026514:39745438c9a3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 27 18:26:48 2021 +0000

description:
indent: add assertions for input handling

Just to document the invariants; the code is already OK.

diffstat:

 usr.bin/indent/io.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (48 lines):

diff -r 0beab69bd9ce -r 39745438c9a3 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat Nov 27 15:23:33 2021 +0000
+++ b/usr.bin/indent/io.c       Sat Nov 27 18:26:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.139 2021/11/26 15:21:38 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.140 2021/11/27 18:26:48 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.139 2021/11/26 15:21:38 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.140 2021/11/27 18:26:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -85,6 +85,7 @@
 const char *
 inp_p(void)
 {
+    assert(inbuf.inp.s < inbuf.inp.e);
     return inbuf.inp.s;
 }
 
@@ -107,18 +108,21 @@
 char
 inp_peek(void)
 {
+    assert(inbuf.inp.s < inbuf.inp.e);
     return *inbuf.inp.s;
 }
 
 char
 inp_lookahead(size_t i)
 {
+    assert(i < (size_t)(inbuf.inp.e - inbuf.inp.s));
     return inbuf.inp.s[i];
 }
 
 void
 inp_skip(void)
 {
+    assert(inbuf.inp.s < inbuf.inp.e);
     inbuf.inp.s++;
     if (inbuf.inp.s >= inbuf.inp.e)
        inp_read_line();



Home | Main Index | Thread Index | Old Index