]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: construct UUIDv6 without "struct uuid"
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 21 May 2024 16:43:36 +0000 (18:43 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 21 May 2024 16:44:17 +0000 (18:44 +0200)
The layout of "struct uuid" is specific to UUIDv1.
Using it for UUIDv6 makes the logic complicated and confuses Coverity.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libuuid/src/gen_uuid.c

index 24b4b0ddeea3c2e4febfcdbf15c820d4e1f511ae..13f6651c51a1038eca6502d962ba0279983314cc 100644 (file)
@@ -671,20 +671,23 @@ int uuid_generate_time_safe(uuid_t out)
 
 void uuid_generate_time_v6(uuid_t out)
 {
-       struct uuid uu = {};
        uint32_t clock_high, clock_low;
        uint16_t clock_seq;
 
        get_clock(&clock_high, &clock_low, &clock_seq, NULL);
 
-       uu.time_low = (clock_high << 4) | (clock_low >> 28);
-       uu.time_mid = clock_low >> 12;
-       uu.time_hi_and_version = (clock_low & 0x0FFF) | (6 << 12);
-
-       ul_random_get_bytes(&uu.clock_seq, 8);
-       uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
-
-       uuid_pack(&uu, out);
+       out[0] = clock_high >> 20;
+       out[1] = clock_high >> 12;
+       out[2] = clock_high >>  4;
+       out[3] = clock_high <<  4;
+       out[3] |= clock_low >> 28;
+       out[4] = clock_low >> 20;
+       out[5] = clock_low >> 12;
+       out[6] = clock_low >>  8;
+       out[7] = clock_low >>  0;
+
+       ul_random_get_bytes(out + 8, 8);
+       __uuid_set_variant_and_version(out, UUID_TYPE_DCE_TIME_V6);
 }
 
 // FIXME variable additional information