From df91caafa1d114ec54a0e8041aa1117c35c52dfd Mon Sep 17 00:00:00 2001 From: "Albert ARIBAUD (3ADEV)" Date: Mon, 4 Jan 2016 16:08:02 +0100 Subject: [PATCH] Fix trim() in lib/Preprocessor.cpp Currently, if its argument is all spaces and tabs, trim() returns it without actually trimming it. Fix this by returning an empty string in this case. Also, drop a useless test: if we did not return "" then beg is not equal to std::string::npos, and in that case, neither is end. --- lib/preprocessor.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e889cd485..df5a862c1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2414,16 +2414,15 @@ static void skipstring(const std::string &line, std::string::size_type &pos) /** * Remove heading and trailing whitespaces from the input parameter. + * If string is all spaces/tabs, return empty string. * @param s The string to trim. */ static std::string trim(const std::string& s) { const std::string::size_type beg = s.find_first_not_of(" \t"); if (beg == std::string::npos) - return s; + return ""; const std::string::size_type end = s.find_last_not_of(" \t"); - if (end == std::string::npos) - return s.substr(beg); return s.substr(beg, end - beg + 1); }