[PATCH] utils: make guestfs_int_count_strings return 0 on NULL input
This miniature patch makes function guestfs_int_count_strings accept NULL input and return 0 signalling that it is empty list. It makes it more usefull with NULL initialized variables and a tiny bit more robust. Maros Zatko (1): utils: make guestfs_int_count_strings return 0 on NULL input src/utils.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.5.5
Make guestfs_int_count_strings a bit more robust and usefull with NULL initialized variables. --- src/utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils.c b/src/utils.c index f099a22..3639e92 100644 --- a/src/utils.c +++ b/src/utils.c @@ -55,6 +55,9 @@ guestfs_int_count_strings (char *const *argv) { size_t r; + if (argv == NULL) + return 0; + for (r = 0; argv[r]; ++r) ; -- 2.5.5
On Tue, May 24, 2016 at 06:20:43PM +0200, Maros Zatko wrote:
Make guestfs_int_count_strings a bit more robust and usefull with NULL initialized variables. --- src/utils.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/src/utils.c b/src/utils.c index f099a22..3639e92 100644 --- a/src/utils.c +++ b/src/utils.c @@ -55,6 +55,9 @@ guestfs_int_count_strings (char *const *argv) { size_t r;
+ if (argv == NULL) + return 0; +
Not sure about this. Wouldn't we prefer that it crashes since that would indicate a programming error? ('Course it would be nice if we had a language that enforced this statically at compile time, but I've never heard of such a thing ...) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
participants (2)
-
Maros Zatko -
Richard W.M. Jones