diff mbox

[libfortran,committed] PR 47802 Hack around POSIX draft localtime_r

Message ID AANLkTim0Q4cXmTNbH5f4gJ1MNkmAy_F8P_LnVMndW2AT@mail.gmail.com
State New
Headers show

Commit Message

Janne Blomqvist March 4, 2011, 5:54 p.m. UTC
This should fix the problem reported on HP-UX 10.2. Committed as obvious:

Comments

Jakub Jelinek March 4, 2011, 6:06 p.m. UTC | #1
On Fri, Mar 04, 2011 at 07:54:29PM +0200, Janne Blomqvist wrote:
> This should fix the problem reported on HP-UX 10.2. Committed as obvious:

Well, it is not so obvious, you shouldn't be ignoring the return value from
strftime, because if it fails, ltm will contain raondom undefined values.
If there are different return values, you should just
__builtin_choose_expr (__builtin_classify_type (localtime_r (timep, &ltm)) == 5,
		       failed = localtime_r (timep, &ltm) == NULL,
		       failed = localtime_r (timep, &ltm) != 0);
if (failed)
  return 0;
or something similar.

> --- intrinsics/ctime.c  (revision 170679)
> +++ intrinsics/ctime.c  (working copy)
> @@ -39,9 +39,13 @@ static size_t
>  strctime (char *s, size_t max, const time_t *timep)
>  {
>  #ifdef HAVE_STRFTIME
> -  struct tm res;
> -  struct tm *ltm = localtime_r (timep, &res);
> -  return strftime (s, max, "%c", ltm);
> +  struct tm ltm;
> +  /* Note: We can't use the return value of localtime_r, as some
> +     targets provide localtime_r based on a draft of the POSIX
> +     standard where the return type is int rather than the
> +     standardized struct tm*.  */
> +  localtime_r (timep, &ltm);
> +  return strftime (s, max, "%c", &ltm);
>  #else
>    return 0;
>  #endif
> Index: ChangeLog
> ===================================================================
> --- ChangeLog   (revision 170679)
> +++ ChangeLog   (working copy)
> @@ -1,3 +1,9 @@
> +2011-03-04  Janne Blomqvist  <jb@gcc.gnu.org>
> +
> +       PR libfortran/47802
> +       * intrinsics/ctime.c (strctime): Don't use return value of
> +       localtime_r.
> +

	Jakub
diff mbox

Patch

Index: intrinsics/ctime.c
===================================================================
--- intrinsics/ctime.c  (revision 170679)
+++ intrinsics/ctime.c  (working copy)
@@ -39,9 +39,13 @@  static size_t
 strctime (char *s, size_t max, const time_t *timep)
 {
 #ifdef HAVE_STRFTIME
-  struct tm res;
-  struct tm *ltm = localtime_r (timep, &res);
-  return strftime (s, max, "%c", ltm);
+  struct tm ltm;
+  /* Note: We can't use the return value of localtime_r, as some
+     targets provide localtime_r based on a draft of the POSIX
+     standard where the return type is int rather than the
+     standardized struct tm*.  */
+  localtime_r (timep, &ltm);
+  return strftime (s, max, "%c", &ltm);
 #else
   return 0;
 #endif
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 170679)
+++ ChangeLog   (working copy)
@@ -1,3 +1,9 @@ 
+2011-03-04  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR libfortran/47802
+       * intrinsics/ctime.c (strctime): Don't use return value of
+       localtime_r.
+


-- 
Janne Blomqvist