~sircmpwn/public-inbox

hare: encoding::json: fix infinite loop in iterator next v2 PROPOSED

Patrick Widmer: 1
 encoding::json: fix infinite loop in iterator next

 1 files changed, 3 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/32222/mbox | git am -3
Learn more about email & git

[PATCH hare v2] encoding::json: fix infinite loop in iterator next Export this patch

Signed-off-by: Patrick Widmer <patrick.widmer@tbwnet.ch>
---
Previously, next calls would infinitely return the same entry.

 encoding/json/value.ha | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/encoding/json/value.ha b/encoding/json/value.ha
index 486be438..8fd1f642 100644
--- a/encoding/json/value.ha
+++ b/encoding/json/value.ha
@@ -75,11 +75,13 @@ export fn iter(obj: *object) iterator = {
export fn next(iter: *iterator) ((const str, const *value) | void) = {
	for (iter.i < len(iter.obj.buckets); iter.i += 1) {
		const bucket = &iter.obj.buckets[iter.i];
		for (iter.j < len(bucket); iter.j += 1) {
		for (iter.j < len(bucket)) {
			const key = bucket[iter.j].0;
			const val = &bucket[iter.j].1;
			iter.j += 1;
			return (key, val);
		};
		iter.j = 0;
	};
};

-- 
2.36.1
This looks like a good fix, but would you mind also adding a test case
for this function?