aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-15 19:15:00 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-15 19:15:00 -0700
commit459e5e6f8f0c4b0310ab00f7c0f708f65a66dc18 (patch)
tree1d4e892965e42e78d1d1ddad03dd0489c13b3a8c
parent1b1dfff97b152f237ff77628ea76ce67246d3139 (diff)
remove leading zeros in %llx
-rw-r--r--src/library.js4
-rwxr-xr-xtests/runner.py35
2 files changed, 38 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index 18f4702c..51921541 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2821,7 +2821,9 @@ LibraryManager.library = {
} else if (next == {{{ charCode('x') }}} || next == {{{ charCode('X') }}}) {
prefix = flagAlternative ? '0x' : '';
#if PRECISE_I64_MATH
- if (argSize == 8 && i64Math) argText = (origArg[1]>>>0).toString(16) + (origArg[0]>>>0).toString(16); else
+ if (argSize == 8 && i64Math) {
+ argText = (origArg[1] ? (origArg[1]>>>0).toString(16) : '') + (origArg[0]>>>0).toString(16);
+ } else
#endif
if (currArg < 0) {
// Represent negative numbers in hex as 2's complement.
diff --git a/tests/runner.py b/tests/runner.py
index 7f46dbfb..ff44e388 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -5253,6 +5253,41 @@ at function.:blag
'''
self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ def test_vsnprintf(self):
+ src = r'''
+ #include <stdio.h>
+ #include <stdarg.h>
+ #include <stdint.h>
+
+ void printy(const char *f, ...)
+ {
+ char buffer[256];
+ va_list args;
+ va_start(args, f);
+ vsnprintf(buffer, 256, f, args);
+ puts(buffer);
+ va_end(args);
+ }
+
+ int main(int argc, char **argv) {
+ int64_t x = argc - 1;
+ int64_t y = argc - 1 + 0x400000;
+ if (x % 3 == 2) y *= 2;
+
+ printy("0x%llx_0x%llx", x, y);
+ printy("0x%llx_0x%llx", x, x);
+ printy("0x%llx_0x%llx", y, x);
+ printy("0x%llx_0x%llx", y, y);
+
+ return 0;
+ }
+ '''
+ self.do_run(src, '''0x0_0x400000
+0x0_0x0
+0x400000_0x0
+0x400000_0x400000
+''')
+
def test_printf_more(self):
src = r'''
#include <stdio.h>