]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: Accept const @value in hypervSetEmbeddedProperty()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Oct 2020 09:55:10 +0000 (11:55 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 20 Oct 2020 10:05:50 +0000 (12:05 +0200)
The hypervSetEmbeddedProperty() function is used to update a
value for given property in a list of properties created by
hypervCreateEmbeddedParam(). The list is nothing fancy - it's a
virHashTable that has NULL as dataFree callback => the table does
not own the value. This is not that obvious since
hypervSetEmbeddedProperty() accepts a non-const pointer. This
fact makes it unnecessary hard to consume, e.g. if we wanted to
pass a stack allocated string.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Matt Coleman <matt@datto.com>
src/hyperv/hyperv_wmi.c
src/hyperv/hyperv_wmi.h

index 41579858dec32d68f12affae97f477b334ff46fa..742a46bc284f3e896966c3aff60462dc5c14a34a 100644 (file)
@@ -351,10 +351,26 @@ hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr info)
     return NULL;
 }
 
+
+/**
+ * hypervSetEmbeddedProperty:
+ * @table: hash table allocated earlier by hypervCreateEmbeddedParam()
+ * @name: name of the property
+ * @value: value of the property
+ *
+ * For given table of properties, set property of @name to @value.
+ * Please note, that the hash table does NOT become owner of the @value and
+ * thus caller must ensure the pointer validity.
+ *
+ * Returns: 0 on success,
+ *         -1 otherwise.
+ */
 int
-hypervSetEmbeddedProperty(virHashTablePtr table, const char *name, char *value)
+hypervSetEmbeddedProperty(virHashTablePtr table,
+                          const char *name,
+                          const char *value)
 {
-    return virHashUpdateEntry(table, name, value);
+    return virHashUpdateEntry(table, name, (void*) value);
 }
 
 /*
index fb19a7f375fe29e1841c4b6ecce129267b6a8307..fa8e48a70ece8add846be9b181f9cdfadd62014f 100644 (file)
@@ -146,8 +146,9 @@ int hypervAddEprParam(hypervInvokeParamsListPtr params, const char *name,
 virHashTablePtr hypervCreateEmbeddedParam(hypervPrivate *priv,
         hypervWmiClassInfoListPtr info);
 
-int hypervSetEmbeddedProperty(virHashTablePtr table, const char *name,
-        char *value);
+int hypervSetEmbeddedProperty(virHashTablePtr table,
+                              const char *name,
+                              const char *value);
 
 int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params,
                            hypervPrivate *priv,