From: Paul Eggert Date: Wed, 4 Sep 2019 00:34:08 +0000 (-0700) Subject: Avoid casting -1 to possibly-unsigned enum X-Git-Tag: emacs-27.0.90~1553^2~47 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d20655669bd6f94cdd9fb2472668e92a069c0cf2;p=emacs.git Avoid casting -1 to possibly-unsigned enum * src/alloc.c (mark_maybe_pointer): * src/pdumper.h (pdumper_object_p_precise): Use pdumper_valid_object_type_p. * src/pdumper.c (pdumper_find_object_type_impl): * src/pdumper.h (pdumper_find_object_type): Return int, not enum Lisp_Type. All callers changed. * src/pdumper.h (PDUMPER_NO_OBJECT): Do not cast -1 to enum Lisp_Type; in theory, C18 says this could yield 7, which would mean PDUMPER_NO_OBJECT == Lisp_Float (!). (pdumper_valid_object_type_p): New function. --- diff --git a/src/alloc.c b/src/alloc.c index 5f8ef0a5dda..089f61f8339 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4617,11 +4617,11 @@ mark_maybe_pointer (void *p) if (pdumper_object_p (p)) { - enum Lisp_Type type = pdumper_find_object_type (p); - if (type != PDUMPER_NO_OBJECT) - mark_object ((type == Lisp_Symbol) - ? make_lisp_symbol(p) - : make_lisp_ptr(p, type)); + int type = pdumper_find_object_type (p); + if (pdumper_valid_object_type_p (type)) + mark_object (type == Lisp_Symbol + ? make_lisp_symbol (p) + : make_lisp_ptr (p, type)); /* See mark_maybe_object for why we can confidently return. */ return; } diff --git a/src/pdumper.c b/src/pdumper.c index 5e70e20431c..f9c31d125a4 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -5057,7 +5057,7 @@ pdumper_cold_object_p_impl (const void *obj) return offset >= dump_private.header.cold_start; } -enum Lisp_Type +int pdumper_find_object_type_impl (const void *obj) { eassert (pdumper_object_p (obj)); @@ -5067,7 +5067,7 @@ pdumper_find_object_type_impl (const void *obj) const struct dump_reloc *reloc = dump_find_relocation (&dump_private.header.object_starts, offset); return (reloc != NULL && dump_reloc_get_offset (*reloc) == offset) - ? (enum Lisp_Type) reloc->type + ? reloc->type : PDUMPER_NO_OBJECT; } diff --git a/src/pdumper.h b/src/pdumper.h index 5d1e9c3aea3..83c094f3caa 100644 --- a/src/pdumper.h +++ b/src/pdumper.h @@ -24,7 +24,7 @@ along with GNU Emacs. If not, see . */ INLINE_HEADER_BEGIN -#define PDUMPER_NO_OBJECT ((enum Lisp_Type) -1) +enum { PDUMPER_NO_OBJECT = -1 }; /* Indicate in source code that we're deliberately relying on pdumper not preserving the given value. Compiles to nothing --- for humans @@ -170,12 +170,12 @@ pdumper_cold_object_p (const void *obj) } -extern enum Lisp_Type pdumper_find_object_type_impl (const void *obj); +extern int pdumper_find_object_type_impl (const void *obj); /* Return the type of the dumped object that starts at OBJ. It is a programming error to call this routine for an OBJ for which pdumper_object_p would return false. */ -INLINE _GL_ATTRIBUTE_CONST enum Lisp_Type +INLINE _GL_ATTRIBUTE_CONST int pdumper_find_object_type (const void *obj) { #ifdef HAVE_PDUMPER @@ -186,6 +186,14 @@ pdumper_find_object_type (const void *obj) #endif } +/* Return true if TYPE is that of a Lisp object. + PDUMPER_NO_OBJECT is invalid. */ +INLINE bool +pdumper_valid_object_type_p (int type) +{ + return 0 <= type; +} + /* Return whether OBJ points exactly to the start of some object in the loaded dump image. It is a programming error to call this routine for an OBJ for which pdumper_object_p would return @@ -194,7 +202,7 @@ INLINE _GL_ATTRIBUTE_CONST bool pdumper_object_p_precise (const void *obj) { #ifdef HAVE_PDUMPER - return pdumper_find_object_type (obj) != PDUMPER_NO_OBJECT; + return pdumper_valid_object_type_p (pdumper_find_object_type (obj)); #else (void) obj; emacs_abort ();