]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: pcivpd: Refactor virPCIVPDResourceIsValidTextValue
authorPeter Krempa <pkrempa@redhat.com>
Wed, 24 Jan 2024 14:53:39 +0000 (15:53 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 31 Jan 2024 16:24:06 +0000 (17:24 +0100)
The function is never called with NULL argument. Remove the check and
refactor the rest including the debug statement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virpcivpd.c

index 248a9b2790e0255b631299febcef69c0d65db32c..81c7c317b3439f12cc91dc1accc30aa00e9adc21 100644 (file)
@@ -175,23 +175,18 @@ virPCIVPDResourceGetFieldValueFormat(const char *keyword)
 bool
 virPCIVPDResourceIsValidTextValue(const char *value)
 {
-    size_t i = 0;
+    const char *v;
+    bool ret = true;
 
-    if (value == NULL)
-        return false;
-
-    /* An empty string is a valid value. */
-    if (STREQ(value, ""))
-        return true;
-
-    while (i < strlen(value)) {
-        if (!g_ascii_isprint(value[i])) {
-            VIR_DEBUG("The provided value contains non-ASCII printable characters: %s", value);
-            return false;
+    for (v = value; *v; v++) {
+        if (!g_ascii_isprint(*v)) {
+            ret = false;
+            break;
         }
-        ++i;
     }
-    return true;
+
+    VIR_DEBUG("val='%s' ret='%d'", value, ret);
+    return ret;
 }
 
 void