From 9eec5335a0f931bfe62a536c763c26e0a41a6a0b Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 17 Apr 2023 18:59:20 +0200 Subject: [PATCH] DBC parser: assert no duplicate signal names in msg (#821) Co-authored-by: Adeeb Shihadeh --- can/dbc.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/can/dbc.cc b/can/dbc.cc index 272e5d642c..22317169b2 100644 --- a/can/dbc.cc +++ b/can/dbc.cc @@ -102,6 +102,7 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch uint32_t address = 0; std::set address_set; std::set msg_name_set; + std::map> signal_name_sets; std::map> signals; DBC* dbc = new DBC; dbc->name = dbc_name; @@ -165,6 +166,10 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch sig.msb = sig.start_bit; } DBC_ASSERT(sig.lsb < (64 * 8) && sig.msb < (64 * 8), "Signal out of bounds: " << line); + + // Check for duplicate signal names + DBC_ASSERT(signal_name_sets[address].find(sig.name) == signal_name_sets[address].end(), "Duplicate signal name: " << sig.name); + signal_name_sets[address].insert(sig.name); } else if (startswith(line, "VAL_ ")) { // new signal value/definition bool ret = std::regex_search(line, match, val_regexp);