diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-04-29 15:54:45 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-04-29 15:54:45 -0700 |
commit | d94a785aea5d9ef1dda385c6f11d50827adb7c33 (patch) | |
tree | e84d8f73c8922cb06816922beb0897d6eeaecf25 /tests | |
parent | d3cf5d84ecfd5218b6f570860b0a92c7eb1be0eb (diff) |
support h and hh in sscanf, and fix non-i32 case in hex sscanf; fixes #2322
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/test_sscanf_hex.in | 24 | ||||
-rw-r--r-- | tests/core/test_sscanf_hex.out | 3 |
2 files changed, 24 insertions, 3 deletions
diff --git a/tests/core/test_sscanf_hex.in b/tests/core/test_sscanf_hex.in index d8175e82..a05eb890 100644 --- a/tests/core/test_sscanf_hex.in +++ b/tests/core/test_sscanf_hex.in @@ -1,7 +1,27 @@ -#include "stdio.h" +#include <stdio.h> +#include <string> +#include <cstdlib> -int main() { +int main() +{ unsigned int a, b; sscanf("0x12AB 12AB", "%x %x", &a, &b); printf("%d %d\n", a, b); + + std::string hexstr("0102037F00FF"); + const char * cstr = hexstr.c_str(); + int len = hexstr.length() / 2; + char * tmp_data = new char[len]; + for(int i = 0; i < len; i++) + { + sscanf(cstr, "%2hhx", &tmp_data[i]); + cstr += 2 * sizeof(char); + } + + for (int j = 0; j < len; j++) + printf("%i, ", tmp_data[j]); + printf("\n"); + delete[] tmp_data; } + + diff --git a/tests/core/test_sscanf_hex.out b/tests/core/test_sscanf_hex.out index ac855044..6e7f66aa 100644 --- a/tests/core/test_sscanf_hex.out +++ b/tests/core/test_sscanf_hex.out @@ -1 +1,2 @@ -4779 4779
\ No newline at end of file +4779 4779 +1, 2, 3, 127, 0, -1, |