@@ -23,19 +23,22 @@ static constexpr const char* HIGHER_OR_EQUAL_OPERATOR = ">=";
2323static constexpr const char * TILDE_OPERATOR = " ~" ;
2424static constexpr const char * CARET_OPERATOR = " ^" ;
2525
26+ // Dbgconf assignment names follow C-style identifier rules.
2627static bool IsDbgconfVariableName (const string& value) {
2728 if (value.empty () || (!isalpha (static_cast <unsigned char >(value[0 ])) && value[0 ] != ' _' )) {
2829 return false ;
2930 }
3031 return all_of (value.begin () + 1 , value.end (), [](unsigned char c) { return isalnum (c) || c == ' _' ; });
3132}
3233
34+ // Remove surrounding whitespace without changing the assignment value content.
3335static string Trim (const string& value) {
3436 const auto first = find_if_not (value.begin (), value.end (), [](unsigned char c) { return isspace (c); });
3537 const auto last = find_if_not (value.rbegin (), value.rend (), [](unsigned char c) { return isspace (c); }).base ();
3638 return first < last ? string (first, last) : string ();
3739}
3840
41+ // Strip C and C++ comments while preserving line breaks that separate statements.
3942static string StripCComments (const string& input) {
4043 string output;
4144 bool inLineComment = false ;
@@ -500,10 +503,13 @@ map<string, string> ProjMgrUtils::ParseDbgconfFile(const string& dbgconf) {
500503 }
501504
502505 const string contentWithoutComments = StripCComments (content);
506+ // Split semicolon-separated statements, also accepting a final unterminated assignment.
503507 size_t statementStart = 0 ;
504508 size_t statementEnd = contentWithoutComments.find (' ;' );
505- while (statementEnd != string::npos) {
506- const string statement = contentWithoutComments.substr (statementStart, statementEnd - statementStart);
509+ while (statementStart < contentWithoutComments.length ()) {
510+ const string statement = contentWithoutComments.substr (
511+ statementStart,
512+ statementEnd == string::npos ? string::npos : statementEnd - statementStart);
507513 const size_t assignment = statement.find (' =' );
508514 if (assignment != string::npos) {
509515 const string key = Trim (statement.substr (0 , assignment));
@@ -512,6 +518,9 @@ map<string, string> ProjMgrUtils::ParseDbgconfFile(const string& dbgconf) {
512518 assignments[key] = value;
513519 }
514520 }
521+ if (statementEnd == string::npos) {
522+ break ;
523+ }
515524 statementStart = statementEnd + 1 ;
516525 statementEnd = contentWithoutComments.find (' ;' , statementStart);
517526 }
0 commit comments