mirror of https://gitee.com/openkylin/libvirt.git
viruuid: Rework virUUIDIsValid()
The only test we do when checking for UUID validity is that whether all bytes are the same (invalid UUID) or not (valid UUID). The algorithm we use is needlessly complicated. Also, the checked UUID is not modified and hence the argument can be of 'const' type. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com> Tested-by: Han Han <hhan@redhat.com>
This commit is contained in:
parent
abf12f071b
commit
32217bb709
|
@ -170,25 +170,22 @@ virUUIDFormat(const unsigned char *uuid, char *uuidstr)
|
|||
* Basic tests:
|
||||
* - Not all of the digits may be equal
|
||||
*/
|
||||
int
|
||||
virUUIDIsValid(unsigned char *uuid)
|
||||
bool
|
||||
virUUIDIsValid(const unsigned char *uuid)
|
||||
{
|
||||
size_t i;
|
||||
unsigned int ctr = 1;
|
||||
unsigned char c;
|
||||
|
||||
if (!uuid)
|
||||
return 0;
|
||||
|
||||
c = uuid[0];
|
||||
return false;
|
||||
|
||||
for (i = 1; i < VIR_UUID_BUFLEN; i++)
|
||||
if (uuid[i] == c)
|
||||
ctr++;
|
||||
if (uuid[i] != uuid[0])
|
||||
return true;
|
||||
|
||||
return ctr != VIR_UUID_BUFLEN;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
getDMISystemUUID(char *uuid, int len)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
int virSetHostUUIDStr(const char *host_uuid);
|
||||
int virGetHostUUID(unsigned char *host_uuid) ATTRIBUTE_NONNULL(1) G_GNUC_NO_INLINE;
|
||||
|
||||
int virUUIDIsValid(unsigned char *uuid);
|
||||
bool virUUIDIsValid(const unsigned char *uuid);
|
||||
|
||||
int virUUIDGenerate(unsigned char *uuid) G_GNUC_NO_INLINE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue