aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2019-11-07 13:30:03 +0100
committerClifford Wolf <clifford@clifford.at>2019-11-07 13:30:03 +0100
commit65f197e28f789aa6bcfd8f4841c0e1ebb91b99a8 (patch)
tree2e188e433c4cfdf52fa41e879b7140a8260c9970
parentc4bd318e76240d3e6a95109c19641cdfd86517b8 (diff)
downloadyosys-65f197e28f789aa6bcfd8f4841c0e1ebb91b99a8.tar.gz
yosys-65f197e28f789aa6bcfd8f4841c0e1ebb91b99a8.tar.bz2
yosys-65f197e28f789aa6bcfd8f4841c0e1ebb91b99a8.zip
Add check for valid macro names in macro definitions
Signed-off-by: Clifford Wolf <clifford@clifford.at>
-rw-r--r--frontends/verilog/preproc.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index dea22ee8a..7e107dc26 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -490,13 +490,17 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
}
while (newline_count-- > 0)
return_char('\n');
- // printf("define: >>%s<< -> >>%s<<\n", name.c_str(), value.c_str());
- defines_map[name] = value;
- if (state == 2)
- defines_with_args.insert(name);
- else
- defines_with_args.erase(name);
- global_defines_cache[name] = std::pair<std::string, bool>(value, state == 2);
+ if (strchr("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ$0123456789", name[0])) {
+ // printf("define: >>%s<< -> >>%s<<\n", name.c_str(), value.c_str());
+ defines_map[name] = value;
+ if (state == 2)
+ defines_with_args.insert(name);
+ else
+ defines_with_args.erase(name);
+ global_defines_cache[name] = std::pair<std::string, bool>(value, state == 2);
+ } else {
+ log_file_error(filename, 0, "Invalid name for macro definition: >>%s<<.\n", name.c_str());
+ }
continue;
}