1 Star 0 Fork 71

wuzx/coreutils

forked from src-openEuler/coreutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-sort-fix-sort-g-infloop-again.patch 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
邹林 提交于 2022-08-27 18:01 . fix 'sort -g' don't meet expectations
From 2f56f5a42033dc6db15d8963e54566f01fa0d61d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sun, 1 May 2022 22:46:21 -0700
Subject: [PATCH] sort: fix sort -g infloop again
Problem reported by Giulio Genovese (Bug#55212).
* src/sort.c (nan_compare): To compare NaNs, simply printf+strcmp.
This avoids the problem of padding bits and unspecified behavior.
Args are now long double instead of char *; caller changed.
---
src/sort.c | 21 ++++++---------------
1 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/src/sort.c b/src/sort.c
index 3b775d6bb..b2a465cf5 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2359,22 +2359,13 @@ numcompare (char const *a, char const *b)
}
#endif /* HAV_EMBRTOWC */
-/* Work around a problem whereby the long double value returned by glibc's
- strtold ("NaN", ...) contains uninitialized bits: clear all bytes of
- A and B before calling strtold. FIXME: remove this function if
- gnulib guarantees that strtold's result is always well defined. */
static int
-nan_compare (char const *sa, char const *sb)
+nan_compare (long double a, long double b)
{
- long double a;
- memset (&a, 0, sizeof a);
- a = strtold (sa, NULL);
-
- long double b;
- memset (&b, 0, sizeof b);
- b = strtold (sb, NULL);
-
- return memcmp (&a, &b, sizeof a);
+ char buf[2][sizeof "-nan()" + CHAR_BIT * sizeof a];
+ snprintf (buf[0], sizeof buf[0], "%Lf", a);
+ snprintf (buf[1], sizeof buf[1], "%Lf", b);
+ return strcmp (buf[0], buf[1]);
}
static int
@@ -2402,7 +2393,7 @@ general_numcompare (char const *sa, char const *sb)
: a == b ? 0
: b == b ? -1
: a == a ? 1
- : nan_compare (sa, sb));
+ : nan_compare (a, b));
}
/* Return an integer in 1..12 of the month name MONTH.
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzx065891/coreutils.git
[email protected]:wuzx065891/coreutils.git
wuzx065891
coreutils
coreutils
master

搜索帮助