# HG changeset patch # User aidan # Date 1180204103 0 # Node ID 1227374e7199168392b957c94d897f4c165296c1 # Parent 4459187632999dbe080a2f36abfd9cde3375003e [xemacs-hg @ 2007-05-26 18:28:19 by aidan] Make double-free checks 64-bit safe, from Sebastian Freundt. diff -r 445918763299 -r 1227374e7199 src/ChangeLog --- a/src/ChangeLog Fri May 25 21:51:11 2007 +0000 +++ b/src/ChangeLog Sat May 26 18:28:23 2007 +0000 @@ -1,3 +1,12 @@ +2007-05-24 Aidan Kehoe + + * free-hook.c (check_free): + * lisp.h: + * lisp.h (xfree): + Inspired by some of Sebastian Freundt's SXEmacs work, use a 64-bit + constant on 64-bit platforms when making sure pointers haven't + been freed twice. + 2007-05-22 Ville Skyttä * Makefile.in.in ($(LISP)/finder-inf.el): Set lisp-directory diff -r 445918763299 -r 1227374e7199 src/free-hook.c --- a/src/free-hook.c Fri May 25 21:51:11 2007 +0000 +++ b/src/free-hook.c Sat May 26 18:28:23 2007 +0000 @@ -179,6 +179,8 @@ / sizeof (long); unsigned long i; + /* Not using the DEADBEEF_CONSTANT #define, since we don't know + * that allocation sizes will be multiples of eight. */ for (i = 0; i < long_length; i++) ((unsigned long *) ptr)[i] = 0xdeadbeef; } diff -r 445918763299 -r 1227374e7199 src/lisp.h --- a/src/lisp.h Fri May 25 21:51:11 2007 +0000 +++ b/src/lisp.h Sat May 26 18:28:23 2007 +0000 @@ -250,6 +250,14 @@ typedef unsigned long uintptr_t; #endif +#if SIZEOF_VOID_P == 8 +#define DEADBEEF_CONSTANT 0xCAFEBABEDEADBEEF +#elif SIZEOF_VOID_P == 4 +#define DEADBEEF_CONSTANT 0xDEADBEEF +#else +#error "What size are your pointers, really?" +#endif /* SIZEOF_VOID_P == 8 */ + /* ---------------------- definition of EMACS_INT --------------------- */ /* EMACS_INT is the underlying integral type into which a Lisp_Object must fit. @@ -1084,7 +1092,7 @@ #define xfree(lvalue, type) do \ { \ xfree_1 (lvalue); \ - VOIDP_CAST (lvalue) = (void *) 0xDEADBEEF; \ + VOIDP_CAST (lvalue) = (void *) DEADBEEF_CONSTANT; \ } while (0) #else #define xfree(lvalue,type) xfree_1 (lvalue)