From: Po Lu Date: Sat, 2 Apr 2022 08:38:19 +0000 (+0800) Subject: Compute size of structs with flexible arrays correctly in Motif DND code X-Git-Tag: emacs-29.0.90~1931^2~821 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f66a47b5bca7a9c603040b7c62a2562a925c94d3;p=emacs.git Compute size of structs with flexible arrays correctly in Motif DND code * src/xterm.c (xm_read_targets_table_rec, xm_setup_dnd_targets): Use FLEXSIZEOF instead of sizeof on struct xm_targets_table_rec. --- diff --git a/src/xterm.c b/src/xterm.c index 48c054c478e..08e3a956336 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -604,6 +604,7 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include #include "character.h" #include "coding.h" #include "composite.h" @@ -1135,7 +1136,8 @@ xm_read_targets_table_rec (uint8_t *bytes, ptrdiff_t length, if (byteorder != XM_TARGETS_TABLE_CUR) SWAPCARD16 (nitems); - rec = xmalloc (sizeof *rec + nitems * 4); + rec = xmalloc (FLEXSIZEOF (struct xm_targets_table_rec, + targets, nitems * 4)); rec->n_targets = nitems; for (i = 0; i < nitems; ++i) @@ -1428,7 +1430,8 @@ xm_setup_dnd_targets (struct x_display_info *dpyinfo, header.total_data_size = 8 + 2 + ntargets * 4; recs = xmalloc (sizeof *recs); - recs[0] = xmalloc (sizeof **recs + ntargets * 4); + recs[0] = xmalloc (FLEXSIZEOF (struct xm_targets_table_rec, + targets, ntargets * 4)); recs[0]->n_targets = ntargets; @@ -1448,7 +1451,9 @@ xm_setup_dnd_targets (struct x_display_info *dpyinfo, header.target_list_count++; header.total_data_size += 2 + ntargets * 4; - recs[header.target_list_count - 1] = xmalloc (sizeof **recs + ntargets * 4); + recs[header.target_list_count - 1] + = xmalloc (FLEXSIZEOF (struct xm_targets_table_rec, + targets, ntargets * 4)); recs[header.target_list_count - 1]->n_targets = ntargets; for (i = 0; i < ntargets; ++i)