aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-09-03 17:34:08 -0700
committerPaul Eggert2019-09-03 17:34:50 -0700
commitd20655669bd6f94cdd9fb2472668e92a069c0cf2 (patch)
tree610e9a9ea0948470c015568ca1e7ccf8bcdd03ef /src
parent5f089ac93f18fbd6e8131b81e1c6b403894b5759 (diff)
downloademacs-d20655669bd6f94cdd9fb2472668e92a069c0cf2.tar.gz
emacs-d20655669bd6f94cdd9fb2472668e92a069c0cf2.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c10
-rw-r--r--src/pdumper.c4
-rw-r--r--src/pdumper.h16
3 files changed, 19 insertions, 11 deletions
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)
4617 4617
4618 if (pdumper_object_p (p)) 4618 if (pdumper_object_p (p))
4619 { 4619 {
4620 enum Lisp_Type type = pdumper_find_object_type (p); 4620 int type = pdumper_find_object_type (p);
4621 if (type != PDUMPER_NO_OBJECT) 4621 if (pdumper_valid_object_type_p (type))
4622 mark_object ((type == Lisp_Symbol) 4622 mark_object (type == Lisp_Symbol
4623 ? make_lisp_symbol(p) 4623 ? make_lisp_symbol (p)
4624 : make_lisp_ptr(p, type)); 4624 : make_lisp_ptr (p, type));
4625 /* See mark_maybe_object for why we can confidently return. */ 4625 /* See mark_maybe_object for why we can confidently return. */
4626 return; 4626 return;
4627 } 4627 }
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)
5057 return offset >= dump_private.header.cold_start; 5057 return offset >= dump_private.header.cold_start;
5058} 5058}
5059 5059
5060enum Lisp_Type 5060int
5061pdumper_find_object_type_impl (const void *obj) 5061pdumper_find_object_type_impl (const void *obj)
5062{ 5062{
5063 eassert (pdumper_object_p (obj)); 5063 eassert (pdumper_object_p (obj));
@@ -5067,7 +5067,7 @@ pdumper_find_object_type_impl (const void *obj)
5067 const struct dump_reloc *reloc = 5067 const struct dump_reloc *reloc =
5068 dump_find_relocation (&dump_private.header.object_starts, offset); 5068 dump_find_relocation (&dump_private.header.object_starts, offset);
5069 return (reloc != NULL && dump_reloc_get_offset (*reloc) == offset) 5069 return (reloc != NULL && dump_reloc_get_offset (*reloc) == offset)
5070 ? (enum Lisp_Type) reloc->type 5070 ? reloc->type
5071 : PDUMPER_NO_OBJECT; 5071 : PDUMPER_NO_OBJECT;
5072} 5072}
5073 5073
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 <http://www.gnu.org/licenses/>. */
24 24
25INLINE_HEADER_BEGIN 25INLINE_HEADER_BEGIN
26 26
27#define PDUMPER_NO_OBJECT ((enum Lisp_Type) -1) 27enum { PDUMPER_NO_OBJECT = -1 };
28 28
29/* Indicate in source code that we're deliberately relying on pdumper 29/* Indicate in source code that we're deliberately relying on pdumper
30 not preserving the given value. Compiles to nothing --- for humans 30 not preserving the given value. Compiles to nothing --- for humans
@@ -170,12 +170,12 @@ pdumper_cold_object_p (const void *obj)
170} 170}
171 171
172 172
173extern enum Lisp_Type pdumper_find_object_type_impl (const void *obj); 173extern int pdumper_find_object_type_impl (const void *obj);
174 174
175/* Return the type of the dumped object that starts at OBJ. It is a 175/* Return the type of the dumped object that starts at OBJ. It is a
176 programming error to call this routine for an OBJ for which 176 programming error to call this routine for an OBJ for which
177 pdumper_object_p would return false. */ 177 pdumper_object_p would return false. */
178INLINE _GL_ATTRIBUTE_CONST enum Lisp_Type 178INLINE _GL_ATTRIBUTE_CONST int
179pdumper_find_object_type (const void *obj) 179pdumper_find_object_type (const void *obj)
180{ 180{
181#ifdef HAVE_PDUMPER 181#ifdef HAVE_PDUMPER
@@ -186,6 +186,14 @@ pdumper_find_object_type (const void *obj)
186#endif 186#endif
187} 187}
188 188
189/* Return true if TYPE is that of a Lisp object.
190 PDUMPER_NO_OBJECT is invalid. */
191INLINE bool
192pdumper_valid_object_type_p (int type)
193{
194 return 0 <= type;
195}
196
189/* Return whether OBJ points exactly to the start of some object in 197/* Return whether OBJ points exactly to the start of some object in
190 the loaded dump image. It is a programming error to call this 198 the loaded dump image. It is a programming error to call this
191 routine for an OBJ for which pdumper_object_p would return 199 routine for an OBJ for which pdumper_object_p would return
@@ -194,7 +202,7 @@ INLINE _GL_ATTRIBUTE_CONST bool
194pdumper_object_p_precise (const void *obj) 202pdumper_object_p_precise (const void *obj)
195{ 203{
196#ifdef HAVE_PDUMPER 204#ifdef HAVE_PDUMPER
197 return pdumper_find_object_type (obj) != PDUMPER_NO_OBJECT; 205 return pdumper_valid_object_type_p (pdumper_find_object_type (obj));
198#else 206#else
199 (void) obj; 207 (void) obj;
200 emacs_abort (); 208 emacs_abort ();