From nobody Sun Feb 8 13:53:31 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=1606489626; cv=none; d=zohomail.com; s=zohoarc; b=boDW8jDZqP38DRYM3YAJuoUPxGjDS3oba1Uf9mTJhM1pQruDHwIOvX9NV08QSnMK2mWe3iiJA5P46PW9ujuKCQ5TepHWa4/Mn20CXpKCEbdLUbMvPmlkDv50oS9kRONvIM1V+DbEJvP1XS+kxLn2RcevmefTZZRLxKS6SdZUD2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606489626; h=Content-Type:Content-Transfer-Encoding:Cc: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=OcEhXyWxKoCOwQy1te8GRYMfXAKT646kF6cYT04wFyqJ1CDwXjH/iw6iYrez1koT6rGrBhyl8hdeTqzam6KGqr4oVfTu/A9OCvZfhfRtp03k903k/iB7RrfruA/oBwMkbtR+yIwQ4VGuPdfer8rxqitf3TZkcNDn6RLnoG3zcqA= 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 1606489626905786.3257232999672; Fri, 27 Nov 2020 07:07:06 -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-568-cd-00An7NHONt6bmmJe5lg-1; Fri, 27 Nov 2020 10:07:02 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01D83D1680; Fri, 27 Nov 2020 15:06:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D42D960864; Fri, 27 Nov 2020 15:06:48 +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 A11271809CA6; Fri, 27 Nov 2020 15:06:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ARF3i8I030617 for ; Fri, 27 Nov 2020 10:03:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 331595D9CC; Fri, 27 Nov 2020 15:03:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 670475D9D5; Fri, 27 Nov 2020 15:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606489625; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=TiVcvsQyufH+U5vJe1QnMbaaqeYhYMlrN6p74ZgUqYSwoWPgO03NfHlcMtZ0O2yHp1C4Rc 5CtwshU8W15MKoCGWF6b/gP26+2QlovteOsb58FFIufvNNKKpcE3R+iI2+0Ry9gvlIw51P 2T4KgCrGjw/HQhm0wmF9DfIBnCJB9ug= X-MC-Unique: cd-00An7NHONt6bmmJe5lg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 01/26] viruuid: Rework virUUIDIsValid() Date: Fri, 27 Nov 2020 16:02:47 +0100 Message-Id: <9e7ea548a6ffc790c676258a738054f63d345480.1606489221.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: david@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.79 on 10.5.11.13 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 --- 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