kconfig: Clear "written" flag to avoid data loss
[carl9170fw.git] / config / preprocess.c
index 65da87fce907ad2bc7b52adba4651dc2c32786be..0243086fb16854d9c7555b13f4ad3f3b2b96c456 100644 (file)
@@ -2,6 +2,7 @@
 //
 // Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com>
 
+#include <ctype.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "list.h"
+#include "lkc.h"
 
 #define ARRAY_SIZE(arr)                (sizeof(arr) / sizeof((arr)[0]))
 
 static char *expand_string_with_args(const char *in, int argc, char *argv[]);
+static char *expand_string(const char *in);
 
 static void __attribute__((noreturn)) pperror(const char *format, ...)
 {
@@ -156,7 +159,7 @@ static char *do_shell(int argc, char *argv[])
                nread--;
 
        /* remove trailing new lines */
-       while (buf[nread - 1] == '\n')
+       while (nread > 0 && buf[nread - 1] == '\n')
                nread--;
 
        buf[nread] = 0;
@@ -548,15 +551,14 @@ static char *expand_string_with_args(const char *in, int argc, char *argv[])
        return __expand_string(&in, is_end_of_str, argc, argv);
 }
 
-char *expand_string(const char *in)
+static char *expand_string(const char *in)
 {
        return expand_string_with_args(in, 0, NULL);
 }
 
 static bool is_end_of_token(char c)
 {
-       /* Why are '.' and '/' valid characters for symbols? */
-       return !(isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/');
+       return !(isalnum(c) || c == '_' || c == '-');
 }
 
 /*