]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh-table: Ensure NULL terminated arguments to vshTable*()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 14 Dec 2021 14:26:47 +0000 (15:26 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 17 Dec 2021 14:05:58 +0000 (15:05 +0100)
There are two functions that take variable arguments:
vshTableNew() and vshTableRowAppend(). Both expect the list of
arguments to be NULL terminated. Annotate them with
G_GNUC_NULL_TERMINATED to enable compile time check for this.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/vshtabletest.c
tools/vsh-table.h

index 2b997753ff311e0bc6dab6f7e6ba225ff49c782f..83d7f9b5abf19935f90895feffd3cb2d2a8dea53 100644 (file)
@@ -33,7 +33,7 @@
 static int
 testVshTableNew(const void *opaque G_GNUC_UNUSED)
 {
-    g_autoptr(vshTable) table = vshTableNew(NULL);
+    g_autoptr(vshTable) table = vshTableNew(NULL, NULL);
 
     if (table) {
         fprintf(stderr, "expected failure when passing null to vshTableNew\n");
@@ -85,7 +85,7 @@ testVshTableRowAppend(const void *opaque G_GNUC_UNUSED)
     if (!table)
         return -1;
 
-    if (vshTableRowAppend(table, NULL) >= 0) {
+    if (vshTableRowAppend(table, NULL, NULL) >= 0) {
         fprintf(stderr, "Appending NULL shouldn't work\n");
         return -1;
     }
index df647e3ba912d46eca4a0ad4615d2e9216b47ef2..18d5139aa612970253f0acbd9c873203ad4ca67e 100644 (file)
@@ -29,10 +29,12 @@ vshTableFree(vshTable *table);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(vshTable, vshTableFree);
 
 vshTable *
-vshTableNew(const char *format, ...);
+vshTableNew(const char *format, ...)
+    G_GNUC_NULL_TERMINATED;
 
 int
-vshTableRowAppend(vshTable *table, const char *arg, ...);
+vshTableRowAppend(vshTable *table, const char *arg, ...)
+    G_GNUC_NULL_TERMINATED;
 
 void
 vshTablePrintToStdout(vshTable *table, vshControl *ctl);