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: prevent undefined behavior in inp_lin...



details:   https://anonhg.NetBSD.org/src/rev/6571954efb77
branches:  trunk
changeset: 1026477:6571954efb77
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 25 21:59:40 2021 +0000

description:
indent: prevent undefined behavior in inp_line_start

No functional change.

diffstat:

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

diffs (33 lines):

diff -r de18f135f7c7 -r 6571954efb77 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Nov 25 21:48:23 2021 +0000
+++ b/usr.bin/indent/io.c       Thu Nov 25 21:59:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.132 2021/11/25 20:00:31 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.133 2021/11/25 21:59:40 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.132 2021/11/25 20:00:31 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.133 2021/11/25 21:59:40 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -94,13 +94,8 @@
     /*
      * The comment we're about to read usually comes from inp.buf, unless
      * it has been copied into save_com.
-     *
-     * XXX: ordered comparison between pointers from different objects
-     * invokes undefined behavior (C99 6.5.8).
      */
-    return inbuf.inp.s >= inbuf.save_com_buf &&
-       inbuf.inp.s < inbuf.save_com_buf + array_length(inbuf.save_com_buf)
-       ? inbuf.save_com_buf : inbuf.inp.buf;
+    return inbuf.saved_inp_s != NULL ? inbuf.save_com_buf : inbuf.inp.buf;
 }
 
 const char *



Home | Main Index | Thread Index | Old Index