Skip to content

Commit

Permalink
DBC parser: assert no duplicate signal names in msg (commaai#821)
Browse files Browse the repository at this point in the history
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
  • Loading branch information
pd0wm and adeebshihadeh authored Apr 17, 2023
1 parent b7546cd commit 9eec533
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch
uint32_t address = 0;
std::set<uint32_t> address_set;
std::set<std::string> msg_name_set;
std::map<uint32_t, std::set<std::string>> signal_name_sets;
std::map<uint32_t, std::vector<Signal>> signals;
DBC* dbc = new DBC;
dbc->name = dbc_name;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9eec533

Please sign in to comment.