From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH] utimens: fix confusing arg type in internal func
Date: Wed, 7 Apr 2021 17:30:42 -0700 [thread overview]
Message-ID: <20210408003042.54031-1-eggert@cs.ucla.edu> (raw)
Although the old code was technically correct, this was accidental
and it understandably confused Coverity. Reported by Ondrej Dubaj in:
https://lists.gnu.org/r/bug-tar/2021-04/msg00000.html
* lib/utimens.c (update_timespec): Change arg type from ‘struct
timespec *[2]’ (pointer to array of 2 pointers to timespecs) to
‘struct timespec **’ (pointer to pointer to the first timespec in
an array of 2 timespecs). Although the old code happened to be
technically correct, it was misleading and confused Coverity.
And though the type ‘struct timespec (**)[2]’ (pointer to pointer
to array of 2 timespecs) would perhaps be more technically
correct, it would be almost as confusing and would require changes
elsewhere in this file; let’s quit while we’re ahead.
---
ChangeLog | 14 ++++++++++++++
lib/utimens.c | 6 +++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8d8725be2..5d91c7acc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,20 @@
2021-04-07 Paul Eggert <eggert@cs.ucla.edu>
+ utimens: fix confusing arg type in internal func
+ Although the old code was technically correct, this was accidental
+ and it understandably confused Coverity. Reported by Ondrej Dubaj in:
+ https://lists.gnu.org/r/bug-tar/2021-04/msg00000.html
+ * lib/utimens.c (update_timespec): Change arg type from ‘struct
+ timespec *[2]’ (pointer to array of 2 pointers to timespecs) to
+ ‘struct timespec **’ (pointer to pointer to the first timespec in
+ an array of 2 timespecs). Although the old code happened to be
+ technically correct, it was misleading and confused Coverity.
+ And though the type ‘struct timespec (**)[2]’ (pointer to pointer
+ to array of 2 timespecs) would perhaps be more technically
+ correct, it would be almost as confusing and would require changes
+ elsewhere in this file; let’s quit while we’re ahead.
+
xalloc: simplify integer overflow test
* lib/xalloc.h (x2nrealloc): Simplify integer overflow detection.
This is easier to maintain, and (unlike the old code) exact.
diff --git a/lib/utimens.c b/lib/utimens.c
index 44d1ea003..06d1aa36f 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -126,14 +126,14 @@ validate_timespec (struct timespec timespec[2])
return result + (utime_omit_count == 1);
}
-/* Normalize any UTIME_NOW or UTIME_OMIT values in *TS, using stat
- buffer STATBUF to obtain the current timestamps of the file. If
+/* Normalize any UTIME_NOW or UTIME_OMIT values in (*TS)[0] and (*TS)[1],
+ using STATBUF to obtain the current timestamps of the file. If
both times are UTIME_NOW, set *TS to NULL (as this can avoid some
permissions issues). If both times are UTIME_OMIT, return true
(nothing further beyond the prior collection of STATBUF is
necessary); otherwise return false. */
static bool
-update_timespec (struct stat const *statbuf, struct timespec *ts[2])
+update_timespec (struct stat const *statbuf, struct timespec **ts)
{
struct timespec *timespec = *ts;
if (timespec[0].tv_nsec == UTIME_OMIT
--
2.30.2
next reply other threads:[~2021-04-08 0:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-08 0:30 Paul Eggert [this message]
2021-04-09 7:50 ` [PATCH] utimens: fix confusing arg type in internal func Kamil Dudka
2021-04-10 1:19 ` Paul Eggert
2021-04-10 13:16 ` Kamil Dudka
2021-04-10 20:42 ` Paul Eggert
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
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210408003042.54031-1-eggert@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=bug-gnulib@gnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).