Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/memswitch Rewrite modify_single() to make compilabl...



details:   https://anonhg.NetBSD.org/src/rev/0e20e3ab00ce
branches:  trunk
changeset: 448748:0e20e3ab00ce
user:      isaki <isaki%NetBSD.org@localhost>
date:      Fri Feb 08 08:55:35 2019 +0000

description:
Rewrite modify_single() to make compilable on gcc7.

diffstat:

 usr.sbin/memswitch/Makefile    |   9 +-------
 usr.sbin/memswitch/memswitch.c |  48 +++++++++++++++++++----------------------
 2 files changed, 23 insertions(+), 34 deletions(-)

diffs (102 lines):

diff -r c56ecf0084f3 -r 0e20e3ab00ce usr.sbin/memswitch/Makefile
--- a/usr.sbin/memswitch/Makefile       Fri Feb 08 08:51:42 2019 +0000
+++ b/usr.sbin/memswitch/Makefile       Fri Feb 08 08:55:35 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/02/07 06:01:04 mrg Exp $
+#      $NetBSD: Makefile,v 1.3 2019/02/08 08:55:35 isaki Exp $
 
 .if ${MACHINE} == "x68k"
 PROG=  memswitch
@@ -8,11 +8,4 @@
 MAN=   memswitch.8
 MANSUBDIR=     /x68k
 
-.include <bsd.own.mk>
-
-# XXX Not sure how to fix this problem
-.if defined(HAVE_GCC) && ${HAVE_GCC} == 7 && ${ACTIVE_CC} == "gcc"
-COPTS.memswitch.c+=    -Wno-error=stringop-overflow
-.endif
-
 .include <bsd.prog.mk>
diff -r c56ecf0084f3 -r 0e20e3ab00ce usr.sbin/memswitch/memswitch.c
--- a/usr.sbin/memswitch/memswitch.c    Fri Feb 08 08:51:42 2019 +0000
+++ b/usr.sbin/memswitch/memswitch.c    Fri Feb 08 08:55:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: memswitch.c,v 1.16 2019/02/08 08:41:11 isaki Exp $     */
+/*     $NetBSD: memswitch.c,v 1.17 2019/02/08 08:55:35 isaki Exp $     */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -196,42 +196,38 @@
 void
 modify_single(const char *expr)
 {
-       int i, l, n;
-       char *class = NULL, *node = NULL;
+       int i;
+       char *buf;
+       char *p;
+       const char *class;
+       const char *node;
        const char *value;
        char valuestr[MAXVALUELEN];
 
-       l = 0;
-       n = strlen(expr);
-       for (i = 0; i < n; i++) {
-               if (expr[i] == '.') {
-                       l = i + 1;
-                       class = alloca(l);
-                       if (class == 0)
-                               err(1, "alloca");
-                       strncpy(class, expr, i);
-                       class[i] = 0;
+       buf = strdup(expr);
+       if (buf == NULL)
+               err(EXIT_FAILURE, "strdup failed");
+
+       p = buf;
+       for (class = p; *p; p++) {
+               if (*p == '.') {
+                       *p++ = '\0';
                        break;
                }
        }
-       if (i >= n)
-               errx(1, "Invalid expression: %s", expr);
 
-       for ( ; i < n; i++) {
-               if (expr[i] == '=') {
-                       node = alloca(i - l + 1);
-                       if (node == 0)
-                               err(1, "alloca");
-                       strncpy(node, &(expr[l]), i - l);
-                       node[i - l] = 0;
+       for (node = p; *p; p++) {
+               if (*p == '=') {
+                       *p++ = '\0';
                        break;
                }
        }
-       if (i >= n)
+
+       value = p;
+
+       if (class[0] == '\0' || node[0] == '\0' || value[0] == '\0')
                errx(1, "Invalid expression: %s", expr);
 
-       value = &(expr[++i]);
-
        for (i = 0; i < number_of_props; i++) {
                if (strcmp(properties[i].class, class) == 0 &&
                    strcmp(properties[i].node, node) == 0) {
@@ -248,7 +244,7 @@
                errx(1, "No such property: %s.%s", class, node);
        }
 
-       return;
+       free(buf);
 }
 
 void



Home | Main Index | Thread Index | Old Index