]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch_tags_advance: Make safe against excessive calls.
authorCarl Worth <cworth@cworth.org>
Sun, 15 Nov 2009 07:02:55 +0000 (23:02 -0800)
committerCarl Worth <cworth@cworth.org>
Sun, 15 Nov 2009 07:02:55 +0000 (23:02 -0800)
Previously, an excess call would have caused a crash. Now it simply
does nothing. Also, make notmuch_tags_get use a similar, consistent
early return for a NULL iterator.

lib/tags.c

index afc132c50e17c2f41cb6f6709e3c6d827d237b95..85507e91fc35da13b52b1b82b2bcbe2a71af8f83 100644 (file)
@@ -97,15 +97,18 @@ notmuch_tags_has_more (notmuch_tags_t *tags)
 const char *
 notmuch_tags_get (notmuch_tags_t *tags)
 {
 const char *
 notmuch_tags_get (notmuch_tags_t *tags)
 {
-    if (tags->iterator)
-       return (char *) tags->iterator->data;
-    else
+    if (tags->iterator == NULL)
        return NULL;
        return NULL;
+
+    return (char *) tags->iterator->data;
 }
 
 void
 notmuch_tags_advance (notmuch_tags_t *tags)
 {
 }
 
 void
 notmuch_tags_advance (notmuch_tags_t *tags)
 {
+    if (tags->iterator == NULL)
+       return;
+
     tags->iterator = tags->iterator->next;
 }
 
     tags->iterator = tags->iterator->next;
 }