On 2/23/20 3:20 PM, Ján Tomko wrote:
Prefer g_ascii_xdigit_value to virHexToBin.
Check the return value of the function and
remove the g_ascii_isxdigit calls, since
they're done anyway internally.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
Reviewed-by: Laine Stump <laine(a)redhat.com>
(The two functions behave differently in the case of being passed
invalid hex-ascii characters, but all our uses check for valid input
prior to calling, so that difference doesn't matter).
---
src/util/viruuid.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/util/viruuid.c b/src/util/viruuid.c
index c8ee59beee..908b09945d 100644
--- a/src/util/viruuid.c
+++ b/src/util/viruuid.c
@@ -29,7 +29,6 @@
#include <unistd.h>
#include "internal.h"
-#include "virutil.h"
#include "virerror.h"
#include "virlog.h"
#include "viralloc.h"
@@ -105,6 +104,7 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid)
cur++;
for (i = 0; i < VIR_UUID_BUFLEN;) {
+ int val;
uuid[i] = 0;
if (*cur == 0)
return -1;
@@ -112,16 +112,15 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid)
cur++;
continue;
}
- if (!g_ascii_isxdigit(*cur))
+ if ((val = g_ascii_xdigit_value(*cur)) < 0)
return -1;
- uuid[i] = virHexToBin(*cur);
- uuid[i] *= 16;
+ uuid[i] = 16 * val;
cur++;
if (*cur == 0)
return -1;
- if (!g_ascii_isxdigit(*cur))
+ if ((val = g_ascii_xdigit_value(*cur)) < 0)
return -1;
- uuid[i] += virHexToBin(*cur);
+ uuid[i] += val;
i++;
cur++;
}