diff mbox series

lib: uuid: fix 32-bit support

Message ID 20241030003317.2901772-2-caleb.connolly@linaro.org
State New
Headers show
Series lib: uuid: fix 32-bit support | expand

Commit Message

Caleb Connolly Oct. 30, 2024, 12:32 a.m. UTC
In 22c48a92cdce (lib: uuid: supporting building as part of host tools),
some instances of simple_strtoull() were accidentally replaced with
strtoul() instead (spot the difference!).

To keep compatibility with building as part of host tools, re-implement
this via a new hextoull macro to handle both cases.

Fixes: 22c48a92cdce (lib: uuid: supporting building as part of host tools)
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
Reported-by: Patrick DELAUNAY <patrick.delaunay@foss.st.com>
---
I've build-tested this but don't have the hardware set up to easily test.
---
 lib/uuid.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Tom Rini Oct. 30, 2024, 1:14 a.m. UTC | #1
On Wed, Oct 30, 2024 at 01:32:55AM +0100, Caleb Connolly wrote:
> In 22c48a92cdce (lib: uuid: supporting building as part of host tools),
> some instances of simple_strtoull() were accidentally replaced with
> strtoul() instead (spot the difference!).
> 
> To keep compatibility with building as part of host tools, re-implement
> this via a new hextoull macro to handle both cases.
> 
> Fixes: 22c48a92cdce (lib: uuid: supporting building as part of host tools)
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> Reported-by: Patrick DELAUNAY <patrick.delaunay@foss.st.com>
> ---
> I've build-tested this but don't have the hardware set up to easily test.
> ---
>  lib/uuid.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Close, but not quite:
=================================== FAILURES ===================================
____________________ test_ut[ut_lib_lib_test_dynamic_uuid] _____________________
test/py/tests/test_ut.py:592: in test_ut
    assert output.endswith('Failures: 0')
E   assert False
E    +  where False = <built-in method endswith of str object at 0x7fd53ca39e30>('Failures: 0')
E    +    where <built-in method endswith of str object at 0x7fd53ca39e30> = 'Test: lib_test_dynamic_uuid: uuid.c\r\ntest/lib/uuid.c:114, lib_test_dynamic_uuid_case(): expected_uuid = uuid_str: E...-8e063312964b", got "92a09169-9f8a-5f94-8635-0d9c2e830a92"\r\nTest lib_test_dynamic_uuid failed 1 times\r\nFailures: 1'.endswith
----------------------------- Captured stdout call -----------------------------
U-Boot> ut lib lib_test_dynamic_uuid
Test: lib_test_dynamic_uuid: uuid.c
test/lib/uuid.c:114, lib_test_dynamic_uuid_case(): expected_uuid = uuid_str: Expected "985f2937-7c2e-5e9a-8a5e-8e063312964b", got "92a09169-9f8a-5f94-8635-0d9c2e830a92"
Test lib_test_dynamic_uuid failed 1 times
Failures: 1
U-Boot>
diff mbox series

Patch

diff --git a/lib/uuid.c b/lib/uuid.c
index c6a27b7d044d..59f07a9a5834 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -34,8 +34,11 @@ 
 
 #ifdef USE_HOSTCC
 /* polyfill hextoul to avoid pulling in strto.c */
 #define hextoul(cp, endp) strtoul(cp, endp, 16)
+#define hextoull(cp, endp) strtoull(cp, endp, 16)
+#else
+#define hextoull(cp, endp) simple_strtoull(cp, endp, 16)
 #endif
 
 int uuid_str_valid(const char *uuid)
 {
@@ -289,9 +292,9 @@  int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
 		return -EINVAL;
 	}
 
 	if (str_format == UUID_STR_FORMAT_STD) {
-		tmp32 = cpu_to_be32(hextoul(uuid_str, NULL));
+		tmp32 = cpu_to_be32(hextoull(uuid_str, NULL));
 		memcpy(uuid_bin, &tmp32, 4);
 
 		tmp16 = cpu_to_be16(hextoul(uuid_str + 9, NULL));
 		memcpy(uuid_bin + 4, &tmp16, 2);
@@ -326,9 +329,9 @@  int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin)
 
 	if (!uuid_str_valid(uuid_str) || !uuid_bin)
 		return -EINVAL;
 
-	tmp32 = cpu_to_le32(hextoul(uuid_str, NULL));
+	tmp32 = cpu_to_le32(hextoull(uuid_str, NULL));
 	memcpy(uuid_bin, &tmp32, 4);
 
 	tmp16 = cpu_to_le16(hextoul(uuid_str + 9, NULL));
 	memcpy(uuid_bin + 4, &tmp16, 2);