Skip to content

Commit 7844db3

Browse files
committed
handle precision -1 in printf .*
1 parent cb0f677 commit 7844db3

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/library.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1950,9 +1950,9 @@ LibraryManager.library = {
19501950
}
19511951

19521952
// Handle precision.
1953-
var precisionSet = false;
1953+
var precisionSet = false, precision = -1;
19541954
if (next == {{{ charCode('.') }}}) {
1955-
var precision = 0;
1955+
precision = 0;
19561956
precisionSet = true;
19571957
textIndex++;
19581958
next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}};
@@ -1969,9 +1969,8 @@ LibraryManager.library = {
19691969
}
19701970
}
19711971
next = {{{ makeGetValue(0, 'textIndex+1', 'i8') }}};
1972-
} else {
1973-
var precision = 6; // Standard default.
19741972
}
1973+
if (precision === -1) precision = 6; // Standard default.
19751974

19761975
// Handle integer sizes. WARNING: These assume a 32-bit architecture!
19771976
var argSize;

tests/printf/output.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8280,4 +8280,5 @@ ffffff8000000000
82808280
1
82818281
1
82828282

8283+
1.234568E+04
82838284
no_new_line

tests/printf/output_i64_1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8280,4 +8280,5 @@ ffffff8000000000
82808280
1
82818281
1
82828282

8283+
1.234568E+04
82838284
no_new_line

tests/printf/test.c

+1
Original file line numberDiff line numberDiff line change
@@ -8285,6 +8285,7 @@ int main() {
82858285
printf("%hx\n", -0xFFFF);
82868286
printf("%x\n", -0xFFFFFFFF);
82878287
printf("\n");
8288+
printf("%*.*E\n", 10, -1, 12345.6789123);
82888289
printf("no_new_line");
82898290
return 0;
82908291
}

0 commit comments

Comments
 (0)