aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2025-01-26 23:04:21 -0800
committerPaul Eggert2025-01-26 23:05:55 -0800
commit1ed769a3cb753a86badba8a2878fa788a6fdc1f8 (patch)
tree3479d096e71014fa8b182480affee76f27f0261f /src
parenta5c47258ffe6d037e3e3c3665ca82a18661cc82c (diff)
downloademacs-1ed769a3cb753a86badba8a2878fa788a6fdc1f8.tar.gz
emacs-1ed769a3cb753a86badba8a2878fa788a6fdc1f8.zip
Pacify -Wanalyzer-use-of-uninitialized-value
With ‘configure --enable-gcc-warnings’, gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7) on x86-64 complained, as it apparently did not want to assume that enum variables have one of the listed values. Work around the problem by using tables rather than switch statements. This gives up a little static checking but I don’t see any other easy way to pacify GCC without disabling the warnings entirely. * src/pdumper.c (dump_fwd_int, dump_fwd_bool, dump_fwd_obj) (dump_fwd_buffer_obj, dump_fwd_kboard_obj): Last arg is now void const * so that these functions’ addresses can all be put into the same array. (dump_fwd, dump_anonymous_allocate_posix, dump_map_file_posix): Use an array rather than a switch. (mem_prot_posix_table): New static constant table.
Diffstat (limited to 'src')
-rw-r--r--src/pdumper.c91
1 files changed, 29 insertions, 62 deletions
diff --git a/src/pdumper.c b/src/pdumper.c
index 45a44db0243..9f0447eb5aa 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2292,11 +2292,12 @@ dump_float (struct dump_context *ctx, const struct Lisp_Float *lfloat)
2292} 2292}
2293 2293
2294static dump_off 2294static dump_off
2295dump_fwd_int (struct dump_context *ctx, const struct Lisp_Intfwd *intfwd) 2295dump_fwd_int (struct dump_context *ctx, void const *fwdptr)
2296{ 2296{
2297#if CHECK_STRUCTS && !defined HASH_Lisp_Intfwd_4D887A7387 2297#if CHECK_STRUCTS && !defined HASH_Lisp_Intfwd_4D887A7387
2298# error "Lisp_Intfwd changed. See CHECK_STRUCTS comment in config.h." 2298# error "Lisp_Intfwd changed. See CHECK_STRUCTS comment in config.h."
2299#endif 2299#endif
2300 struct Lisp_Intfwd const *intfwd = fwdptr;
2300 dump_emacs_reloc_immediate_intmax_t (ctx, intfwd->intvar, *intfwd->intvar); 2301 dump_emacs_reloc_immediate_intmax_t (ctx, intfwd->intvar, *intfwd->intvar);
2301 struct Lisp_Intfwd out; 2302 struct Lisp_Intfwd out;
2302 dump_object_start (ctx, &out, sizeof (out)); 2303 dump_object_start (ctx, &out, sizeof (out));
@@ -2306,11 +2307,12 @@ dump_fwd_int (struct dump_context *ctx, const struct Lisp_Intfwd *intfwd)
2306} 2307}
2307 2308
2308static dump_off 2309static dump_off
2309dump_fwd_bool (struct dump_context *ctx, const struct Lisp_Boolfwd *boolfwd) 2310dump_fwd_bool (struct dump_context *ctx, void const *fwdptr)
2310{ 2311{
2311#if CHECK_STRUCTS && !defined (HASH_Lisp_Boolfwd_0EA1C7ADCC) 2312#if CHECK_STRUCTS && !defined (HASH_Lisp_Boolfwd_0EA1C7ADCC)
2312# error "Lisp_Boolfwd changed. See CHECK_STRUCTS comment in config.h." 2313# error "Lisp_Boolfwd changed. See CHECK_STRUCTS comment in config.h."
2313#endif 2314#endif
2315 struct Lisp_Boolfwd const *boolfwd = fwdptr;
2314 dump_emacs_reloc_immediate_bool (ctx, boolfwd->boolvar, *boolfwd->boolvar); 2316 dump_emacs_reloc_immediate_bool (ctx, boolfwd->boolvar, *boolfwd->boolvar);
2315 struct Lisp_Boolfwd out; 2317 struct Lisp_Boolfwd out;
2316 dump_object_start (ctx, &out, sizeof (out)); 2318 dump_object_start (ctx, &out, sizeof (out));
@@ -2320,11 +2322,12 @@ dump_fwd_bool (struct dump_context *ctx, const struct Lisp_Boolfwd *boolfwd)
2320} 2322}
2321 2323
2322static dump_off 2324static dump_off
2323dump_fwd_obj (struct dump_context *ctx, const struct Lisp_Objfwd *objfwd) 2325dump_fwd_obj (struct dump_context *ctx, void const *fwdptr)
2324{ 2326{
2325#if CHECK_STRUCTS && !defined (HASH_Lisp_Objfwd_45D3E513DC) 2327#if CHECK_STRUCTS && !defined (HASH_Lisp_Objfwd_45D3E513DC)
2326# error "Lisp_Objfwd changed. See CHECK_STRUCTS comment in config.h." 2328# error "Lisp_Objfwd changed. See CHECK_STRUCTS comment in config.h."
2327#endif 2329#endif
2330 struct Lisp_Objfwd const *objfwd = fwdptr;
2328 if (NILP (Fgethash (dump_off_to_lisp (emacs_offset (objfwd->objvar)), 2331 if (NILP (Fgethash (dump_off_to_lisp (emacs_offset (objfwd->objvar)),
2329 ctx->staticpro_table, 2332 ctx->staticpro_table,
2330 Qnil))) 2333 Qnil)))
@@ -2337,12 +2340,12 @@ dump_fwd_obj (struct dump_context *ctx, const struct Lisp_Objfwd *objfwd)
2337} 2340}
2338 2341
2339static dump_off 2342static dump_off
2340dump_fwd_buffer_obj (struct dump_context *ctx, 2343dump_fwd_buffer_obj (struct dump_context *ctx, void const *fwdptr)
2341 const struct Lisp_Buffer_Objfwd *buffer_objfwd)
2342{ 2344{
2343#if CHECK_STRUCTS && !defined (HASH_Lisp_Buffer_Objfwd_611EBD13FF) 2345#if CHECK_STRUCTS && !defined (HASH_Lisp_Buffer_Objfwd_611EBD13FF)
2344# error "Lisp_Buffer_Objfwd changed. See CHECK_STRUCTS comment in config.h." 2346# error "Lisp_Buffer_Objfwd changed. See CHECK_STRUCTS comment in config.h."
2345#endif 2347#endif
2348 struct Lisp_Buffer_Objfwd const *buffer_objfwd = fwdptr;
2346 struct Lisp_Buffer_Objfwd out; 2349 struct Lisp_Buffer_Objfwd out;
2347 dump_object_start (ctx, &out, sizeof (out)); 2350 dump_object_start (ctx, &out, sizeof (out));
2348 DUMP_FIELD_COPY (&out, buffer_objfwd, type); 2351 DUMP_FIELD_COPY (&out, buffer_objfwd, type);
@@ -2353,12 +2356,12 @@ dump_fwd_buffer_obj (struct dump_context *ctx,
2353} 2356}
2354 2357
2355static dump_off 2358static dump_off
2356dump_fwd_kboard_obj (struct dump_context *ctx, 2359dump_fwd_kboard_obj (struct dump_context *ctx, void const *fwdptr)
2357 const struct Lisp_Kboard_Objfwd *kboard_objfwd)
2358{ 2360{
2359#if CHECK_STRUCTS && !defined (HASH_Lisp_Kboard_Objfwd_CAA7E71069) 2361#if CHECK_STRUCTS && !defined (HASH_Lisp_Kboard_Objfwd_CAA7E71069)
2360# error "Lisp_Intfwd changed. See CHECK_STRUCTS comment in config.h." 2362# error "Lisp_Intfwd changed. See CHECK_STRUCTS comment in config.h."
2361#endif 2363#endif
2364 struct Lisp_Kboard_Objfwd const *kboard_objfwd = fwdptr;
2362 struct Lisp_Kboard_Objfwd out; 2365 struct Lisp_Kboard_Objfwd out;
2363 dump_object_start (ctx, &out, sizeof (out)); 2366 dump_object_start (ctx, &out, sizeof (out));
2364 DUMP_FIELD_COPY (&out, kboard_objfwd, type); 2367 DUMP_FIELD_COPY (&out, kboard_objfwd, type);
@@ -2372,29 +2375,16 @@ dump_fwd (struct dump_context *ctx, lispfwd fwd)
2372#if CHECK_STRUCTS && !defined (HASH_Lisp_Fwd_Type_9CBA6EE55E) 2375#if CHECK_STRUCTS && !defined (HASH_Lisp_Fwd_Type_9CBA6EE55E)
2373# error "Lisp_Fwd_Type changed. See CHECK_STRUCTS comment in config.h." 2376# error "Lisp_Fwd_Type changed. See CHECK_STRUCTS comment in config.h."
2374#endif 2377#endif
2375 void const *p = fwd.fwdptr; 2378 typedef dump_off (*dump_fwd_fnptr) (struct dump_context *, void const *);
2376 dump_off offset; 2379 static dump_fwd_fnptr const dump_fwd_table[] = {
2377 2380 [Lisp_Fwd_Int] = dump_fwd_int,
2378 switch (XFWDTYPE (fwd)) 2381 [Lisp_Fwd_Bool] = dump_fwd_bool,
2379 { 2382 [Lisp_Fwd_Obj] = dump_fwd_obj,
2380 case Lisp_Fwd_Int: 2383 [Lisp_Fwd_Buffer_Obj] = dump_fwd_buffer_obj,
2381 offset = dump_fwd_int (ctx, p); 2384 [Lisp_Fwd_Kboard_Obj] = dump_fwd_kboard_obj,
2382 break; 2385 };
2383 case Lisp_Fwd_Bool:
2384 offset = dump_fwd_bool (ctx, p);
2385 break;
2386 case Lisp_Fwd_Obj:
2387 offset = dump_fwd_obj (ctx, p);
2388 break;
2389 case Lisp_Fwd_Buffer_Obj:
2390 offset = dump_fwd_buffer_obj (ctx, p);
2391 break;
2392 case Lisp_Fwd_Kboard_Obj:
2393 offset = dump_fwd_kboard_obj (ctx, p);
2394 break;
2395 }
2396 2386
2397 return offset; 2387 return dump_fwd_table[XFWDTYPE (fwd)] (ctx, fwd.fwdptr);
2398} 2388}
2399 2389
2400static dump_off 2390static dump_off
@@ -4544,26 +4534,19 @@ dump_anonymous_allocate_w32 (void *base,
4544# define MAP_ANONYMOUS MAP_ANON 4534# define MAP_ANONYMOUS MAP_ANON
4545# endif 4535# endif
4546 4536
4537static int const mem_prot_posix_table[] = {
4538 [DUMP_MEMORY_ACCESS_NONE] = PROT_NONE,
4539 [DUMP_MEMORY_ACCESS_READ] = PROT_READ,
4540 [DUMP_MEMORY_ACCESS_READWRITE] = PROT_READ | PROT_WRITE,
4541};
4542
4547static void * 4543static void *
4548dump_anonymous_allocate_posix (void *base, 4544dump_anonymous_allocate_posix (void *base,
4549 size_t size, 4545 size_t size,
4550 enum dump_memory_protection protection) 4546 enum dump_memory_protection protection)
4551{ 4547{
4552 void *ret; 4548 void *ret;
4553 int mem_prot; 4549 int mem_prot = mem_prot_posix_table[protection];
4554
4555 switch (protection)
4556 {
4557 case DUMP_MEMORY_ACCESS_NONE:
4558 mem_prot = PROT_NONE;
4559 break;
4560 case DUMP_MEMORY_ACCESS_READ:
4561 mem_prot = PROT_READ;
4562 break;
4563 case DUMP_MEMORY_ACCESS_READWRITE:
4564 mem_prot = PROT_READ | PROT_WRITE;
4565 break;
4566 }
4567 4550
4568 int mem_flags = MAP_PRIVATE | MAP_ANONYMOUS; 4551 int mem_flags = MAP_PRIVATE | MAP_ANONYMOUS;
4569 if (mem_prot != PROT_NONE) 4552 if (mem_prot != PROT_NONE)
@@ -4707,25 +4690,9 @@ dump_map_file_posix (void *base, int fd, off_t offset, size_t size,
4707 enum dump_memory_protection protection) 4690 enum dump_memory_protection protection)
4708{ 4691{
4709 void *ret; 4692 void *ret;
4710 int mem_prot; 4693 int mem_prot = mem_prot_posix_table[protection];
4711 int mem_flags; 4694 int mem_flags = (protection == DUMP_MEMORY_ACCESS_READWRITE
4712 4695 ? MAP_PRIVATE : MAP_SHARED);
4713 switch (protection)
4714 {
4715 case DUMP_MEMORY_ACCESS_NONE:
4716 mem_prot = PROT_NONE;
4717 mem_flags = MAP_SHARED;
4718 break;
4719 case DUMP_MEMORY_ACCESS_READ:
4720 mem_prot = PROT_READ;
4721 mem_flags = MAP_SHARED;
4722 break;
4723 case DUMP_MEMORY_ACCESS_READWRITE:
4724 mem_prot = PROT_READ | PROT_WRITE;
4725 mem_flags = MAP_PRIVATE;
4726 break;
4727 }
4728
4729 if (base) 4696 if (base)
4730 mem_flags |= MAP_FIXED; 4697 mem_flags |= MAP_FIXED;
4731 4698