From 5175604b48b7dea9b60fe5f2ee440891032d522f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 21 May 2024 18:44:19 +0200 Subject: [PATCH] libuuid: construct UUIDv7 without "struct uuid" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The layout of "struct uuid" is specific to UUIDv1. Using it for UUIDv7 makes the logic complicated and confuses Coverity. Signed-off-by: Thomas Weißschuh --- libuuid/src/gen_uuid.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c index 13f6651c5..419d39da1 100644 --- a/libuuid/src/gen_uuid.c +++ b/libuuid/src/gen_uuid.c @@ -694,21 +694,20 @@ void uuid_generate_time_v6(uuid_t out) void uuid_generate_time_v7(uuid_t out) { struct timeval tv; - struct uuid uu; uint64_t ms; gettimeofday(&tv, NULL); ms = tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC; - uu.time_low = ms >> 16; - uu.time_mid = ms; - - ul_random_get_bytes(&uu.time_hi_and_version, 10); - uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | (7 << 12); - uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000; - - uuid_pack(&uu, out); + out[0] = ms >> 40; + out[1] = ms >> 32; + out[2] = ms >> 24; + out[3] = ms >> 16; + out[4] = ms >> 8; + out[5] = ms >> 0; + ul_random_get_bytes(out + 6, 10); + __uuid_set_variant_and_version(out, UUID_TYPE_DCE_TIME_V7); } -- 2.47.3