Pádraig Brady <[email protected]> writes:
> On 03/11/2025 13:09, Pádraig Brady wrote:
>> On 03/11/2025 06:36, Collin Funk wrote:
>>> diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh
>>> index b33e84a3d..60496fc06 100755
>>> --- a/tests/misc/write-errors.sh
>>> +++ b/tests/misc/write-errors.sh
>>> @@ -30,6 +30,7 @@ cat /dev/zero
>>> comm -z /dev/zero /dev/zero
>>> cut -z -c1- /dev/zero
>>> cut -z -f1- /dev/zero
>>> +date +%2147483648c
>>> dd if=/dev/zero
>>> expand /dev/zero
>>> factor --version; yes 1 | factor
>> Cool.
>> Why pick 2^31 BTW ? Wouldn't 2^31-1 (i.e. INT_MAX) suffice?
>> In either case it's probably better to use getlimits and $INT_MAX (or
>> $INT_OFLOW if needed).
>> Specific numbers like this sets off all sorts of questions in my head.
>> BTW it's interesting that date supports $INT_OFLOW, while printf
>> does not:
It was based on that recent bug report. You are correct though,
getlimits_ is better.
> Testing here shows date supports +%${INTMAX_MAX}c
> which would be a better test anyway as $INT_OFLOW
> finishes within the test timeout on my system
> which would result in a false pass.
fprintftime uses off64_t for the field width. How about the attached
patch which adds off64_t to getlimits output and uses that? I think Paul
mentioned wanting to use zprintf which returns off64_t instead of int in
Coreutils. So it will likely be used in the future.
My assumption is that printf limits the field with to INT_MAX since the
C function allows you to pass it with '*' as an int argument. I could be
wrong though, I haven't looked much into it.
Your patches look good by the way. I disliked the duplicate error output
when I noticed it yesterday, but didn't think to call ferror (stdout)
for some reason.
Collin
>From 08308386097c95cfe30c4218b0e54936a2e4d891 Mon Sep 17 00:00:00 2001
Message-ID: <08308386097c95cfe30c4218b0e54936a2e4d891.1762219247.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Sun, 2 Nov 2025 22:36:31 -0800
Subject: [PATCH] tests: date: check that write errors are promptly diagnosed
This improvement is due to changes to Gnulib's fprintftime module.
* NEWS: Mention the improvement.
* src/getlimits.c (OFF64_T_MAX, OFF64_T_MIN): New macros.
(main): Print them.
* tests/misc/write-errors.sh: Call getlimits_. Add a date invocation.
---
NEWS | 4 ++--
src/getlimits.c | 9 +++++++++
tests/misc/write-errors.sh | 2 ++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index fa14e7a2c..0a81cf7b5 100644
--- a/NEWS
+++ b/NEWS
@@ -66,8 +66,8 @@ GNU coreutils NEWS -*- outline -*-
** Improvements
- 'fmt', 'nl', and 'pr' will now exit promptly upon receiving a write error,
- which is significant when reading large / unbounded inputs.
+ 'fmt', 'date', 'nl', and 'pr' will now exit promptly upon receiving a write
+ error, which is significant when reading large / unbounded inputs.
install, sort, and split now use posix_spawn() to invoke child programs more
efficiently and more independently from their own memory usage.
diff --git a/src/getlimits.c b/src/getlimits.c
index 1cd10a6e9..db44967e7 100644
--- a/src/getlimits.c
+++ b/src/getlimits.c
@@ -46,6 +46,14 @@
# define PID_T_MIN TYPE_MINIMUM (pid_t)
#endif
+#ifndef OFF64_T_MAX
+# define OFF64_T_MAX TYPE_MAXIMUM (off64_t)
+#endif
+
+#ifndef OFF64_T_MIN
+# define OFF64_T_MIN TYPE_MINIMUM (off64_t)
+#endif
+
/* These are not interesting to print.
* Instead of these defines it would be nice to be able to do
* #ifdef (TYPE##_MIN) in function macro below. */
@@ -161,6 +169,7 @@ main (int argc, char **argv)
print_int (GID_T);
print_int (PID_T);
print_int (OFF_T);
+ print_int (OFF64_T);
print_int (INTMAX);
print_int (UINTMAX);
diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh
index 612658c6a..47220584a 100755
--- a/tests/misc/write-errors.sh
+++ b/tests/misc/write-errors.sh
@@ -18,6 +18,7 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ timeout env
+getlimits_
if ! test -w /dev/full || ! test -c /dev/full; then
skip_ '/dev/full is required'
@@ -30,6 +31,7 @@ cat /dev/zero
comm -z /dev/zero /dev/zero
cut -z -c1- /dev/zero
cut -z -f1- /dev/zero
+date +%${OFF64_T_MAX}c
date --version; yes 0 | date -f-
dd if=/dev/zero
expand /dev/zero
--
2.51.1