From 9f7babc3ff000d1a8a567479c1b5d309658d8b7f Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Thu, 1 Aug 2024 08:00:57 -0500 Subject: [PATCH] Use c-strings to constant initialize token array Since `std::string` has to be dynamically constructed and destructed, it could be accessed before initialization or after destruction in a multithreaded context. By using constant c-strings instead, we guarantee that the array will be valid for the whole lifetime of the program. The use of `constexpr` also enforces this requirement. I have run clang-format on the file to format my changes according to CONTRIBUTING.md. --- src/token.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/token.h b/src/token.h index 9c9a5b7..1134af0 100644 --- a/src/token.h +++ b/src/token.h @@ -13,7 +13,7 @@ #include namespace YAML { -const std::string TokenNames[] = { +constexpr const char* TokenNames[] = { "DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START", "BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY", "FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",