projects
/
carl9170fw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
kconfig: Clear "written" flag to avoid data loss
[carl9170fw.git]
/
config
/
preprocess.c
diff --git
a/config/preprocess.c
b/config/preprocess.c
index 0574039238c65cf1df6bb1dba86b9fff8c989375..0243086fb16854d9c7555b13f4ad3f3b2b96c456 100644
(file)
--- a/
config/preprocess.c
+++ b/
config/preprocess.c
@@
-2,6
+2,7
@@
//
// Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com>
//
// Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com>
+#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
@@
-9,10
+10,12
@@
#include <string.h>
#include "list.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[]);
#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, ...)
{
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 */
nread--;
/* remove trailing new lines */
- while (buf[nread - 1] == '\n')
+ while (
nread > 0 &&
buf[nread - 1] == '\n')
nread--;
buf[nread] = 0;
nread--;
buf[nread] = 0;
@@
-229,6
+232,7
@@
struct variable {
char *name;
char *value;
enum variable_flavor flavor;
char *name;
char *value;
enum variable_flavor flavor;
+ int exp_count;
struct list_head node;
};
struct list_head node;
};
@@
-253,11
+257,22
@@
static char *variable_expand(const char *name, int argc, char *argv[])
if (!v)
return NULL;
if (!v)
return NULL;
+ if (argc == 0 && v->exp_count)
+ pperror("Recursive variable '%s' references itself (eventually)",
+ name);
+
+ if (v->exp_count > 1000)
+ pperror("Too deep recursive expansion");
+
+ v->exp_count++;
+
if (v->flavor == VAR_RECURSIVE)
res = expand_string_with_args(v->value, argc, argv);
else
res = xstrdup(v->value);
if (v->flavor == VAR_RECURSIVE)
res = expand_string_with_args(v->value, argc, argv);
else
res = xstrdup(v->value);
+ v->exp_count--;
+
return res;
}
return res;
}
@@
-284,6
+299,7
@@
void variable_add(const char *name, const char *value,
v = xmalloc(sizeof(*v));
v->name = xstrdup(name);
v = xmalloc(sizeof(*v));
v->name = xstrdup(name);
+ v->exp_count = 0;
list_add_tail(&v->node, &variable_list);
}
list_add_tail(&v->node, &variable_list);
}
@@
-535,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);
}
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)
{
{
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 == '-');
}
/*
}
/*