From nobody Tue Nov 12 17:25:46 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 4Xntbv010Bz5cqh8; Tue, 12 Nov 2024 17:25:47 +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 4Xntbt6bPtz4mn4; Tue, 12 Nov 2024 17:25:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731432346; 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=Iz7huuoD+yiNmfZaN6uzv34OLo2vXxjgk8ITWD+LqEI=; b=vrVPjXgYpxabA7zESPAOUafbiJbNHBoE1B2LOeSaz7BXc7wh1Qy1AbElQBeVW1OrXZ3jmd gzk1CWpe6DfOG6O8ESGnTGPuA/4jamuU8SqHkKk4yZRKPsetqnSugOxLIKqzup+m0SCwTm YqdhaYRHqrMLNRnrAFAFkWGF+Dt4AhD5n2Z5sjJPtTsOdgZfrdUWDaauQ7jvYoWnGnmK/F c7OGrXEmYK7/FnXIHDPsS4jdAHRsM6c/q2spXFz40qh9q0e3x/uFWGwYeaUtJ44X8DsEq6 70sk0SPjtWVhY3vCuhJUJT+iNaUkixSgy1DHxEOX25PtCHIlSPu4vyvEPoGCbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731432346; 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=Iz7huuoD+yiNmfZaN6uzv34OLo2vXxjgk8ITWD+LqEI=; b=U9V7ZmEiXgmLbyjYTKWjqBOx2bQSAf0Qps0lHe4lJJoOxu4LL/5DfwttXugz2iRBdBdJfl MqULkNcbXHEIpXeEbZhkMMx2408dM6cR+WMguTS3JTclRCyxOo27ePTJUh63twF/8I9d6f QiZ8GEOlC3NSA/ovtvk6KsLMotf1jhjaSnzZAAuVpuFrWikdTzqzTdhKnerJiU02JSxyfB rUYfZML0AoJGYmYSa3Pf2QnKezZQmQdhoBfoCeDfHy7FXlGTQ2i5na6Z/EAMqCDJzyXD0C +DfiYmdJWLSnSythPmNh0S3InxStr8VCf2yb+GPldBqn8LlMxVkCEtsbHzCZAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731432346; a=rsa-sha256; cv=none; b=biUY4BbPzNjqokDNPdq5kwCWiuIMPbSel6uafSckXnY4HGly/9gIYAfV7FuCPPngtpMkZL ipE+hQIRJ8UPzJdzkspsJ7P1dQSzhArYD3SOar1n3DW039cEp6vp0BubYZdDxFc7cOaa9Q 1kb12CW8eIbQFq4YncJMgtsvS9/iVitnhJDUWmoJas8D3IImfoFn8xcY3ScKVOPCFFcmDk RP2UT6LWzLBWY8Potdnng/howe798pwy4Ty+juIIP0XwO311aLdwKUui00c8oKPlQafMpj /WVJ6PyCC3lcYW8VP1UbRNistJWEBbQtVOVgPfHvMwCyZC4F6NyuK8XaCOZPDw== 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 4Xntbt6BhTzKY8; Tue, 12 Nov 2024 17:25:46 +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 4ACHPkJ5033767; Tue, 12 Nov 2024 17:25:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ACHPkjP033764; Tue, 12 Nov 2024 17:25:46 GMT (envelope-from git) Date: Tue, 12 Nov 2024 17:25:46 GMT Message-Id: <202411121725.4ACHPkjP033764@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 93f7a3023c31 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 93f7a3023c3147d42dbe3dab58a5a70779587ea5 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=93f7a3023c3147d42dbe3dab58a5a70779587ea5 commit 93f7a3023c3147d42dbe3dab58a5a70779587ea5 Author: Ed Maste AuthorDate: 2021-05-27 15:25:32 +0000 Commit: Ed Maste CommitDate: 2024-11-12 17:25:28 +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 --- 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 69561e3e1e73..9bf30370a374 100644 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -746,9 +746,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 @@ -758,6 +759,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