summaryrefslogtreecommitdiff
path: root/src/s2wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-12 13:19:15 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-12 13:19:15 -0800
commit53bfa6cae963c62c40c1eac305ae94b6dea6e59c (patch)
tree8084fa03cd3a5fe2a016f982eb3f565da600c93f /src/s2wasm.h
parentba882732bbe63010cd2b3fe3ad2bd57c16cf6eec (diff)
downloadbinaryen-53bfa6cae963c62c40c1eac305ae94b6dea6e59c.tar.gz
binaryen-53bfa6cae963c62c40c1eac305ae94b6dea6e59c.tar.bz2
binaryen-53bfa6cae963c62c40c1eac305ae94b6dea6e59c.zip
more escaping
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r--src/s2wasm.h33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 48e9dac10..6f209a436 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -181,19 +181,24 @@ private:
assert(*s == '"');
s++;
std::vector<char> str;
- auto ESCAPES = "nrtfb\\\"";
while (*s && *s != '\"') {
if (s[0] == '\\') {
- if (strchr(ESCAPES, s[1])) {
- str.push_back(s[1]);
- s += 2;
- continue;
- } else if (isdigit(s[1])) {
- int code = (s[1] - '0')*8*8 + (s[2] - '0')*8 + (s[3] - '0');
- str.push_back(char(code));
- s += 4;
- continue;
- } else abort_on("getQuoted-escape");
+ switch (s[1]) {
+ case 'n': str.push_back('\n'); s += 2; continue;
+ case 'r': str.push_back('\r'); s += 2; continue;
+ case 't': str.push_back('\t'); s += 2; continue;
+ case 'f': str.push_back('\f'); s += 2; continue;
+ case 'b': str.push_back('\b'); s += 2; continue;
+ case '\\': str.push_back('\\'); s += 2; continue;
+ default: {
+ if (isdigit(s[1])) {
+ int code = (s[1] - '0')*8*8 + (s[2] - '0')*8 + (s[3] - '0');
+ str.push_back(char(code));
+ s += 4;
+ continue;
+ } else abort_on("getQuoted-escape");
+ }
+ }
}
str.push_back(*s);
s++;
@@ -740,10 +745,10 @@ private:
}
} else if (match(".int32")) {
raw->resize(4);
- (*(int32_t*)(&raw[0])) = getInt();
+ (*(int32_t*)(&(*raw)[0])) = getInt();
} else if (match(".int64")) {
raw->resize(8);
- (*(int64_t*)(&raw[0])) = getInt();
+ (*(int64_t*)(&(*raw)[0])) = getInt();
} else abort_on("data form");
skipWhitespace();
mustMatch(".size");
@@ -754,7 +759,7 @@ private:
while (nextStatic % align) nextStatic++;
// assign the address, add to memory
staticAddresses[name] = nextStatic;
- wasm.memory.segments.emplace_back(nextStatic, (const char*)&raw[0], seenSize);
+ wasm.memory.segments.emplace_back(nextStatic, (const char*)&(*raw)[0], seenSize);
nextStatic += seenSize;
}