emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 7610169 1/2: Fix check for unsafe watch descriptor


From: Paul Eggert
Subject: [Emacs-diffs] master 7610169 1/2: Fix check for unsafe watch descriptor
Date: Mon, 13 Aug 2018 18:55:58 -0400 (EDT)

branch: master
commit 76101698a770d389f22b547c331ec78473040c47
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Fix check for unsafe watch descriptor
    
    * src/lisp.h (make_pointer_integer_unsafe): New function.
    (make_pointer_integer): Use it.
    * src/gfilenotify.c (dir_monitor_callback): Omit redundant eassert.
    (Fgfile_add_watch): Signal an error instead of failing an
    assertion if the pointer does not work.
---
 src/gfilenotify.c | 7 +++----
 src/lisp.h        | 8 +++++++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/gfilenotify.c b/src/gfilenotify.c
index 7eea2cf..798f308 100644
--- a/src/gfilenotify.c
+++ b/src/gfilenotify.c
@@ -77,7 +77,6 @@ dir_monitor_callback (GFileMonitor *monitor,
 
   /* Determine callback function.  */
   monitor_object = make_pointer_integer (monitor);
-  eassert (FIXNUMP (monitor_object));
   watch_object = assq_no_quit (monitor_object, watch_list);
 
   if (CONSP (watch_object))
@@ -203,10 +202,10 @@ will be reported only in case of the `moved' event.  */)
   if (! monitor)
     xsignal2 (Qfile_notify_error, build_string ("Cannot watch file"), file);
 
-  Lisp_Object watch_descriptor = make_pointer_integer (monitor);
+  Lisp_Object watch_descriptor = make_pointer_integer_unsafe (monitor);
 
-  /* Check the dicey assumption that make_pointer_integer is safe.  */
-  if (! FIXNUMP (watch_descriptor))
+  if (! (FIXNUMP (watch_descriptor)
+        && XFIXNUMPTR (watch_descriptor) == monitor))
     {
       g_object_unref (monitor);
       xsignal2 (Qfile_notify_error, build_string ("Unsupported file watcher"),
diff --git a/src/lisp.h b/src/lisp.h
index b7ef8dc..18d5353 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1189,9 +1189,15 @@ XFIXNUMPTR (Lisp_Object a)
 }
 
 INLINE Lisp_Object
+make_pointer_integer_unsafe (void *p)
+{
+  return TAG_PTR (Lisp_Int0, p);
+}
+
+INLINE Lisp_Object
 make_pointer_integer (void *p)
 {
-  Lisp_Object a = TAG_PTR (Lisp_Int0, p);
+  Lisp_Object a = make_pointer_integer_unsafe (p);
   eassert (FIXNUMP (a) && XFIXNUMPTR (a) == p);
   return a;
 }



reply via email to

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