From nobody Thu Nov 14 00:49:33 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XphPT61kGz5cpVh; Thu, 14 Nov 2024 00:49:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XphPT5Dsgz4tx1; Thu, 14 Nov 2024 00:49:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731545373; h=from:from: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; bh=FQ0sGkeBD2/CR8cMxZ97I03Lf01zYka02x+9LkZznxU=; b=PxW0j7ZgAnTh2J9QJH6owhz6sTJRDNZuYfT3G5RbJlogdN7YMb6a+1CPYNnKdK2rnLU99k p++dRld+HTr/cHJfskxPRm7MgmjvUoFw+Z38mdBdJu10HYaMK6hBdCzRHJbKJDBAsNxwgE +pQCde+0Cg01fgisck3oExZpoC5egxD1RDGY6A+PwlvHLTnbbC1jAb8L2tTssG5kmF5fg6 STm9L0NYR7mWBs3esixQlChjW2MTg3LcUF2NTTdVNEulmMqwZkPT92NFXYI8RzIiKmE75A +u3wqZ+1B2zhxX/uqmiyQAluT3pJjBjuKhm6gIuv3eb6UX7wVK3aRyzyS5kc6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731545373; h=from:from: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; bh=FQ0sGkeBD2/CR8cMxZ97I03Lf01zYka02x+9LkZznxU=; b=x0ostHFV3RSYlK5hwkNxz5XXT/BgDXk+RnK+Qluxtio7DiZHl3grZyWg4ddKB4c/L7UEXn avsKQZ6AqHwuB9Ch2kS822lXh0nDIHTsbh4k68bD32WQ6lJKknI2KwOedeWbRXSIz5zuAP JQIULqcQ2/WTQq4PkHRjKpTdX9pJOiEt5jYuq4WRDy8e/8zzp1GG8ujgrL/TfhrlipK6xJ JcgMXI3fMxdosrIIceNUHgMxnKpCUDiK00wqc2/qw5hzjitUlVl8EJTVliJesijAUSNm/N PgSw8WtJW2rI9C+7d56h7CNkMnjRwfq0GcHlhUd1StG+5o2/XfouHaAyeULrPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731545373; a=rsa-sha256; cv=none; b=p3oXmfK+KsymoGtd+W5BxcVFkJacaCeXLpTaCsP5xI5PHwZ7V5QZ5YKvZ7EllOu8bgwtZf Ud6dnD1Hium51iysFn8pip+W7OsrqFAp8tm1oEVfDOFPbm1/zFKM9iMoDW5FS0zRktUPmx ILJL5Nfyyv24N1HZmDsr9iB/AJrdlTZ2qzwUJtsQZZeNExzHHdoE77YQN9ykcjq3Hx1Ddn s8URoKH7XwlpzREKgCsVlRU2b0hB9DbRs8fPNM/m1TsbgclY+/WM52MZDQgFBWPrZKM+w3 wtpDzce4N55WIDh9rmq3AFKiY7e55aOjK/HdGItBrYcDD4PS1kapYAtG6Pdjhg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XphPT4jZYzGsc; Thu, 14 Nov 2024 00:49:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AE0nXSf026853; Thu, 14 Nov 2024 00:49:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AE0nXaJ026850; Thu, 14 Nov 2024 00:49:33 GMT (envelope-from git) Date: Thu, 14 Nov 2024 00:49:33 GMT Message-Id: <202411140049.4AE0nXaJ026850@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: fcd8e27dcf38 - stable/14 - style.9: be explicit about booleans in comparisons List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: fcd8e27dcf38532c4caf62f1610f389e5c9bd20c Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=fcd8e27dcf38532c4caf62f1610f389e5c9bd20c commit fcd8e27dcf38532c4caf62f1610f389e5c9bd20c Author: Ed Maste AuthorDate: 2021-05-27 15:25:32 +0000 Commit: Ed Maste CommitDate: 2024-11-14 00:49:21 +0000 style.9: be explicit about booleans in comparisons We prefer something like "if (count != 0)" over "if (count)" for non-boolean variables. This was implicit in examples, but was unclear for some new contributors. Attempt to clarify by providing a more explicit statement and example. Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30507 (cherry picked from commit 93f7a3023c3147d42dbe3dab58a5a70779587ea5) --- share/man/man9/style.9 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/share/man/man9/style.9 b/share/man/man9/style.9 index 52292b896add..75daea47ca96 100644 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -756,9 +756,10 @@ not: !(p = f()) .Ed .Pp -Do not use +Do not test without a comparison, or with unary .Ic \&! -for tests unless it is a boolean, e.g., use: +(except for booleans). +For example, use: .Bd -literal if (*p == '\e0') .Ed @@ -768,6 +769,16 @@ not: if (!*p) .Ed .Pp +Prefer: +.Bd -literal +if (count != 0) +.Ed +.Pp +over: +.Bd -literal +if (count) +.Ed +.Pp Routines returning .Vt "void *" should not have their return values cast