apphandler: fix wrong usage of regex_search()

Original intension of doing regex_search in `while` loop was tring to
found all possibile matchies, but it require move the begining of
string each time manually, and it also hard to decide how long need to
moved.

Change to use `if` to only convert the first matchies found, and return
when any convertion failed.

Change-Id: I050d7f0457b36632c5c8a827f53082542c5f6691
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
diff --git a/apphandler.cpp b/apphandler.cpp
index 8ad2879..58f6868 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -486,15 +486,20 @@
     Revision r = {0};
     size_t val;
 
-    while (std::regex_search(s, m, fw_regex))
+    if (std::regex_search(s, m, fw_regex))
     {
+        if (m.size() < 3)
+        { // required m.size() to be at lease 3 to convert both major and minor
+            return -1;
+        }
+
         // convert major
         {
             std::string_view str = m[1].str();
             auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)};
             if (ec != std::errc() || ptr != str.begin() + str.size())
             { // failed to convert major string
-                continue;
+                return -1;
             }
             r.major = val & 0x7F;
         }
@@ -505,7 +510,7 @@
             auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)};
             if (ec != std::errc() || ptr != str.begin() + str.size())
             { // failed to convert minor string
-                continue;
+                return -1;
             }
             r.minor = val & 0xFF;
         }