changeset 27925:cf45351fc7fa

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.
author John W. Eaton <jwe@octave.org>
date Fri, 10 Jan 2020 10:08:44 -0500
parents 733d056eb867
children 3b4526d90476
files libinterp/parse-tree/lex.ll
diffstat 1 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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