From: Isaac Dunham <ibid.ag@gmail.com>
To: Andreas Schwab <schwab@suse.de>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH] script: don't assume time_t is compatible with long
Date: Thu, 15 Oct 2015 18:12:59 -0700 [thread overview]
Message-ID: <20151016011258.GA3711@newbook> (raw)
In-Reply-To: <mvm37xcs2mb.fsf@hawking.suse.de>
[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]
On Thu, Oct 15, 2015 at 03:06:04PM +0200, Andreas Schwab wrote:
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
> term-utils/script.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/term-utils/script.c b/term-utils/script.c
> index eb4ddc3..ad252a3 100644
> --- a/term-utils/script.c
> +++ b/term-utils/script.c
> @@ -141,7 +141,7 @@ static void script_init_debug(void)
> static inline time_t script_time(time_t *t)
> {
> const char *str = getenv("SCRIPT_TEST_SECOND_SINCE_EPOCH");
> - time_t sec;
> + long sec;
>
> if (str && sscanf(str, "%ld", &sec) == 1)
> return sec;
I don't think this does what the commit message says.
Rather, it moves the assumption.
If you're trying to actually *fix* it so it works with 64-bit time_t on
x86 (some kernel developers have discussed a path forwards on that, and
OpenBSD has already implemented it), this will not do the job.
And I note that the old code here is already technically wrong, since this
is supposed to a replacement for time(). It should have included something
equivalent to:
if (t)
*t = (time_t)sec;
I'm guessing that the attached patch would be the most corrrect approach;
any comments?
Thanks,
Isaac Dunham
[-- Attachment #2: 0001-script-don-t-assume-that-time_t-is-compatible-with-l.patch --]
[-- Type: text/plain, Size: 1062 bytes --]
>From 4fc3751060ab5d4fb84aa814520c7ca1afe32a28 Mon Sep 17 00:00:00 2001
From: Isaac Dunham <ibid.ag@gmail.com>
Date: Thu, 15 Oct 2015 18:03:28 -0700
Subject: [PATCH] script: don't assume that time_t is compatible with long
time_t may change to 64-bit on 32-bit Linux kernels at some point;
at that point, it may be desireable to test for issues with dates
past 2038.
---
term-utils/script.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/term-utils/script.c b/term-utils/script.c
index eb4ddc3..f0e997e 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -141,11 +141,13 @@ static void script_init_debug(void)
static inline time_t script_time(time_t *t)
{
const char *str = getenv("SCRIPT_TEST_SECOND_SINCE_EPOCH");
- time_t sec;
+ int64_t sec;
- if (str && sscanf(str, "%ld", &sec) == 1)
- return sec;
- return time(t);
+ if (!str || sscanf(str, "%lld", &sec) != 1)
+ return time(t);
+ if (t)
+ *t = (time_t)sec;
+ return (time_t)sec;
}
#else /* !TEST_SCRIPT */
# define script_time(x) time(x)
--
2.6.1
next prev parent reply other threads:[~2015-10-16 1:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 13:06 [PATCH] script: don't assume time_t is compatible with long Andreas Schwab
2015-10-16 1:12 ` Isaac Dunham [this message]
2015-10-16 10:10 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151016011258.GA3711@newbook \
--to=ibid.ag@gmail.com \
--cc=schwab@suse.de \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.