Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): prefer positive array index in Buf_Add...



details:   https://anonhg.NetBSD.org/src/rev/0a8705ce1212
branches:  trunk
changeset: 939675:0a8705ce1212
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 27 16:38:32 2020 +0000

description:
make(1): prefer positive array index in Buf_AddByte

Ideally the condition for allocating more memory would have been
(old_len + 2 > bp->cap) since that's the actually intended wording.  But
GCC 5 neglected to generate good code for that on x86_64, so be it.

diffstat:

 usr.bin/make/buf.h |  14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diffs (29 lines):

diff -r e3287ef123e8 -r 0a8705ce1212 usr.bin/make/buf.h
--- a/usr.bin/make/buf.h        Sun Sep 27 16:21:06 2020 +0000
+++ b/usr.bin/make/buf.h        Sun Sep 27 16:38:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.h,v 1.31 2020/09/27 16:21:06 rillig Exp $  */
+/*     $NetBSD: buf.h,v 1.32 2020/09/27 16:38:32 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -97,13 +97,13 @@
 static inline MAKE_ATTR_UNUSED void
 Buf_AddByte(Buffer *bp, char byte)
 {
-    size_t new_len = ++bp->len;
-    char *end_plus_one;
-    if (__predict_false(new_len >= bp->cap))
+    size_t old_len = bp->len++;
+    char *end;
+    if (__predict_false(old_len + 1 >= bp->cap))
        Buf_Expand_1(bp);
-    end_plus_one = bp->data + new_len;
-    end_plus_one[-1] = byte;
-    end_plus_one[0] = 0;
+    end = bp->data + old_len;
+    end[0] = byte;
+    end[1] = '\0';
 }
 
 static inline MAKE_ATTR_UNUSED size_t



Home | Main Index | Thread Index | Old Index