From cf913b41c6f3e3d46eb654feb7b43a48dd141d97 Mon Sep 17 00:00:00 2001 From: Christian Buttner Date: Fri, 18 Jul 2025 15:54:07 +0200 Subject: [PATCH] Fix `Formatter.print` returning incorrect size (#2306) * Fix `Formatter.print` returning incorrect size --- lib/std/io/formatter.c3 | 3 +-- lib/std/io/formatter_private.c3 | 1 - releasenotes.md | 2 ++ test/test_suite/struct/init_cont_struct_array_locally.c3t | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index db21b9bca..4c89d5ee1 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -69,7 +69,6 @@ struct Formatter PrintFlags flags; uint width; uint prec; - usz idx; fault first_fault; } } @@ -571,5 +570,5 @@ fn usz? Formatter.print(&self, String str) self.out_fn = &out_null_fn; } foreach (c : str) self.out(c)!; - return self.idx; + return str.len; } diff --git a/lib/std/io/formatter_private.c3 b/lib/std/io/formatter_private.c3 index 5291355f3..1080f447c 100644 --- a/lib/std/io/formatter_private.c3 +++ b/lib/std/io/formatter_private.c3 @@ -660,7 +660,6 @@ fn usz? Formatter.out_char(&self, any arg) @private fn usz? Formatter.out_reverse(&self, char[] buf) @private { usz n; - usz buffer_start_idx = self.idx; usz len = buf.len; // pad spaces up to given width if (!self.flags.zeropad && !self.flags.left) diff --git a/releasenotes.md b/releasenotes.md index 2ab8517be..ddd4cdda0 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -59,6 +59,7 @@ - Segfault when failing to cast subexpression to 'isz' in pointer subtraction #2305. - Fix unexpected display of macro definition when passing a poisoned expression #2305. - `@links` on macros would not be added to calling functions. +- Fix `Formatter.print` returning incorrect size. ### Stdlib changes - Improve contract for readline. #2280 @@ -66,6 +67,7 @@ - Added string::bformat. - Virtual memory library. - New virtual emory arena allocator. +- Added `WString.len`. ## 0.7.3 Change list diff --git a/test/test_suite/struct/init_cont_struct_array_locally.c3t b/test/test_suite/struct/init_cont_struct_array_locally.c3t index 66282d803..5967404cb 100644 --- a/test/test_suite/struct/init_cont_struct_array_locally.c3t +++ b/test/test_suite/struct/init_cont_struct_array_locally.c3t @@ -49,7 +49,7 @@ entry: %0 = call ptr @std.io.stdout() call void @llvm.memcpy.p0.p0.i32(ptr align 1 %x1, ptr align 1 %x, i32 2, i1 false) call void @llvm.memcpy.p0.p0.i32(ptr align 1 %x2, ptr align 1 %x1, i32 2, i1 false) - call void @llvm.memset.p0.i64(ptr align 8 %formatter, i8 0, i64 48, i1 false) + call void @llvm.memset.p0.i64(ptr align 8 %formatter, i8 0, i64 40, i1 false) %1 = insertvalue %any undef, ptr %0, 0 %2 = insertvalue %any %1, i64 ptrtoint (ptr @"$ct.std.io.File" to i64), 1 store %any %2, ptr %taddr, align 8