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

Mod'ing struct tm causes segmentation fault on RHEL 5.4



The following program generates a segmentation fault on RHEL 5.4. Other systems (eg: Solaris, AIX, RHEL 4) do not exhibit this problem.

Comments?

Tim

% cc -DBUG -o fault fault.c

=> fault.c <=
#include <stdio.h>
#include <time.h>
#include <sys/time.h>

main ()
{
 struct tm *date;
 int date_as_int;

date_as_int = time ((time_t *) NULL);
 date = localtime ((time_t *) &date_as_int);

#ifdef BUG
 date->tm_year %= 100;
#else
 while (date->tm_year >= 100)
   date->tm_year -= 100;
#endif

 printf ("%02d/%02d/%02d %02d:%02d:%02d\n",
     date->tm_year, date->tm_mon+1, date->tm_mday,
     date->tm_hour, date->tm_min, date->tm_sec);
}

Tim



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