public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Zack Weinberg <zack@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/zack/y2038-preliminaries] Warn when gettimeofday is called with non-null tzp argument.
Date: Tue, 20 Aug 2019 12:32:00 -0000	[thread overview]
Message-ID: <20190820123201.15877.qmail@sourceware.org> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 4001 bytes --]

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5fc9cbd920c43edf56e12c15ebb1b62b8d9d24b7

commit 5fc9cbd920c43edf56e12c15ebb1b62b8d9d24b7
Author: Zack Weinberg <zackw@panix.com>
Date:   Mon Aug 19 13:51:25 2019 -0400

    Warn when gettimeofday is called with non-null tzp argument.
    
    At this stage I don’t think we can issue warnings for settimeofday
    with a non-null tzp argument, nor for arbitrary use of struct
    timezone.  But we can warn about gettimeofday with non-null tzp.
    
    This uses a macro instead of an inline (fortify-style) function
    because I got false positives with an inline, even with GCC 9.
    
    	* time/sys/time.h (__timezone_ptr_t): Delete.
    	(gettimeofday): Always declare second argument with type ‘void *’.
    	When possible, wrap with a macro that detects non-null and
    	non-constant second argument and issues a warning.
    	Improve commentary.
    	(settimeofday): Improve commentary.
    
    	* time/gettimeofday.c (gettimeofday):
    	Declare second argument as type ‘void *’.

Diff:
---
 time/gettimeofday.c |  4 ++--
 time/sys/time.h     | 36 +++++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/time/gettimeofday.c b/time/gettimeofday.c
index 22a996a..bd1fc3c 100644
--- a/time/gettimeofday.c
+++ b/time/gettimeofday.c
@@ -23,10 +23,10 @@
    If *TZ is not NULL, clear it.
    Returns 0 on success, -1 on errors.  */
 int
-__gettimeofday (struct timeval *tv, struct timezone *tz)
+__gettimeofday (struct timeval *restrict tv, void *restrict tz)
 {
   if (__glibc_unlikely (tz != 0))
-    memset (tz, 0, sizeof *tz);
+    memset (tz, 0, sizeof (struct timezone));
 
   struct timespec ts;
   if (__clock_gettime (CLOCK_REALTIME, &ts))
diff --git a/time/sys/time.h b/time/sys/time.h
index 5dbc7fc..1b6c112 100644
--- a/time/sys/time.h
+++ b/time/sys/time.h
@@ -54,23 +54,37 @@ struct timezone
     int tz_minuteswest;		/* Minutes west of GMT.  */
     int tz_dsttime;		/* Nonzero if DST is ever in effect.  */
   };
-
-typedef struct timezone *__restrict __timezone_ptr_t;
-#else
-typedef void *__restrict __timezone_ptr_t;
 #endif
 
-/* Get the current time of day and timezone information,
-   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
-   Returns 0 on success, -1 on errors.
-   NOTE: This form of timezone information is obsolete.
-   Use the functions and variables declared in <time.h> instead.  */
+/* Get the current time of day, putting it into *TV.
+   If TZ is not null, *TZ must be a struct timezone, and both fields
+   will be set to zero.
+   Calling this function with a non-null TZ is obsolete;
+   use localtime etc. instead.
+   This function itself is semi-obsolete;
+   most callers should use time or clock_gettime instead. */
 extern int gettimeofday (struct timeval *__restrict __tv,
-			 __timezone_ptr_t __tz) __THROW __nonnull ((1));
+			 void *__restrict __tz) __THROW __nonnull ((1));
+
+#if __GNUC_PREREQ (4,3)
+/* Issue a warning for use of gettimeofday with a non-null __tz argument.  */
+__warndecl (__warn_gettimeofday_timezone,
+            "gettimeofday with non-null or non-constant timezone parameter;"
+            " this is obsolete and inaccurate, use localtime instead");
+
+#define gettimeofday(__tv, __tz)                        \
+  (((!__builtin_constant_p (__tz) || (__tz) != 0)       \
+    ? __warn_gettimeofday_timezone ()                   \
+    : (void) 0),                                        \
+   (gettimeofday) (__tv, __tz))
+#endif
 
 #ifdef __USE_MISC
 /* Set the current time of day and timezone information.
-   This call is restricted to the super-user.  */
+   This call is restricted to the super-user.
+   Setting the timezone in this way is obsolete, but we don't yet
+   warn about it because it still has some uses for which there is
+   no alternative.  */
 extern int settimeofday (const struct timeval *__tv,
 			 const struct timezone *__tz)
      __THROW;


             reply	other threads:[~2019-08-20 12:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20 12:32 Zack Weinberg [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-08-28 13:05 Zack Weinberg
2019-08-22 23:04 Zack Weinberg
2019-08-21 12:28 Zack Weinberg
2019-08-20 13:25 Zack Weinberg
2019-08-20 12:08 Zack Weinberg
2019-08-19 18:31 Zack Weinberg

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=20190820123201.15877.qmail@sourceware.org \
    --to=zack@sourceware.org \
    --cc=glibc-cvs@sourceware.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).