Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: src/IceGlobalContext.cpp

Issue 300563003: Subzero: Initial O2 lowering (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Jan's third-round comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceDefs.h ('k') | src/IceInst.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceGlobalContext.cpp
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index 7a21b401f36f2c5098bddecd0aa102504842a248..d77a5ddb554c4e1f3ec68232da712a6cc72152d3 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//
+#include <ctype.h> // isdigit()
+
#include "IceDefs.h"
#include "IceTypes.h"
#include "IceCfg.h"
@@ -129,8 +131,14 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
return NewName;
}
- ItemsParsed = sscanf(Name.c_str(), "_Z%u%s", &BaseLength, NameBase);
- if (ItemsParsed == 2 && BaseLength <= strlen(NameBase)) {
+ // Artificially limit BaseLength to 9 digits (less than 1 billion)
+ // because sscanf behavior is undefined on integer overflow. If
+ // there are more than 9 digits (which we test by looking at the
+ // beginning of NameBase), then we consider this a failure to parse
+ // a namespace mangling, and fall back to the simple prefixing.
+ ItemsParsed = sscanf(Name.c_str(), "_Z%9u%s", &BaseLength, NameBase);
+ if (ItemsParsed == 2 && BaseLength <= strlen(NameBase) &&
+ !isdigit(NameBase[0])) {
// Transform _Z3barxyz ==> _ZN6Prefix3barExyz
// ^^^^^^^^ ^
// (splice in "N6Prefix", and insert "E" after "3bar")
« no previous file with comments | « src/IceDefs.h ('k') | src/IceInst.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698