all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@CS.UCLA.EDU>
Cc: bug-gnu-emacs@gnu.org
Subject: Re: Emacs current-time-string core dump on 64-bit hosts
Date: Mon, 03 Apr 2006 21:57:04 -0700	[thread overview]
Message-ID: <878xqm3plr.fsf@penguin.cs.ucla.edu> (raw)
In-Reply-To: <877j6c74jk.fsf@penguin.cs.ucla.edu>

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  <eggert@cs.ucla.edu>

	* 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 ----

  parent reply	other threads:[~2006-04-04  4:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-17  5:58 Emacs current-time-string core dump on 64-bit hosts Paul Eggert
2006-03-17 12:16 ` Eli Zaretskii
2006-03-17 12:46   ` Andreas Schwab
2006-03-17 16:04   ` Kevin Rodgers
2006-03-18  0:44   ` Paul Eggert
2006-03-18 11:50     ` Eli Zaretskii
2006-03-19  2:30       ` Paul Eggert
2006-03-21 19:25         ` Richard Stallman
2006-03-18  8:43   ` Richard Stallman
2006-03-19  1:53     ` Paul Eggert
2006-03-19 21:50       ` Richard Stallman
2006-03-19 23:44         ` Paul Eggert
2006-03-20 19:59           ` Eli Zaretskii
2006-03-27 22:00             ` Paul Eggert
2006-03-28 10:16               ` Eli Zaretskii
2006-03-30  7:52                 ` Paul Eggert
2006-03-30 20:36                   ` Eli Zaretskii
2006-04-04  4:57                   ` Paul Eggert [this message]
2006-04-04 18:20                     ` Eli Zaretskii
2006-03-21  1:00           ` Richard Stallman
2006-03-24 20:45             ` Paul Eggert
2006-03-25  9:10               ` Eli Zaretskii
2006-03-26  5:25                 ` Paul Eggert
2006-03-26 20:06                   ` Eli Zaretskii
2006-03-27 22:29                     ` Richard Stallman
2006-03-28 10:20                       ` Eli Zaretskii
2006-03-29  8:14                         ` Richard Stallman
2006-03-25 15:26               ` Richard Stallman
2006-03-24 21:00             ` Paul Eggert
2006-03-24 21:09             ` Paul Eggert
2006-03-25 15:26               ` Richard Stallman
2006-03-26  7:31                 ` Paul Eggert
     [not found]                   ` <E1FNnCd-0000pN-J4@fencepost.gnu.org>
2006-03-27 20:49                     ` Paul Eggert
2006-03-28 19:33                       ` Richard Stallman
2006-03-30  7:57                         ` Paul Eggert
2006-03-31 17:28                           ` Richard Stallman
2006-03-31 20:51                             ` Paul Eggert
2006-04-01 20:28                               ` Richard Stallman
2006-04-03  4:44                                 ` Paul Eggert
2006-03-17 16:25 ` Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2006-03-17  8:02 Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878xqm3plr.fsf@penguin.cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.