Module Name:    src
Committed By:   rillig
Date:           Thu Nov 25 21:59:40 UTC 2021

Modified Files:
        src/usr.bin/indent: io.c

Log Message:
indent: prevent undefined behavior in inp_line_start

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.132 src/usr.bin/indent/io.c:1.133
--- src/usr.bin/indent/io.c:1.132	Thu Nov 25 20:00:31 2021
+++ src/usr.bin/indent/io.c	Thu Nov 25 21:59:40 2021
@@ -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 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #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 @@ inp_line_start(void)
     /*
      * 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 *

Reply via email to