aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-01-28 09:13:29 +0000
committergingerBill <bill@gingerbill.org>2018-01-28 09:13:29 +0000
commitbee4cb57f20d0310a3bbaa39ccdfa1165d82974a (patch)
treee040f140367995bbc733154ea387b5f9d624e0fa
parent53b670b889791cf9f7652830cf079c8b877222c6 (diff)
Fix printf bug #177
-rw-r--r--core/fmt.odin17
1 files changed, 9 insertions, 8 deletions
diff --git a/core/fmt.odin b/core/fmt.odin
index 2c78019ab..3efbfb822 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -316,7 +316,7 @@ _parse_int :: proc(s: string, offset: int) -> (result: int, new_offset: int, ok:
new_offset = offset;
n := len(s[new_offset..]);
- for new_offset < n {
+ for new_offset <= n {
c := rune(s[new_offset]);
if !is_digit(c) do break;
new_offset += 1;
@@ -1034,7 +1034,7 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string {
was_prev_index := false;
- for i := 0; i < end; /**/ {
+ loop: for i := 0; i < end; /**/ {
fi = Fmt_Info{buf = b, good_arg_index = true};
prev_i := i;
@@ -1045,7 +1045,7 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string {
write_string(b, fmt[prev_i..i]);
}
if i >= end {
- break;
+ break loop;
}
// Process a "verb"
@@ -1125,19 +1125,20 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string {
if i >= end {
write_string(b, "%!(NO VERB)");
- break;
+ break loop;
}
verb, w := utf8.decode_rune_from_string(fmt[i..]);
i += w;
- if verb == '%' {
+ switch {
+ case verb == '%':
write_byte(b, '%');
- } else if !fi.good_arg_index {
+ case !fi.good_arg_index:
write_string(b, "%!(BAD ARGUMENT NUMBER)");
- } else if arg_index >= len(args) {
+ case arg_index >= len(args):
write_string(b, "%!(MISSING ARGUMENT)");
- } else {
+ case:
fmt_arg(&fi, args[arg_index], verb);
arg_index += 1;
}