aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2025-03-02 15:57:14 -0800
committerPaul Eggert2025-03-02 15:58:04 -0800
commit76342efe9d758a6ca66cdc0ed197381664a6fbbd (patch)
treee73b473b36d6ecdf6864c6eae0f32d26fb49d368
parent07bbfea901a71a89d54129ee690e71e9a79b7720 (diff)
downloademacs-76342efe9d758a6ca66cdc0ed197381664a6fbbd.tar.gz
emacs-76342efe9d758a6ca66cdc0ed197381664a6fbbd.zip
Pacify GCC in pgtkselect malloc alignment
This is a better fix for Bug#76414. * src/pgtkselect.c (pgtk_nalloc): New function. (pgtk_get_window_property, lisp_data_to_selection_data): Use it.
-rw-r--r--src/pgtkselect.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/pgtkselect.c b/src/pgtkselect.c
index c05594d7366..7e314df8921 100644
--- a/src/pgtkselect.c
+++ b/src/pgtkselect.c
@@ -57,6 +57,17 @@ static void lisp_data_to_selection_data (struct pgtk_display_info *, Lisp_Object
57static Lisp_Object pgtk_get_local_selection (Lisp_Object, Lisp_Object, 57static Lisp_Object pgtk_get_local_selection (Lisp_Object, Lisp_Object,
58 bool, struct pgtk_display_info *); 58 bool, struct pgtk_display_info *);
59 59
60/* Allocate an array of NITEMS items, each of positive size ITEM_SIZE.
61 Make room for an extra byte at the end, as GDK sometimes needs that. */
62
63static void *
64pgtk_nalloc (ptrdiff_t nitems, ptrdiff_t item_size)
65{
66 /* To pacify gcc --Wanalyzer-allocation-size, make room for an extra
67 item at the end instead of just the extra byte GDK sometimes needs. */
68 return xnmalloc (nitems + 1, item_size);
69}
70
60/* From a Lisp_Object, return a suitable frame for selection 71/* From a Lisp_Object, return a suitable frame for selection
61 operations. OBJECT may be a frame, a terminal object, or nil 72 operations. OBJECT may be a frame, a terminal object, or nil
62 (which stands for the selected frame--or, if that is not an pgtk 73 (which stands for the selected frame--or, if that is not an pgtk
@@ -1129,7 +1140,7 @@ pgtk_get_window_property (GdkWindow *window, unsigned char **data_ret,
1129 eassert (actual_format == 32); 1140 eassert (actual_format == 32);
1130 1141
1131 length = length / sizeof (GdkAtom); 1142 length = length / sizeof (GdkAtom);
1132 xdata = xmalloc (sizeof (GdkAtom) * length + 1); 1143 xdata = pgtk_nalloc (length, sizeof (GdkAtom));
1133 memcpy (xdata, data, 1 + length * sizeof (GdkAtom)); 1144 memcpy (xdata, data, 1 + length * sizeof (GdkAtom));
1134 1145
1135 g_free (data); 1146 g_free (data);
@@ -1145,10 +1156,7 @@ pgtk_get_window_property (GdkWindow *window, unsigned char **data_ret,
1145 1156
1146 element_size = pgtk_size_for_format (actual_format); 1157 element_size = pgtk_size_for_format (actual_format);
1147 length = length / element_size; 1158 length = length / element_size;
1148 1159 xdata = pgtk_nalloc (length, element_size);
1149 /* Add an extra byte on the end. GDK guarantees that it is
1150 NULL. */
1151 xdata = xmalloc (1 + element_size * length);
1152 memcpy (xdata, data, 1 + element_size * length); 1160 memcpy (xdata, data, 1 + element_size * length);
1153 1161
1154 if (actual_format == 32 && LONG_WIDTH > 32) 1162 if (actual_format == 32 && LONG_WIDTH > 32)
@@ -1437,7 +1445,7 @@ lisp_data_to_selection_data (struct pgtk_display_info *dpyinfo,
1437 } 1445 }
1438 else if (SYMBOLP (obj)) 1446 else if (SYMBOLP (obj))
1439 { 1447 {
1440 void *data = xmalloc (sizeof (GdkAtom) + 1); 1448 void *data = pgtk_nalloc (1, sizeof (GdkAtom));
1441 GdkAtom *x_atom_ptr = data; 1449 GdkAtom *x_atom_ptr = data;
1442 cs->data = data; 1450 cs->data = data;
1443 cs->format = 32; 1451 cs->format = 32;
@@ -1448,7 +1456,7 @@ lisp_data_to_selection_data (struct pgtk_display_info *dpyinfo,
1448 } 1456 }
1449 else if (RANGED_FIXNUMP (SHRT_MIN, obj, SHRT_MAX)) 1457 else if (RANGED_FIXNUMP (SHRT_MIN, obj, SHRT_MAX))
1450 { 1458 {
1451 void *data = xmalloc (sizeof (short) + 1); 1459 void *data = pgtk_nalloc (1, sizeof (short));
1452 short *short_ptr = data; 1460 short *short_ptr = data;
1453 cs->data = data; 1461 cs->data = data;
1454 cs->format = 16; 1462 cs->format = 16;
@@ -1463,7 +1471,7 @@ lisp_data_to_selection_data (struct pgtk_display_info *dpyinfo,
1463 || (CONSP (XCDR (obj)) 1471 || (CONSP (XCDR (obj))
1464 && FIXNUMP (XCAR (XCDR (obj))))))) 1472 && FIXNUMP (XCAR (XCDR (obj)))))))
1465 { 1473 {
1466 void *data = xmalloc (sizeof (unsigned long) + 1); 1474 void *data = pgtk_nalloc (1, sizeof (unsigned long));
1467 unsigned long *x_long_ptr = data; 1475 unsigned long *x_long_ptr = data;
1468 cs->data = data; 1476 cs->data = data;
1469 cs->format = 32; 1477 cs->format = 32;