summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fmt.c6
-rw-r--r--test/test_fmt_sscanf.c34
2 files changed, 40 insertions, 0 deletions
diff --git a/fmt.c b/fmt.c
index e2e15a5..bfee475 100644
--- a/fmt.c
+++ b/fmt.c
@@ -1109,11 +1109,17 @@ fmt_sscanf_state_produce_int(struct fmt_sscanf_state *state)
c = fmt_sscanf_state_consume_string(state);
} else {
fmt_sscanf_state_restore_string(state);
+ c = '0';
}
} else {
if (state->base == 0) {
state->base = 8;
}
+
+ if (state->base != 8) {
+ fmt_sscanf_state_restore_string(state);
+ c = '0';
+ }
}
}
diff --git a/test/test_fmt_sscanf.c b/test/test_fmt_sscanf.c
index b2a4e74..8abab69 100644
--- a/test/test_fmt_sscanf.c
+++ b/test/test_fmt_sscanf.c
@@ -677,6 +677,38 @@ test_38(void)
#undef STRING
}
+static void
+test_39(void)
+{
+ int reta, retb;
+ unsigned int ia, ib;
+
+#define STRING "0"
+#define FORMAT "%u"
+ reta = sscanf(STRING, FORMAT, &ia);
+ retb = fmt_sscanf(STRING, FORMAT, &ib);
+ check(reta == retb);
+ check(ia == ib);
+#undef FORMAT
+#undef STRING
+}
+
+static void
+test_40(void)
+{
+ int reta, retb;
+ int ia, ib;
+
+#define STRING "-0"
+#define FORMAT "%d"
+ reta = sscanf(STRING, FORMAT, &ia);
+ retb = fmt_sscanf(STRING, FORMAT, &ib);
+ check(reta == retb);
+ check(ia == ib);
+#undef FORMAT
+#undef STRING
+}
+
int
main(int argc, char *argv[])
{
@@ -721,6 +753,8 @@ main(int argc, char *argv[])
test_36();
test_37();
test_38();
+ test_39();
+ test_40();
return 0;
}