diff options
author | Maya <96890070+VioletEternity@users.noreply.github.com> | 2022-03-11 23:31:23 +0000 |
---|---|---|
committer | Maya <96890070+VioletEternity@users.noreply.github.com> | 2022-03-11 23:31:23 +0000 |
commit | 2a3d0c1d29f99c96004564a74c0dc04f7713d870 (patch) | |
tree | 3aa1b0ecf0d3c7f0ea07ab570c246ec9a83d3110 /ecp5 | |
parent | 20e595e2113bb5d2de479e70f64ebd980e756716 (diff) | |
download | nextpnr-2a3d0c1d29f99c96004564a74c0dc04f7713d870.tar.gz nextpnr-2a3d0c1d29f99c96004564a74c0dc04f7713d870.tar.bz2 nextpnr-2a3d0c1d29f99c96004564a74c0dc04f7713d870.zip |
ecp5: verify hex strings contain only valid characters.
Diffstat (limited to 'ecp5')
-rw-r--r-- | ecp5/bitstream.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ecp5/bitstream.cc b/ecp5/bitstream.cc index a23e4cd2..b1c60ccb 100644 --- a/ecp5/bitstream.cc +++ b/ecp5/bitstream.cc @@ -149,6 +149,8 @@ std::vector<bool> parse_init_str(const Property &p, int length, const char *cell for (int i = 0; i < int(str.length()) - 2; i++) { char c = str.at((str.size() - i) - 1); int nibble = chtohex(c); + if (nibble == (int)std::string::npos) + log_error("hex string has invalid char '%c' at position %d.\n", c, i); result.at(i * 4) = nibble & 0x1; if (i * 4 + 1 < length) result.at(i * 4 + 1) = nibble & 0x2; @@ -582,13 +584,16 @@ static std::vector<bool> parse_config_str(const Property &p, int length) if (base == "0b") { for (int i = 0; i < int(str.length()) - 2; i++) { char c = str.at((str.size() - 1) - i); - NPNR_ASSERT(c == '0' || c == '1'); + if (!(c == '0' || c == '1')) + log_error("binary string has invalid char '%c' at position %d.\n", c, i); word.at(i) = (c == '1'); } } else if (base == "0x") { for (int i = 0; i < int(str.length()) - 2; i++) { char c = str.at((str.size() - i) - 1); int nibble = chtohex(c); + if (nibble == (int)std::string::npos) + log_error("hex string has invalid char '%c' at position %d.\n", c, i); word.at(i * 4) = nibble & 0x1; if (i * 4 + 1 < length) word.at(i * 4 + 1) = nibble & 0x2; |