# HG changeset patch # User John W. Eaton # Date 1578668924 18000 # Node ID cf45351fc7fac89037defacc285da1b59d8d226b # Parent 733d056eb867ba1bfb2cf2eebdfa77c21d8a2039 avoid parse exception when initial comment block is all whitespace lex.ll (looks_like_copyright): Check that value returned from std::string::find_first_no_of is valid. diff -r 733d056eb867 -r cf45351fc7fa libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Thu Jan 09 14:04:48 2020 -0800 +++ b/libinterp/parse-tree/lex.ll Fri Jan 10 10:08:44 2020 -0500 @@ -2301,21 +2301,18 @@ static bool looks_like_copyright (const std::string& s) { - bool retval = false; - - if (! s.empty ()) - { - // Comment characters have been stripped but whitespace - // (including newlines) remains. - - size_t offset = s.find_first_not_of (" \t\n\r"); - - retval = (s.substr (offset, 9) == "Copyright" - || s.substr (offset, 6) == "Author" - || s.substr (offset, 23) == "SPDX-License-Identifier"); - } - - return retval; + if (s.empty ()) + return false; + + // Comment characters have been stripped but whitespace + // (including newlines) remains. + + size_t offset = s.find_first_not_of (" \t\n\r"); + + return (offset != std::string::npos + && (s.substr (offset, 9) == "Copyright" + || s.substr (offset, 6) == "Author" + || s.substr (offset, 23) == "SPDX-License-Identifier")); } static bool