bug-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Emacs current-time-string core dump on 64-bit hosts


From: Paul Eggert
Subject: Re: Emacs current-time-string core dump on 64-bit hosts
Date: Mon, 03 Apr 2006 21:57:04 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I got a response via private email from Ulrich Leodolter about that
old comment of his in w32.c and ntlib.c.  He wrote:

> I cant remember the context, but i think know the reason for this
> workaround:
>
> time_t t = -1;
> char *str = ctime(&t);
>
> I verified that str is a null pointer when this code is compiled with
> MS Visual C/C++ 6.0, but it returns a time string on Linux/GNU.

So it appears that my analysis was correct.  That is, the problem was
unrelated to whether the working directory was a network drive.  The
problem (which is documented by Microsoft) is that, if a time stamp is
negative, ctime returns a null pointer.  This null pointer caused the
circa 1995 edition of Emacs to crash, since 1995 Emacs assumed that
ctime always returns a valid pointer.

If a future edition of Emacs uses ctime, it won't be able to assume
that ctime must return a nonnull pointer.  Even assuming reliable
implementations like glibc, a ctime-using Emacs would have to check
whether ctime's returned value is null; and to be portable to
less-reliable implementations like Solaris 8, Emacs would have to
check that ctime's argument is in an implementation-dependent range.
And either way, the w32 wrapper would not be needed.

With that in mind I'd like to re-propose the following minor cleanup
patch to the w32 code.  It doesn't fix any bugs, since Emacs no longer
uses ctime.  But it simplifies the Emacs code (e.g., it means we don't
have to fuss about the two typos in those "Sun Jan 01 00:00:00 1970"
strings :-).


2006-04-03  Paul Eggert  <address@hidden>

        * lib-src/ntlib.c (sys_ctime): Remove.  Emacs no longer uses ctime,
        and would not need to wrap w32 ctime even if Emacs used ctime,
        assuming Emacs used ctime safely (e.g., checking result against NULL).
        * lib-src/ntlib.h (ctime): Likewise.
        * src/w32.c (sys_ctime): Likewise.
        * src/s/ms-w32.h (ctime): Likewise.

Index: lib-src/ntlib.c
===================================================================
RCS file: /cvsroot/emacs/emacs/lib-src/ntlib.c,v
retrieving revision 1.13
diff -p -c -r1.13 ntlib.c
*** lib-src/ntlib.c     6 Feb 2006 11:28:28 -0000       1.13
--- lib-src/ntlib.c     4 Apr 2006 04:32:17 -0000
*************** fchown (int fd, int uid, int gid)
*** 188,203 ****
    return 0;
  }
  
- /* Place a wrapper around the MSVC version of ctime.  It returns NULL
-    on network directories, so we handle that case here.
-    (Ulrich Leodolter, 1/11/95).  */
- char *
- sys_ctime (const time_t *t)
- {
-   char *str = (char *) ctime (t);
-   return (str ? str : "Sun Jan 01 00:00:00 1970");
- }
- 
  FILE *
  sys_fopen(const char * path, const char * mode)
  {
--- 188,193 ----
Index: lib-src/ntlib.h
===================================================================
RCS file: /cvsroot/emacs/emacs/lib-src/ntlib.h,v
retrieving revision 1.11
diff -p -c -r1.11 ntlib.h
*** lib-src/ntlib.h     6 Feb 2006 11:28:28 -0000       1.11
--- lib-src/ntlib.h     4 Apr 2006 04:32:17 -0000
*************** int fchown (int fd, int uid, int gid);
*** 61,67 ****
  #define close   _close
  #undef creat
  #define creat   _creat
- #undef ctime
  #undef dup
  #define dup     _dup
  #undef dup2
--- 61,66 ----
Index: src/w32.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/w32.c,v
retrieving revision 1.100
diff -p -c -r1.100 w32.c
*** src/w32.c   27 Feb 2006 02:07:37 -0000      1.100
--- src/w32.c   4 Apr 2006 04:32:17 -0000
*************** Boston, MA 02110-1301, USA.
*** 43,49 ****
  #undef chdir
  #undef chmod
  #undef creat
- #undef ctime
  #undef fopen
  #undef link
  #undef mkdir
--- 43,48 ----
*************** gettimeofday (struct timeval *tv, struct
*** 1325,1340 ****
  /* IO support and wrapper functions for W32 API. */
  /* ------------------------------------------------------------------------- 
*/
  
- /* Place a wrapper around the MSVC version of ctime.  It returns NULL
-    on network directories, so we handle that case here.
-    (Ulrich Leodolter, 1/11/95).  */
- char *
- sys_ctime (const time_t *t)
- {
-   char *str = (char *) ctime (t);
-   return (str ? str : "Sun Jan 01 00:00:00 1970");
- }
- 
  /* Emulate sleep...we could have done this with a define, but that
     would necessitate including windows.h in the files that used it.
     This is much easier.  */
--- 1324,1329 ----
Index: src/s/ms-w32.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/s/ms-w32.h,v
retrieving revision 1.37
diff -p -c -r1.37 ms-w32.h
*** src/s/ms-w32.h      6 Feb 2006 15:23:23 -0000       1.37
--- src/s/ms-w32.h      4 Apr 2006 04:32:17 -0000
*************** Boston, MA 02110-1301, USA.  */
*** 317,323 ****
  #define close   sys_close
  #undef creat
  #define creat   sys_creat
- #define ctime sys_ctime
  #undef dup
  #define dup     sys_dup
  #undef dup2
--- 317,322 ----




reply via email to

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