Cleanup: clang-tidy warnings in UUID code
Use C++ version of C headers, and avoid static function call on instance. No functional changes.
This commit is contained in:
@@ -20,8 +20,9 @@
|
||||
|
||||
#include "BLI_uuid.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <random>
|
||||
#include <string.h>
|
||||
|
||||
/* Ensure the UUID struct doesn't have any padding, to be compatible with memcmp(). */
|
||||
static_assert(sizeof(UUID) == 16, "expect UUIDs to be 128 bit exactly");
|
||||
@@ -32,8 +33,8 @@ UUID BLI_uuid_generate_random()
|
||||
std::mt19937_64 rng;
|
||||
|
||||
/* Ensure the RNG really can output 64-bit values. */
|
||||
static_assert(rng.min() == 0LL);
|
||||
static_assert(rng.max() == 0xffffffffffffffffLL);
|
||||
static_assert(std::mt19937_64::min() == 0LL);
|
||||
static_assert(std::mt19937_64::max() == 0xffffffffffffffffLL);
|
||||
|
||||
struct timespec ts;
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
@@ -65,41 +66,42 @@ UUID BLI_uuid_generate_random()
|
||||
|
||||
bool BLI_uuid_equal(const UUID uuid1, const UUID uuid2)
|
||||
{
|
||||
return memcmp(&uuid1, &uuid2, sizeof(uuid1)) == 0;
|
||||
return std::memcmp(&uuid1, &uuid2, sizeof(uuid1)) == 0;
|
||||
}
|
||||
|
||||
void BLI_uuid_format(char *buffer, const UUID uuid)
|
||||
{
|
||||
sprintf(buffer,
|
||||
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
uuid.time_low,
|
||||
uuid.time_mid,
|
||||
uuid.time_hi_and_version,
|
||||
uuid.clock_seq_hi_and_reserved,
|
||||
uuid.clock_seq_low,
|
||||
uuid.node[0],
|
||||
uuid.node[1],
|
||||
uuid.node[2],
|
||||
uuid.node[3],
|
||||
uuid.node[4],
|
||||
uuid.node[5]);
|
||||
std::sprintf(buffer,
|
||||
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
uuid.time_low,
|
||||
uuid.time_mid,
|
||||
uuid.time_hi_and_version,
|
||||
uuid.clock_seq_hi_and_reserved,
|
||||
uuid.clock_seq_low,
|
||||
uuid.node[0],
|
||||
uuid.node[1],
|
||||
uuid.node[2],
|
||||
uuid.node[3],
|
||||
uuid.node[4],
|
||||
uuid.node[5]);
|
||||
}
|
||||
|
||||
bool BLI_uuid_parse_string(UUID *uuid, const char *buffer)
|
||||
{
|
||||
const int num_fields_parsed = sscanf(buffer,
|
||||
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||
&uuid->time_low,
|
||||
&uuid->time_mid,
|
||||
&uuid->time_hi_and_version,
|
||||
&uuid->clock_seq_hi_and_reserved,
|
||||
&uuid->clock_seq_low,
|
||||
&uuid->node[0],
|
||||
&uuid->node[1],
|
||||
&uuid->node[2],
|
||||
&uuid->node[3],
|
||||
&uuid->node[4],
|
||||
&uuid->node[5]);
|
||||
const int num_fields_parsed = std::sscanf(
|
||||
buffer,
|
||||
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||
&uuid->time_low,
|
||||
&uuid->time_mid,
|
||||
&uuid->time_hi_and_version,
|
||||
&uuid->clock_seq_hi_and_reserved,
|
||||
&uuid->clock_seq_low,
|
||||
&uuid->node[0],
|
||||
&uuid->node[1],
|
||||
&uuid->node[2],
|
||||
&uuid->node[3],
|
||||
&uuid->node[4],
|
||||
&uuid->node[5]);
|
||||
return num_fields_parsed == 11;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user