summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-06 19:52:03 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-06 19:52:03 -0800
commit80e27d2fcba39ef96f3043f79e0fd3fb9e92241d (patch)
tree4b02abe80f81839cd51030a88ceb5736e8785f14 /src
parent54cc7b3916c61a0fefd66455ed6de7efe6d317bd (diff)
downloadbinaryen-80e27d2fcba39ef96f3043f79e0fd3fb9e92241d.tar.gz
binaryen-80e27d2fcba39ef96f3043f79e0fd3fb9e92241d.tar.bz2
binaryen-80e27d2fcba39ef96f3043f79e0fd3fb9e92241d.zip
fix negative hex parsing
Diffstat (limited to 'src')
-rw-r--r--src/wasm-s-parser.h34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index b9556bb3b..f3df437da 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -690,29 +690,35 @@ private:
}
switch (type) {
case i32: {
- std::istringstream istr(str);
- int32_t temp;
- if (str[0] == '0' && str[1] == 'x') {
- uint32_t temp2;
- istr >> std::hex >> temp2;
- temp = temp2;
+ if ((str[0] == '0' && str[1] == 'x') || (str[0] == '-' && str[1] == '0' && str[2] == 'x')) {
+ bool negative = str[0] == '-';
+ if (negative) str++;
+ std::istringstream istr(str);
+ uint32_t temp;
+ istr >> std::hex >> temp;
+ ret->value.i32 = negative ? -temp : temp;
} else {
+ std::istringstream istr(str);
+ int32_t temp;
istr >> temp;
+ ret->value.i32 = temp;
}
- ret->value.i32 = temp;
break;
}
case i64: {
- std::istringstream istr(str);
- int64_t temp;
- if (str[0] == '0' && str[1] == 'x') {
- uint64_t temp2;
- istr >> std::hex >> temp2;
- temp = temp2;
+ if ((str[0] == '0' && str[1] == 'x') || (str[0] == '-' && str[1] == '0' && str[2] == 'x')) {
+ bool negative = str[0] == '-';
+ if (negative) str++;
+ std::istringstream istr(str);
+ uint64_t temp;
+ istr >> std::hex >> temp;
+ ret->value.i64 = negative ? -temp : temp;
} else {
+ std::istringstream istr(str);
+ int64_t temp;
istr >> temp;
+ ret->value.i64 = temp;
}
- ret->value.i64 = temp;
break;
}
case f32: {