Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: expand macro in string concatenation



details:   https://anonhg.NetBSD.org/src/rev/24febc9d9ca0
branches:  trunk
changeset: 1023093:24febc9d9ca0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 23 17:03:23 2021 +0000

description:
lint: expand macro in string concatenation

No functional change.

diffstat:

 usr.bin/xlint/lint1/lint1.h |   4 +-
 usr.bin/xlint/lint1/tree.c  |  57 +++++++++++++++++++++-----------------------
 2 files changed, 29 insertions(+), 32 deletions(-)

diffs (102 lines):

diff -r 85ac2524414e -r 24febc9d9ca0 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Mon Aug 23 13:08:18 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Mon Aug 23 17:03:23 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.124 2021/08/23 06:26:37 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.125 2021/08/23 17:03:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -79,7 +79,7 @@
        } while (false)
 
 /*
- * Strings cannot be referenced to simply by a pointer to its first
+ * Strings cannot be referenced simply by a pointer to their first
  * char. This is because strings can contain NUL characters other than the
  * trailing NUL.
  *
diff -r 85ac2524414e -r 24febc9d9ca0 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Aug 23 13:08:18 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Aug 23 17:03:23 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.350 2021/08/23 06:50:01 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.351 2021/08/23 17:03:23 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.350 2021/08/23 06:50:01 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.351 2021/08/23 17:03:23 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4238,40 +4238,37 @@
        }
 }
 
-/*
- * Concatenate two string constants.
- */
+/* Append s2 to s1, then free s2. */
 strg_t *
-cat_strings(strg_t *strg1, strg_t *strg2)
+cat_strings(strg_t *s1, strg_t *s2)
 {
-       size_t  len1, len2, len;
-
-       if (strg1->st_tspec != strg2->st_tspec) {
+       size_t len1, len2, sz;
+
+       if (s1->st_tspec != s2->st_tspec) {
                /* cannot concatenate wide and regular string literals */
                error(292);
-               return strg1;
+               return s1;
        }
 
-       len1 = strg1->st_len;
-       len2 = strg2->st_len + 1;       /* + NUL */
-       len = len1 + len2;
-
-#define COPY(F) \
-    do { \
-       strg1->F = xrealloc(strg1->F, len * sizeof(*strg1->F)); \
-       (void)memcpy(strg1->F + len1, strg2->F, len2 * sizeof(*strg1->F)); \
-       free(strg2->F); \
-    } while (false)
-
-       if (strg1->st_tspec == CHAR)
-               COPY(st_cp);
-       else
-               COPY(st_wcp);
-
-       strg1->st_len = len - 1; /* - NUL */
-       free(strg2);
-
-       return strg1;
+       len1 = s1->st_len;
+       len2 = s2->st_len;
+
+       if (s1->st_tspec == CHAR) {
+               sz = sizeof(*s1->st_cp);
+               s1->st_cp = xrealloc(s1->st_cp, (len1 + len2 + 1) * sz);
+               memcpy(s1->st_cp + len1, s2->st_cp, (len2 + 1) * sz);
+               free(s2->st_cp);
+       } else {
+               sz = sizeof(*s1->st_wcp);
+               s1->st_wcp = xrealloc(s1->st_wcp, (len1 + len2 + 1) * sz);
+               memcpy(s1->st_wcp + len1, s2->st_wcp, (len2 + 1) * sz);
+               free(s2->st_wcp);
+       }
+
+       s1->st_len = len1 + len2;
+       free(s2);
+
+       return s1;
 }
 
 static bool



Home | Main Index | Thread Index | Old Index