From nobody Mon Feb 9 13:00:14 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=1612179005; cv=none; d=zohomail.com; s=zohoarc; b=gFu3p2ymai+1vI/Tv/IUSCiSuehom2uH7fSj5aZE5gklfCjKL7MWWYdloTsFBybXqE+FvF56XOuusZLUeEsKoqDeHSPTfjn2VU/eARKxya0ed3T782O4R+eGU7k1h1m1tBFWEuPjsv0cm1o/yrDnAbN8nYTSd8WMilUzgxno/lI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179005; 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=DtXBUQX78KIbc27ojQphowYybabC1Tb1xbEck6yD7+A=; b=oHMY+7fnJPbS8ZqSybPGxAbUP2enrPjKwiRhhT0/FTvHW/QvNkCkGUS9iEmSNKQZXDHUt3dgOn/3zE8vYqe2xmzW2I+ecJD0bm132bQ1qzA/b8lPlJREeNsCnu1M6omFSXfPO+pGsR61djOi4nVKtFiyp7+5R5Cbr0OFAr74zhk= 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 1612179005601712.9082274282952; Mon, 1 Feb 2021 03:30:05 -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-595-FwdKH4eKOIq5iLy6-Oxo1A-1; Mon, 01 Feb 2021 06:28:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15CC780400F; Mon, 1 Feb 2021 11:28:41 +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 E8BD45DA2E; Mon, 1 Feb 2021 11:28:40 +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 6130750038; Mon, 1 Feb 2021 11:28:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSD0I003258 for ; Mon, 1 Feb 2021 06:28:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 475862C313; Mon, 1 Feb 2021 11:28:13 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B3DD1840B; Mon, 1 Feb 2021 11:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179004; 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=DtXBUQX78KIbc27ojQphowYybabC1Tb1xbEck6yD7+A=; b=HsDfonTftiVeRAchVMU/6gtizOTpklsCfMeXMqQHC1+T4rnGRec2PVvNDglNjzaVtcK0Zo qb9OsJ0sFiT4fASBxVKNgfL3mXzTF6MRzGLbtXVNO13WRPlJRofZBqHcwZyHkkKY5c6PLs KQXMkZvSObQ2gUNtjeN1PLEqcJtzWgk= X-MC-Unique: FwdKH4eKOIq5iLy6-Oxo1A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/20] commandhelper: Simplify envsort Date: Mon, 1 Feb 2021 12:27:47 +0100 Message-Id: <20210201112804.144366-4-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.14 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" This saves two invocations of each `strndup` and `free`. Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 2b937979c0..22835302b8 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -37,24 +37,19 @@ extern char **environ; =20 static int envsort(const void *a, const void *b) { - const char *const*astrptr =3D a; - const char *const*bstrptr =3D b; - const char *astr =3D *astrptr; - const char *bstr =3D *bstrptr; - char *aeq =3D strchr(astr, '=3D'); - char *beq =3D strchr(bstr, '=3D'); - char *akey; - char *bkey; - int ret; - - if (!(akey =3D strndup(astr, aeq - astr))) - abort(); - if (!(bkey =3D strndup(bstr, beq - bstr))) - abort(); - ret =3D strcmp(akey, bkey); - free(akey); - free(bkey); - return ret; + const char *astr =3D *(const char**)a; + const char *bstr =3D *(const char**)b; + + while (true) { + char achar =3D (*astr =3D=3D '=3D') ? '\0' : *astr; + char bchar =3D (*bstr =3D=3D '=3D') ? '\0' : *bstr; + + if ((achar =3D=3D '\0') || (achar !=3D bchar)) + return achar - bchar; + + astr++; + bstr++; + } } =20 int main(int argc, char **argv) { --=20 2.26.2