1 Star 0 Fork 72

nicholastao/coreutils

forked from src-openEuler/coreutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-pr-fix-infinite-loop-when-double-spacing.patch 2.17 KB
一键复制 编辑 原始数据 按行查看 历史
const 提交于 2023-07-07 05:23 . coreutils: update to 9.3
From 3fb0cc80fa5e1cede9ec05303a70c26d0d23ca1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Tue, 25 Apr 2023 14:07:03 +0100
Subject: [PATCH] pr: fix infinite loop when double spacing
* src/pr.c (init_parameters): Ensure we avoid a 0 lines_per_body
which was possible when adjusting for double spacing.
That caused print_page() to always return true,
causing an infinite loop.
* tests/pr/pr-tests.pl: Add a test case.
* NEWS: Mention the fix.
Fixes https://bugs.debian.org/1034808
Conflict:NEWS context adaption
Reference:https://github.com/coreutils/coreutils/commit/3fb0cc80fa5e1cede9ec05303a70c26d0d23ca1d
---
NEWS | 3 +++
src/pr.c | 2 +-
tests/pr/pr-tests.pl | 3 +++
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index f65eb95..5320b9c 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 9.3 (2023-04-18) [stable]
** Bug fixes
+
+ 'pr --length=1 --double-space' no longer enters an infinite loop.
+ [This bug was present in "the beginning".]
cp --reflink=auto (the default), mv, and install
will again fall back to a standard copy in more cases.
Previously copies could fail with permission errors on
diff --git a/src/pr.c b/src/pr.c
index 2c5cdceb1..14a368b6c 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -1209,7 +1209,7 @@ init_parameters (int number_of_files)
lines_per_body = lines_per_page;
if (double_space)
- lines_per_body = lines_per_body / 2;
+ lines_per_body = MAX (1, lines_per_body / 2);
/* If input is stdin, cannot print parallel files. BSD dumps core
on this. */
diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl
index 265e6e108..eafc13d81 100755
--- a/tests/pr/pr-tests.pl
+++ b/tests/pr/pr-tests.pl
@@ -415,6 +415,9 @@ my @tv = (
['padding2', '-t -n,64', "1\n", (" "x 63)."1,1\n", 0],
# Ensure we handle buffer truncation correctly
['padding3', '-t -N1000000 -n,1', "1\n", "0,1\n", 0],
+
+# This entered an infinite loop before coreutils-9.4
+['page-length1', '-dl1', "", "", 0],
);
# Convert the above old-style test vectors to the newer
--
2.36.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nicholastao/coreutils.git
git@gitee.com:nicholastao/coreutils.git
nicholastao
coreutils
coreutils
master

搜索帮助