From fd9749b9cd3a892212adc2e41cb18d66574ae72c Mon Sep 17 00:00:00 2001 From: Will Crozier Date: Tue, 22 Feb 2022 19:47:57 +0000 Subject: [PATCH] RTC options: don't split quoted sections of string values This allows for passing in option values with quoted spaces such as include paths. --- compiler/lib/utils/options.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/lib/utils/options.cpp b/compiler/lib/utils/options.cpp index 381a9bea..16eeb67b 100644 --- a/compiler/lib/utils/options.cpp +++ b/compiler/lib/utils/options.cpp @@ -614,25 +614,25 @@ getOptionDesc(std::string& options, size_t StartPos, bool IsShortForm, return -1; } - if ((OPTION_type(od) == OT_CSTRING) && - options.at(pos) == '"') { + if (OPTION_type(od) == OT_CSTRING) { + /* Handle any quoted sections within string value */ size_t sz = options.size(); - if ((pos+1) >= sz) { - return -1; - } - /* Handle quoted string value */ - ePos = options.find('"', pos+1); - if (ePos == std::string::npos) { - return -1; + bool quoted = false; + ePos = pos; + + while (ePos < sz) { + char c = options.at(ePos); + if (c == '"') { + quoted = !quoted; + } else if (c == ' ' && !quoted) { + break; + } + ++ePos; } - /* Advance ePos to the next position or npos */ - if (ePos+1 < sz) { - ++ePos; - if (options.at(ePos) != ' ') { - return -1; - } - } else { + if (quoted) { + return -1; // closing quote is missing + } else if (ePos == sz) { ePos = std::string::npos; } } else {