From bb5b2ed9b340192e75ca473a8e3e302b112f0ba1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 6 Jun 2023 11:40:03 +0200 Subject: Sync uuid code with libstud-uuid --- libbutl/uuid.cxx | 23 ++++++++++++----------- libbutl/uuid.hxx | 16 ++++++++-------- 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'libbutl') diff --git a/libbutl/uuid.cxx b/libbutl/uuid.cxx index 377afb7..2132808 100644 --- a/libbutl/uuid.cxx +++ b/libbutl/uuid.cxx @@ -5,7 +5,7 @@ #include // ENOTSUP -#include // sprintf() scanf() +#include // snprintf() sscanf() #include // strlen() #include #include @@ -19,16 +19,17 @@ namespace butl { array r; - sprintf (r.data (), - (upper - ? "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X" - : "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), - time_low, - time_mid, - time_hiv, - clock_seq_hir, - clock_seq_low, - node[0], node[1], node[2], node[3], node[4], node[5]); + snprintf (r.data (), + 37, + (upper + ? "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X" + : "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), + time_low, + time_mid, + time_hiv, + clock_seq_hir, + clock_seq_low, + node[0], node[1], node[2], node[3], node[4], node[5]); return r; } diff --git a/libbutl/uuid.hxx b/libbutl/uuid.hxx index 47a814c..862f02d 100644 --- a/libbutl/uuid.hxx +++ b/libbutl/uuid.hxx @@ -48,12 +48,12 @@ namespace butl { // Normally not accessed directly (see RFC4122 Section 4.1.2). // - std::uint32_t time_low = 0; - std::uint16_t time_mid = 0; - std::uint16_t time_hiv = 0; // hi_and_version - std::uint8_t clock_seq_hir = 0; // hi_and_reserved - std::uint8_t clock_seq_low = 0; - std::uint8_t node[6] = {0, 0, 0, 0, 0, 0}; + std::uint32_t time_low = 0; + std::uint16_t time_mid = 0; + std::uint16_t time_hiv = 0; // hi_and_version + std::uint8_t clock_seq_hir = 0; // hi_and_reserved + std::uint8_t clock_seq_low = 0; + std::uint8_t node[6] = {0, 0, 0, 0, 0, 0}; // System UUID generator. See the uuid_generator interface for details. // @@ -183,7 +183,7 @@ namespace butl ~uuid_generator () = default; // Generate a UUID. If strong is true (default), generate a strongly- - // unique UUID. Throw std::runtime_error to report errors, including if + // unique UUID. Throw std::system_error to report errors, including if // strong uniqueness cannot be guaranteed. // // A weak UUID is not guaranteed to be unique, neither universialy nor @@ -207,7 +207,7 @@ namespace butl // Optional explicit initialization and termination. Note that it is not // thread-safe and must only be performed once (normally from main()) // before/after any calls to generate(), respectively. Both functions may - // throw std::runtime_error to report errors. + // throw std::system_error to report errors. // static void initialize (); -- cgit v1.1