From 05d569ee442196f7d42d65c25ae68eef08322547 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 26 Jan 2017 17:47:24 -0800 Subject: [PATCH] Simplify error case of token_type_description and keyword_description Simply return a constant string, since in practice the error case is not hit --- src/parse_tree.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index f3bbdbf43..32da0cf10 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -123,23 +123,14 @@ void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) { const wchar_t *token_type_description(parse_token_type_t type) { const wchar_t *description = enum_to_str(type, token_enum_map); if (description) return description; + return L"unknown_token_type"; - // This leaks memory but it should never be run unless we have a bug elsewhere in the code. - const wcstring d = format_string(L"unknown_token_type_%ld", static_cast(type)); - wchar_t *d2 = new wchar_t[d.size() + 1]; - // cppcheck-suppress memleak - return std::wcscpy(d2, d.c_str()); } const wchar_t *keyword_description(parse_keyword_t type) { const wchar_t *keyword = enum_to_str(type, keyword_enum_map); if (keyword) return keyword; - - // This leaks memory but it should never be run unless we have a bug elsewhere in the code. - const wcstring d = format_string(L"unknown_keyword_%ld", static_cast(type)); - wchar_t *d2 = new wchar_t[d.size() + 1]; - // cppcheck-suppress memleak - return std::wcscpy(d2, d.c_str()); + return L"unknown_keyword"; } static wcstring token_type_user_presentable_description(