From nobody Mon Jun 26 16:30:42 2023 X-Original-To: dev-commits-src-branches@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 4QqYHQ65Ylz4kZmv; Mon, 26 Jun 2023 16:30:42 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QqYHQ46pkz46Hf; Mon, 26 Jun 2023 16:30:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687797042; 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=wpXEJ4kedeHIG2jVhNW61OgwSyPT+IaLlbl0WkEM66o=; b=vQ2mGJWldpmLTSWtpB7CLNqsxnhtZ/sdWQ8sEYaMS0Z6ocmFls5UKk3ecYY6+ZtKmsdeZs LlN2yDv3iGhnYopx7AX6rAfshmZSTHmvf/kv0g2cKx+ZHTp7TW1yIdk6emqfbTYI5+K0Pf m9YPTIvss4XHGvIKb8kMAJ3OaAjb8VYFKPaA8RuVejqr75KaKehayBKGvjURjY9zvtOeZc Mjt+2jWu8FViDRC7AlUtsM/XT5etIqTxcSmJp/AS01Mwn0YMaxBMuOiAJeC0wEZWuCNvhU yTLMb9MmD5NoV4KWgVA89OF9Cw9I/TdzTpY4cevOWmMEChuomNu/+dkoG3odxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687797042; 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=wpXEJ4kedeHIG2jVhNW61OgwSyPT+IaLlbl0WkEM66o=; b=iTsuMjGGiz9dKXBaMPF+Zdzj+fYSUCMZ+zabjkxhZ2dgAlHvhO7kPYA+UHuBr3kpRsvnnm F9kbv1ZNn7IITeMj0UPMNoxYxC+xHSH0/dwmPagCzITKvBRnr7mRFmpN1s9OuHtLtz1fPL rSkLJ4h+uodcVEIvrsHP1L8fgCsSpI1MdBbUJLlwH5rP4ohe4T0iPnXcYWP5rjndiOZcD0 46wCyC+h5yzK4sIwHpxLrtcxB1JQ/DWiz9n7lBYrVcX7QL0ESmcKnF/c6F2kgOHxVm60LM hDZHwxldRW3WiBa0IV6yt6HK8geMjBTqwKC4DARNKFJeXhBfxFbm6R26l5j5QQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687797042; a=rsa-sha256; cv=none; b=NStI1A0ClukdWNURGHwn7JSQv0M2f5SvTeZE1yGObE/oL6gESO6s8IWHGXLJ6+2qeuv+OB S4RGNfiQr8O4KBjIHNVEz6CC3NnSgX96qrqRPVAxiWsTH7AgY4UEOwFsj2qDjIoRL9pLAN G6ERDuRwN02HYkkien10/hhhijWnyek46AxzfRayeWI3RJYmDHygc2cC3wqhaXFLoXjgLa QxnkK/tG624HEBeAQK9DARyUn4wgiRzcb6ahiqXp0zjmo37dj7Rt7eHNRIFc8662U72ZL8 ytwCTR1YZ0sUHcbve7FE3fB7dFw3U3LG1yfrGEehXM/GpdipBj5WxxDe3AmDQg== 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 4QqYHQ2FbQzGmp; Mon, 26 Jun 2023 16:30:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35QGUgkk025543; Mon, 26 Jun 2023 16:30:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35QGUgGJ025542; Mon, 26 Jun 2023 16:30:42 GMT (envelope-from git) Date: Mon, 26 Jun 2023 16:30:42 GMT Message-Id: <202306261630.35QGUgGJ025542@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: 70af4d57c18f - stable/13 - seq: fix check for rounding error/truncation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 70af4d57c18fbcb46e3d7d7501cad756f812bed3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=70af4d57c18fbcb46e3d7d7501cad756f812bed3 commit 70af4d57c18fbcb46e3d7d7501cad756f812bed3 Author: Ed Maste AuthorDate: 2023-06-19 01:37:06 +0000 Commit: Ed Maste CommitDate: 2023-06-26 16:30:31 +0000 seq: fix check for rounding error/truncation Based on OpenBSD 30f0fd29ba6c: > We need to compare the printable version of the last value displayed, > not the floating point representation. Otherwise, we may print the > last value twice. PR: 271964 Reported by: Daniel Kolesa Reviewed by: yuripv Obtained from: OpenBSD Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40601 (cherry picked from commit e54db9a9ccd588f650a2e57bf9d1cbbafc0e12eb) --- usr.bin/seq/seq.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c index 823e8c2c4da0..50c6b6022967 100644 --- a/usr.bin/seq/seq.c +++ b/usr.bin/seq/seq.c @@ -88,14 +88,14 @@ main(int argc, char *argv[]) { const char *sep, *term; struct lconv *locale; - char pad, *fmt, *cur_print, *last_print; - double first, last, incr, last_shown_value, cur, step; + char pad, *fmt, *cur_print, *last_print, *prev_print; + double first, last, incr, prev, cur, step; int c, errflg, equalize; pad = ZERO; fmt = NULL; first = 1.0; - last = incr = last_shown_value = 0.0; + last = incr = prev = 0.0; c = errflg = equalize = 0; sep = "\n"; term = NULL; @@ -186,7 +186,7 @@ main(int argc, char *argv[]) cur = first + incr * step++) { printf(fmt, cur); fputs(sep, stdout); - last_shown_value = cur; + prev = cur; } /* @@ -194,10 +194,9 @@ main(int argc, char *argv[]) * * We might have, so check if the printable version of the last * computed value ('cur') and desired 'last' value are equal. If they - * are equal after formatting truncation, but 'cur' and - * 'last_shown_value' are not equal, it means the exit condition of the - * loop held true due to a rounding error and we still need to print - * 'last'. + * are equal after formatting truncation, but 'cur' and 'prev' are not + * equal, it means the exit condition of the loop held true due to a + * rounding error and we still need to print 'last'. */ if (asprintf(&cur_print, fmt, cur) < 0) { err(1, "asprintf"); @@ -205,12 +204,17 @@ main(int argc, char *argv[]) if (asprintf(&last_print, fmt, last) < 0) { err(1, "asprintf"); } - if (strcmp(cur_print, last_print) == 0 && cur != last_shown_value) { + if (asprintf(&prev_print, fmt, prev) < 0) { + err(1, "asprintf"); + } + if (strcmp(cur_print, last_print) == 0 && + strcmp(cur_print, prev_print) != 0) { fputs(last_print, stdout); fputs(sep, stdout); } free(cur_print); free(last_print); + free(prev_print); if (term != NULL) fputs(term, stdout);