summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-17 21:38:31 -0400
committerDavid Robillard <d@drobilla.net>2016-03-17 21:38:31 -0400
commit2843ab1de415ccaf9be291439ca04690c1ed073f (patch)
treeacfaeb4128caae51dd11482376a517bde434419c
parentce981fefe0c4d4f9c871b574a92eec06e3149e3e (diff)
downloadsord-2843ab1de415ccaf9be291439ca04690c1ed073f.tar.gz
sord-2843ab1de415ccaf9be291439ca04690c1ed073f.tar.bz2
sord-2843ab1de415ccaf9be291439ca04690c1ed073f.zip
Return NULL from sord_iter_get for end iterators
-rw-r--r--NEWS5
-rw-r--r--sord/sord.h2
-rw-r--r--src/sord.c4
3 files changed, 8 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index b89f6fb..594628f 100644
--- a/NEWS
+++ b/NEWS
@@ -4,9 +4,10 @@ sord (0.15.1) unstable;
* Return error from sord_inserter_write_statement() if a node can not be written
(e.g. undefined prefix)
* Make sord_node_get_counted return byte count, and clarify documentation
- * Add sord_node_get_string_measured to get both byte and character counts
+ * Safely return NULL from sord_iter_get() for end iterators
+ * Add sord_node_get_string_measured() to get both byte and character counts
- -- David Robillard <d@drobilla.net> Tue, 15 Mar 2016 14:51:35 -0400
+ -- David Robillard <d@drobilla.net> Thu, 17 Mar 2016 21:38:13 -0400
sord (0.14.0) stable;
diff --git a/sord/sord.h b/sord/sord.h
index e93cff8..eff15af 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -559,6 +559,8 @@ sord_iter_get(const SordIter* iter, SordQuad quad);
/**
Return a field of the quad pointed to by `iter`.
+
+ Returns NULL if `iter` is NULL or is at the end.
*/
SORD_API
const SordNode*
diff --git a/src/sord.c b/src/sord.c
index fbc33f7..22732c9 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -445,7 +445,9 @@ sord_iter_get(const SordIter* iter, SordQuad id)
const SordNode*
sord_iter_get_node(const SordIter* iter, SordQuadIndex index)
{
- return iter ? ((SordNode**)zix_btree_get(iter->cur))[index] : NULL;
+ return (!sord_iter_end(iter)
+ ? ((SordNode**)zix_btree_get(iter->cur))[index]
+ : NULL);
}
static bool