Snap for 6001391 from 4797d5b58a1ec5592b4dd37531f65d7522fc9a4a to qt-aml-networking-release

Change-Id: Ic840cf48e8410ed0ffddee474bafe841475928cd
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 310ff1e..dbd1f8b 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -309,6 +309,10 @@
 AidlConstantValue* AidlConstantValue::ShallowIntegralCopy(const AidlConstantValue& other) {
   // TODO(b/142894901): Perform full proper copy
   AidlTypeSpecifier type = AidlTypeSpecifier(AIDL_LOCATION_HERE, "long", false, nullptr, "");
+  // TODO(b/142722772) CheckValid() should be called before ValueString()
+  if (!other.CheckValid()) {
+    AIDL_FATAL(other) << "Invalid value for ShallowIntegralCopy";
+  }
   if (!other.evaluate(type)) {
     AIDL_FATAL(other) << "Unsupported type for ShallowIntegralCopy: " << ToString(other.GetType());
   }
diff --git a/aidl_language_y.yy b/aidl_language_y.yy
index b1dfd55..c9df5e8 100644
--- a/aidl_language_y.yy
+++ b/aidl_language_y.yy
@@ -18,6 +18,7 @@
 #include "aidl_language.h"
 #include "aidl_language_y.h"
 #include "logging.h"
+#include <android-base/parseint.h>
 #include <set>
 #include <map>
 #include <stdio.h>
@@ -517,13 +518,23 @@
     delete $4;
   }
  | type identifier '(' arg_list ')' '=' INTVALUE ';' {
-    $$ = new AidlMethod(loc(@2), false, $1, $2->GetText(), $4, $1->GetComments(), std::stoi($7->GetText()));
+    int32_t serial;
+    if (!android::base::ParseInt($7->GetText(), &serial)) {
+        AIDL_ERROR(loc(@7)) << "Could not parse int value: " << $7->GetText();
+        ps->AddError();
+    }
+    $$ = new AidlMethod(loc(@2), false, $1, $2->GetText(), $4, $1->GetComments(), serial);
     delete $2;
     delete $7;
   }
  | annotation_list ONEWAY type identifier '(' arg_list ')' '=' INTVALUE ';' {
     const std::string& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments();
-    $$ = new AidlMethod(loc(@4), true, $3, $4->GetText(), $6, comments, std::stoi($9->GetText()));
+    int32_t serial;
+    if (!android::base::ParseInt($9->GetText(), &serial)) {
+        AIDL_ERROR(loc(@9)) << "Could not parse int value: " << $9->GetText();
+        ps->AddError();
+    }
+    $$ = new AidlMethod(loc(@4), true, $3, $4->GetText(), $6, comments, serial);
     $3->Annotate(std::move(*$1));
     delete $1;
     delete $2;