From 4bcd0b3c1766e459426e7d4138619790d4dd77d8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 12 Mar 2012 11:27:32 +0000 Subject: inspect: Use 1/0 instead of true/false, and fix a bug in UUID parsing. UUID parsing returned 'false' (ie. 0 == OK) when the UUID contained illegal characters. Now it returns -1 == failure. --- src/inspect_fs_unix.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c index fe44c3aa..09d47d6b 100644 --- a/src/inspect_fs_unix.c +++ b/src/inspect_fs_unix.c @@ -913,10 +913,10 @@ uuid_cmp(const void *x, const void *y) const md_uuid *b = y; for (size_t i = 0; i < 1; i++) { - if (a->uuid[i] != b->uuid[i]) return false; + if (a->uuid[i] != b->uuid[i]) return 0; } - return true; + return 1; } static void @@ -929,23 +929,27 @@ md_uuid_free(void *x) /* Taken from parse_uuid in mdadm */ static int -parse_uuid(const char *str, uint32_t *uuid) +parse_uuid (const char *str, uint32_t *uuid) { - for (size_t i = 0; i < 4; i++) uuid[i] = 0; - - int hit = 0; /* number of Hex digIT */ + size_t hit = 0; /* number of Hex digIT */ char c; + size_t i; + int n; + + for (i = 0; i < 4; i++) + uuid[i] = 0; + while ((c = *str++)) { - int n; if (c >= '0' && c <= '9') n = c - '0'; else if (c >= 'a' && c <= 'f') n = 10 + c - 'a'; else if (c >= 'A' && c <= 'F') n = 10 + c - 'A'; - else if (strchr(":. -", c)) + else if (strchr (":. -", c)) continue; - else return false; + else + return -1; if (hit < 32) { uuid[hit / 8] <<= 4; -- cgit