From nobody Mon Feb 9 03:47:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999095; cv=none; d=zohomail.com; s=zohoarc; b=aL7yR8y/3qYEirWtcjGaUQqiGeSBTcC2FVtLcGUaAVWHGrD23h53ySOBpsvZiS+okLC3YxM/rVEL+pxMvKZ0v2EbOO9GyRP6jJnr3mJ1espT3sflUF5326UG5xxhjgbCQoUrrBZpqCSJWG+X8WJlYM1i2ZebO5wSl7bszvYQmDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999095; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dBLJ6IJAkS3SLaj90xrFLg8r38ICJZPEKlRJoHIGpFg=; b=m6SM16QEw9DDb/W+mZ9+FvLsMkAHmgKxpukElZPm9YPhBkma4y9z+aY1dSp0tRQAehOgtMZJCkOvZH4f+wn45B4iW5wXy83E9WVYift0TPA2w2jV9QqhNbRR7P9uVXgKx0XVdBy6mOhDiX3BLDWcqLzMavaWAbuDG8bkypwj4S8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999095401777.1484358726216; Thu, 3 Dec 2020 04:38:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-505-K-uxZiT6OjmWEpDf_a3STQ-1; Thu, 03 Dec 2020 07:37:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CA2F185E4A3; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76A731A839; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0B48F4E58F; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Caeoo002875 for ; Thu, 3 Dec 2020 07:36:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2BB3F5C1BD; Thu, 3 Dec 2020 12:36:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id A19E35C1B4 for ; Thu, 3 Dec 2020 12:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999094; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dBLJ6IJAkS3SLaj90xrFLg8r38ICJZPEKlRJoHIGpFg=; b=fPd4mqrnvHx+4enXUz8NQM1dtWVg5qfZ8Xs6ld/tJVCKKlKoiA2zhQp40FbQz8DXBqLxL4 RjNbGhHl/lvWlOavOfJJ6paNaG0/Xr7mdt1/iYLDZPIU0Ro3fCD9urjdhE9G1t2VKgHHpq 1q9WiGjxYy0rzj2MwBgQwS1LmXoQKJk= X-MC-Unique: K-uxZiT6OjmWEpDf_a3STQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 01/27] viruuid: Rework virUUIDIsValid() Date: Thu, 3 Dec 2020 13:36:04 +0100 Message-Id: <7b27afef80ace93d07c9eb1f7951d9eb3288e18f.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Peter Krempa --- src/util/viruuid.c | 17 +++++++---------- src/util/viruuid.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/util/viruuid.c b/src/util/viruuid.c index 908b09945d..558fbb9c0d 100644 --- a/src/util/viruuid.c +++ b/src/util/viruuid.c @@ -170,25 +170,22 @@ virUUIDFormat(const unsigned char *uuid, char *uuidst= r) * 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 =3D 1; - unsigned char c; =20 if (!uuid) - return 0; - - c =3D uuid[0]; + return false; =20 for (i =3D 1; i < VIR_UUID_BUFLEN; i++) - if (uuid[i] =3D=3D c) - ctr++; + if (uuid[i] !=3D uuid[0]) + return true; =20 - return ctr !=3D VIR_UUID_BUFLEN; + return false; } =20 + static int getDMISystemUUID(char *uuid, int len) { diff --git a/src/util/viruuid.h b/src/util/viruuid.h index 5d64e58405..b403b1906a 100644 --- a/src/util/viruuid.h +++ b/src/util/viruuid.h @@ -43,7 +43,7 @@ int virSetHostUUIDStr(const char *host_uuid); int virGetHostUUID(unsigned char *host_uuid) ATTRIBUTE_NONNULL(1) G_GNUC_N= O_INLINE; =20 -int virUUIDIsValid(unsigned char *uuid); +bool virUUIDIsValid(const unsigned char *uuid); =20 int virUUIDGenerate(unsigned char *uuid) G_GNUC_NO_INLINE; =20 --=20 2.26.2