From: Pino Toscano Date: Fri, 15 Sep 2017 14:42:05 +0000 (+0200) Subject: Do not crash with NULL values from aug_get X-Git-Tag: v0.6~23 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=a9c904a256cb10be03995e265c8446be87b73284;p=ocaml-augeas.git Do not crash with NULL values from aug_get The Augeas documentation states that NULL can be a valid value associated to a note. Hence, make sure to not crash, and return None in case there is a single node with NULL value. Easily reproducible with: let v = Augeas.get aug "/files" in --- diff --git a/augeas-c.c b/augeas-c.c index f4396cb..b81c2b1 100644 --- a/augeas-c.c +++ b/augeas-c.c @@ -206,11 +206,11 @@ ocaml_augeas_get (value tv, value pathv) int r; r = aug_get (t, path, &val); - if (r == 1) { /* Return Some val */ + if (r == 1 && val) { /* Return Some val */ v = caml_copy_string (val); optv = caml_alloc (1, 0); Field (optv, 0) = v; - } else if (r == 0) /* Return None */ + } else if (r == 0 || !val) /* Return None */ optv = Val_int (0); else if (r == -1) /* Error or multiple matches */ raise_error (t, "Augeas.get");