Mod'ing struct tm causes segmentation fault on RHEL 5.4

Tim P. Starrin Timothy.P.Starrin at nasa.gov
Thu Jul 1 23:11:18 UTC 2010


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




More information about the redhat-list mailing list