[Patch, libfortran, committed] PR 47802 Hack around POSIX draft localtime_r
Janne Blomqvist
blomqvist.janne@gmail.com
Fri Mar 4 19:09:00 GMT 2011
On Fri, Mar 4, 2011 at 20:06, Jakub Jelinek <jakub@redhat.com> wrote:
> 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, <m)) == 5,
> failed = localtime_r (timep, <m) == NULL,
> failed = localtime_r (timep, <m) != 0);
> if (failed)
> return 0;
> or something similar.
Fair enough, that does the trick. Patch that I just committed below.
Index: intrinsics/ctime.c
===================================================================
--- intrinsics/ctime.c (revision 170680)
+++ intrinsics/ctime.c (working copy)
@@ -40,11 +40,16 @@ strctime (char *s, size_t max, const tim
{
#ifdef HAVE_STRFTIME
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
+ int failed;
+ /* Some targets provide a 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, <m);
+ __builtin_choose_expr (__builtin_classify_type (localtime_r (timep, <m))
+ == 5,
+ failed = localtime_r (timep, <m) == NULL,
+ failed = localtime_r (timep, <m) != 0);
+ if (failed)
+ return 0;
return strftime (s, max, "%c", <m);
#else
return 0;
Index: ChangeLog
===================================================================
--- ChangeLog (revision 170680)
+++ ChangeLog (working copy)
@@ -1,6 +1,12 @@
2011-03-04 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/47802
+ * intrinsics/ctime.c (strctime): Use builtins to check localtime_r
+ return value.
+
+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
More information about the Gcc-patches
mailing list