From nobody Sat May 30 17:43:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1780039753; cv=none; d=zohomail.com; s=zohoarc; b=PXVGIUnHby4dUU/WmICOXj3j7Qrew9B+rzu7tjRLz5TtCr5HZSb7/BktyGuARYadT9fXSmbz6XUcwjMdDs1riFH6P0NsLTuvfvfxaHRP+ChxF9a7jnGc+B4JJO59pXbCdp8mtx0aEq+hB+T5SUzZ4KicKpxiBMUlG80lsve0Ghk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780039753; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZqdxVbZW6CeWlAgMhY3W1SPLXqzeacXw4q7zWAMzo7I=; b=fJpKW8tcdy5i/JyXEgrXmOpFyawyFYT62GuER+/J7Mjsa60rLG2zKHDOTGOWegns0k1FAb+gbmpy+kamR/jO7jXPJIQkgw+gUXE9Y/v6rnS25v3Dh4d2VE466vS1nyZeAyYsihGMLCCWA09NkGEk5+RMkLgabzDcj1uRJVZ5/PQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178003975345833.62682059592839; Fri, 29 May 2026 00:29:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSrdy-00065h-7X; Fri, 29 May 2026 03:28:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSrdu-00065E-Po for qemu-devel@nongnu.org; Fri, 29 May 2026 03:28:30 -0400 Received: from [115.124.30.124] (helo=out30-124.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSrdq-0006No-Bj for qemu-devel@nongnu.org; Fri, 29 May 2026 03:28:30 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X3oeNs-_1780039684 cluster:ay36) by smtp.aliyun-inc.com; Fri, 29 May 2026 15:28:05 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1780039686; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=ZqdxVbZW6CeWlAgMhY3W1SPLXqzeacXw4q7zWAMzo7I=; b=vvLqsKX0k2DGb6KgC0v8gp73GmItoVbul8H31Ii1lmYJj2dV3G3DiTOqTbDQBSJKvwkqjoMBeO7jhehFlWP8/G77scshdAWXt2rz4M1VwF/mnsks9fGsX2HY2ipXkL0nvQ4HhyoMUvF8Dp8nJoQdV+AIf3sSiek8WxySXj2sezg= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R171e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037033178; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=7; SR=0; TI=SMTPD_---0X3oeNs-_1780039684; From: Bin Guo To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, kevans@freebsd.org, laurent@vivier.eu, deller@gmx.de, pierrick.bouvier@oss.qualcomm.com, philmd@linaro.org Subject: [PATCH] util/cutils: drop qemu_strnlen() in favor of strnlen() Date: Fri, 29 May 2026 15:28:03 +0800 Message-ID: <20260529072803.99475-1-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.124 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.124; envelope-from=guobin@linux.alibaba.com; helo=out30-124.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1780039756204154100 There are only three call sites, and strnlen() is available on all supported platforms (POSIX.1-2008, Windows via UCRT, MinGW). Remove the hand-rolled wrapper and use the standard function directly. While here, align bsd-user/uaccess.c to use size_t for max_len/len, matching linux-user/uaccess.c and eliminating a signed/unsigned mismatch. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Bin Guo Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- bsd-user/uaccess.c | 4 ++-- include/qemu/cutils.h | 16 ---------------- linux-user/uaccess.c | 2 +- util/cutils.c | 15 +-------------- 4 files changed, 4 insertions(+), 33 deletions(-) diff --git a/bsd-user/uaccess.c b/bsd-user/uaccess.c index 89163257f4..7ad4b580f4 100644 --- a/bsd-user/uaccess.c +++ b/bsd-user/uaccess.c @@ -43,7 +43,7 @@ abi_long target_strlen(abi_ulong guest_addr1) { uint8_t *ptr; abi_ulong guest_addr; - int max_len, len; + size_t max_len, len; =20 guest_addr =3D guest_addr1; for (;;) { @@ -51,7 +51,7 @@ abi_long target_strlen(abi_ulong guest_addr1) ptr =3D lock_user(VERIFY_READ, guest_addr, max_len, 1); if (!ptr) return -TARGET_EFAULT; - len =3D qemu_strnlen((const char *)ptr, max_len); + len =3D strnlen((const char *)ptr, max_len); unlock_user(ptr, guest_addr, 0); guest_addr +=3D len; /* we don't allow wrapping or integer overflow */ diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 36c68ce86c..025b7f24dd 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -101,22 +101,6 @@ int strstart(const char *str, const char *val, const c= har **ptr); * false otherwise. */ int stristart(const char *str, const char *val, const char **ptr); -/** - * qemu_strnlen: - * @s: string - * @max_len: maximum number of bytes in @s to scan - * - * Return the length of the string @s, like strlen(), but do not - * examine more than @max_len bytes of the memory pointed to by @s. - * If no NUL terminator is found within @max_len bytes, then return - * @max_len instead. - * - * This function has the same behaviour as the POSIX strnlen() - * function. - * - * Returns: length of @s in bytes, or @max_len, whichever is smaller. - */ -int qemu_strnlen(const char *s, int max_len); /** * qemu_strsep: * @input: pointer to string to parse diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c index 27e841e651..f9bd713edd 100644 --- a/linux-user/uaccess.c +++ b/linux-user/uaccess.c @@ -99,7 +99,7 @@ ssize_t target_strlen(abi_ulong guest_addr1) ptr =3D lock_user(VERIFY_READ, guest_addr, max_len, 1); if (!ptr) return -TARGET_EFAULT; - len =3D qemu_strnlen((const char *)ptr, max_len); + len =3D strnlen((const char *)ptr, max_len); unlock_user(ptr, guest_addr, 0); guest_addr +=3D len; /* we don't allow wrapping or integer overflow */ diff --git a/util/cutils.c b/util/cutils.c index 76a9442085..a89213966e 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -54,7 +54,7 @@ =20 void strpadcpy(char *buf, int buf_size, const char *str, char pad) { - int len =3D qemu_strnlen(str, buf_size); + int len =3D strnlen(str, buf_size); memcpy(buf, str, len); memset(buf + len, pad, buf_size - len); } @@ -118,19 +118,6 @@ int stristart(const char *str, const char *val, const = char **ptr) return 1; } =20 -/* XXX: use host strnlen if available ? */ -int qemu_strnlen(const char *s, int max_len) -{ - int i; - - for(i =3D 0; i < max_len; i++) { - if (s[i] =3D=3D '\0') { - break; - } - } - return i; -} - char *qemu_strsep(char **input, const char *delim) { char *result =3D *input; --=20 2.50.1 (Apple Git-155)