From nobody Tue Feb 10 04:33:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573660114; cv=none; d=zoho.com; s=zohoarc; b=kI1y3zjTS0vVoHhZzcMEe2KFgFiyDWrqgZqBmhBY46LicrQ/WyDKgM5s5YfB+ecUne3q1MxV9QaD1BrCych7Swe3EI3e5lL24mYpNofwWsifrliS6vJYuNldupX3rA0mSi2zr8tQW2tlEhkJUL/dUUVz3sgzahRfDYYgxzYwaSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573660114; 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=vHI2w4O4FfGvNtS+njdtJs7aiU+vCNaWqsDgE8MaP3Q=; b=Rzl4gUTkiccasJ3shb1bZ2QUYFjhOzhiKvzN/WoAY5GMlAy+uiFtpryISL2AytZvTk7aDBvYO66IN2RnK19lFiKBmL6FpvlEsSPPQZQ3nQAGlWEravZVkkfr8j/cUApwsEmJax263ABWQMm1x4nN4gi3eloeVfSOiKe0Te8B6dQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573660114644539.7938991985712; Wed, 13 Nov 2019 07:48:34 -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-190-0ys13gr4OIO7aaeG3uf0gA-1; Wed, 13 Nov 2019 10:48:32 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BE3B86A072; Wed, 13 Nov 2019 15:48:20 +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 0AE0410027B9; Wed, 13 Nov 2019 15:48:20 +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 BA3F44E56D; Wed, 13 Nov 2019 15:48:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xADFmFl3017706 for ; Wed, 13 Nov 2019 10:48:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 073CB10246E3; Wed, 13 Nov 2019 15:48:15 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-61.brq.redhat.com [10.40.200.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39986101E58D for ; Wed, 13 Nov 2019 15:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573660113; 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=vHI2w4O4FfGvNtS+njdtJs7aiU+vCNaWqsDgE8MaP3Q=; b=iP7o9v57572b1GMmLq8KMhTU2nxGsZRkNdYV7nBD6/Nk8d8z06y8b1Bp87I3WQ1C+bIyFP Q12JCH8DzGAt4WopSlT/fDhqtU+JvBPXbe8G5gwsn7FJppCryWPh4timDr3pL6P1HU+5/5 up6qXlW5ByE4IP/TJdrGu95qyDzB1Nw= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 13 Nov 2019 16:48:51 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/12] util: use GRegex in virStringSearch 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.22 X-MC-Unique: 0ys13gr4OIO7aaeG3uf0gA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- src/util/virstring.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index 283cf8c8d8..3da793c87a 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1017,29 +1017,27 @@ virStringSearch(const char *str, size_t max_matches, char ***matches) { - regex_t re; - regmatch_t rem; + g_autoptr(GRegex) regex =3D NULL; + g_autoptr(GError) err =3D NULL; + g_autoptr(GMatchInfo) info =3D NULL; size_t nmatches =3D 0; ssize_t ret =3D -1; - int rv =3D -1; =20 *matches =3D NULL; =20 VIR_DEBUG("search '%s' for '%s'", str, regexp); =20 - if ((rv =3D regcomp(&re, regexp, REG_EXTENDED)) !=3D 0) { - char error[100]; - regerror(rv, &re, error, sizeof(error)); + regex =3D g_regex_new(regexp, 0, 0, &err); + if (!regex) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Error while compiling regular expression '%s': %= s"), - regexp, error); + _("Failed to compile regex %s"), err->message); return -1; } =20 - if (re.re_nsub !=3D 1) { + if (g_regex_get_capture_count(regex) !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Regular expression '%s' must have exactly 1 matc= h group, not %zu"), - regexp, re.re_nsub); + _("Regular expression '%s' must have exactly 1 matc= h group, not %d"), + regexp, g_regex_get_capture_count(regex)); goto cleanup; } =20 @@ -1051,28 +1049,27 @@ virStringSearch(const char *str, =20 while ((nmatches - 1) < max_matches) { char *match; + int endpos; =20 - if (regexec(&re, str, 1, &rem, 0) !=3D 0) + if (!g_regex_match(regex, str, 0, &info)) break; =20 if (VIR_EXPAND_N(*matches, nmatches, 1) < 0) goto cleanup; =20 - if (VIR_STRNDUP(match, str + rem.rm_so, - rem.rm_eo - rem.rm_so) < 0) - goto cleanup; + match =3D g_match_info_fetch(info, 1); =20 VIR_DEBUG("Got '%s'", match); =20 (*matches)[nmatches-2] =3D match; =20 - str =3D str + rem.rm_eo; + g_match_info_fetch_pos(info, 1, NULL, &endpos); + str +=3D endpos; } =20 ret =3D nmatches - 1; /* don't count the trailing null */ =20 cleanup: - regfree(&re); if (ret < 0) { virStringListFree(*matches); *matches =3D NULL; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list