mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
collections: fix LinkedList.to_format
For-loop in LinkedList.to_format goes brrrrrr and prints the value of
the first node an infinte number of times because it does not properly
iterate the linked list.
Fix the list iterations and add the missing string format specifier.
Bug can be reproduced with:
```
import std;
fn void main() => @pool()
{
io::printfn("%s", linkedlist::@tnew{usz}({1,2,3}));
}
```
This commit is contained in:
committed by
Christoffer Lerno
parent
9d54e9e3c4
commit
15fc435d92
@@ -24,9 +24,9 @@ struct LinkedList
|
||||
fn usz? LinkedList.to_format(&self, Formatter* f) @dynamic
|
||||
{
|
||||
usz len = f.print("{ ")!;
|
||||
for (Node* node = self._first; node != null; node.next)
|
||||
for (Node* node = self._first; node != null; node = node.next)
|
||||
{
|
||||
len += f.printf(node.next ? "%s, " : "s", node.value)!;
|
||||
len += f.printf(node.next ? "%s, " : "%s", node.value)!;
|
||||
}
|
||||
return len + f.print(" }");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user