From a00445c8e04db6c96dabccf23c04ab2e4571ca2b Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Thu, 2 Dec 2021 11:29:19 +0900 Subject: [PATCH] Parse isa_string as C-style string On C++11 and later, std::string is guaranteed to be null-terminated. However, `*(str.end())` is NOT guaranteed to be '\0'. So, we parse ISA string using C-style string buffer (raw pointers). --- riscv/processor.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/riscv/processor.cc b/riscv/processor.cc index ed9042f1..a7b4a5be 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -221,7 +221,8 @@ void processor_t::parse_isa_string(const char* str) if (isa_string[4] != 'i') bad_isa_string(str, "'I' extension is required"); - auto p = isa_string.begin(); + const char* isa_str = isa_string.c_str(); + auto p = isa_str; for (p += 4; islower(*p) && !strchr("zsx", *p); ++p) { while (*all_subsets && (*p != *all_subsets)) ++all_subsets; @@ -333,7 +334,7 @@ void processor_t::parse_isa_string(const char* str) p = end; } if (*p) { - bad_isa_string(str, ("can't parse: " + std::string(p, isa_string.end())).c_str()); + bad_isa_string(str, ("can't parse: " + std::string(p)).c_str()); } }