nostrdb-rs

nostrdb in rust!
git clone git://jb55.com/nostrdb-rs
Log | Files | Refs | Submodules | README | LICENSE

commit fdc4670526f346d0507e4efcc99bb3d79cf69a19
parent 622b0054b1df533eb547682663154127bf4e88e1
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  8 Apr 2024 08:58:18 -0700

tags: fix infinite loop in tags iteration

Reported-by: yukikishimoto@protonmail.com
Fixes: https://github.com/damus-io/nostrdb-rs/issues/5
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/tags.rs | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/tags.rs b/src/tags.rs @@ -143,10 +143,12 @@ impl<'a> Iterator for TagsIter<'a> { type Item = Tag<'a>; fn next(&mut self) -> Option<Self::Item> { - unsafe { - bindings::ndb_tags_iterate_next(self.as_mut_ptr()); - }; - self.tag() + let res = unsafe { bindings::ndb_tags_iterate_next(self.as_mut_ptr()) }; + if res == 0 { + None + } else { + self.tag() + } } } @@ -219,6 +221,8 @@ mod tests { assert_eq!(t2.get(2).is_none(), true); assert_eq!(t2_e0.variant(), NdbStrVariant::Str("hi")); assert_eq!(t2_e1.variant(), NdbStrVariant::Str("3")); + + assert_eq!(tags_iter.next().is_none(), true); } } }