[PATCH v3 04/25] virTypedParameterAssignValueVArgs: Ensure proper typed param type in caller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There are two callers of virTypedParameterAssignValueVArgs.

- 'virTypedParameterAssignValue' always uses the correct type, thus
  doesn't need to be modified. Just use the proper type in the function
  declaration

- 'virTypedParameterAssign' can get improper type, but we can move the
  validation into it decreasing the scope in which failures need to be
  propagated.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virtypedparam.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index fe4c04bcea..f325f3b012 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -203,7 +203,7 @@ virTypedParameterToString(virTypedParameterPtr param)
 }


-static int
+static void
 virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
                                   virTypedParameterType type,
                                   va_list ap,
@@ -240,30 +240,23 @@ virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
             param->value.s = g_strdup("");
         break;
     case VIR_TYPED_PARAM_LAST:
-    default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected type %1$d for field %2$s"), type,
-                       NULLSTR(param->field));
-        return -1;
+        break;
     }
-
-    return 0;
 }


 static int
 virTypedParameterAssignValue(virTypedParameterPtr param,
-                             int type,
+                             virTypedParameterType type,
                              ...)
 {
-    int ret;
     va_list ap;

     va_start(ap, type);
-    ret = virTypedParameterAssignValueVArgs(param, type, ap, true);
+    virTypedParameterAssignValueVArgs(param, type, ap, true);
     va_end(ap);

-    return ret;
+    return 0;
 }


@@ -276,7 +269,6 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
                         int type, ...)
 {
     va_list ap;
-    int ret = -1;

     if (virStrcpyStatic(param->field, name) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%1$s' too long"),
@@ -284,11 +276,18 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
         return -1;
     }

+    if (type < VIR_TYPED_PARAM_INT ||
+        type >= VIR_TYPED_PARAM_LAST) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected type %1$d for field %2$s"), type, name);
+        return -1;
+    }
+
     va_start(ap, type);
-    ret = virTypedParameterAssignValueVArgs(param, type, ap, false);
+    virTypedParameterAssignValueVArgs(param, type, ap, false);
     va_end(ap);

-    return ret;
+    return 0;
 }


-- 
2.39.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux