m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

module/time.c violates aliasing rules


From: Andreas Schwab
Subject: module/time.c violates aliasing rules
Date: Mon, 05 Jun 2006 00:55:42 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

modules/time.c: In function 'builtin_ctime':
modules/time.c:100: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
modules/time.c: In function 'builtin_gmtime':
modules/time.c:144: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
modules/time.c: In function 'builtin_localtime':
modules/time.c:157: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
modules/time.c: In function 'builtin_strftime':
modules/time.c:204: warning: dereferencing type-punned pointer will break 
strict-aliasing rules

This is guaranteed to fail on bigendian hosts with time_t > int.

It will still break down after 2038-01-19 03:14:07+00:00.

Andreas.

2006-06-05  Andreas Schwab  <address@hidden>

        * modules/time.c (ctime): Pass correctly typed variable to
        m4_numeric_arg.
        (gmtime): Likewise.
        (localtime): Likewise.
        (strftime): Likewise.

--- modules/time.c.~1.13.~      2005-12-12 16:28:30.000000000 +0100
+++ modules/time.c      2006-06-05 00:37:36.000000000 +0200
@@ -95,9 +95,13 @@ M4BUILTIN_HANDLER (currenttime)
 M4BUILTIN_HANDLER (ctime)
 {
   time_t t;
+  int i;
 
   if (argc == 2)
-    m4_numeric_arg (context, argc, argv, 1, (int *) &t);
+    {
+      m4_numeric_arg (context, argc, argv, 1, &i);
+      t = i;
+    }
   else
     t = time (0L);
 
@@ -140,10 +144,12 @@ format_tm (m4_obstack *obs, struct tm *t
 M4BUILTIN_HANDLER (gmtime)
 {
   time_t t;
+  int i;
 
-  if (!m4_numeric_arg (context, argc, argv, 1, (int *) &t))
+  if (!m4_numeric_arg (context, argc, argv, 1, &i))
     return;
 
+  t = i;
   format_tm (obs, gmtime (&t));
 }
 
@@ -153,10 +159,12 @@ M4BUILTIN_HANDLER (gmtime)
 M4BUILTIN_HANDLER (localtime)
 {
   time_t t;
+  int i;
 
-  if (!m4_numeric_arg (context, argc, argv, 1, (int *) &t))
+  if (!m4_numeric_arg (context, argc, argv, 1, &i))
     return;
 
+  t = i;
   format_tm (obs, localtime (&t));
 }
 
@@ -201,9 +209,10 @@ M4BUILTIN_HANDLER (strftime)
   char *buf;
   int l;
 
-  if (!m4_numeric_arg (context, argc, argv, 2, (int *) &t))
+  if (!m4_numeric_arg (context, argc, argv, 2, &l))
     return;
 
+  t = l;
   tm = localtime (&t);
 
   buf = (char *) obstack_alloc (obs, 1024);

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]