diff options
| author | Po Lu | 2022-04-02 16:38:19 +0800 |
|---|---|---|
| committer | Po Lu | 2022-04-02 16:38:19 +0800 |
| commit | f66a47b5bca7a9c603040b7c62a2562a925c94d3 (patch) | |
| tree | 62ec3f4f0b67c37f54ecf53cc78cf60fa477b054 /src | |
| parent | b312959ebd528b01e95fe5eca71cc3890a97421d (diff) | |
| download | emacs-f66a47b5bca7a9c603040b7c62a2562a925c94d3.tar.gz emacs-f66a47b5bca7a9c603040b7c62a2562a925c94d3.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 11 |
1 files changed, 8 insertions, 3 deletions
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 <https://www.gnu.org/licenses/>. */ | |||
| 604 | #include <fcntl.h> | 604 | #include <fcntl.h> |
| 605 | #include <errno.h> | 605 | #include <errno.h> |
| 606 | #include <sys/stat.h> | 606 | #include <sys/stat.h> |
| 607 | #include <flexmember.h> | ||
| 607 | #include "character.h" | 608 | #include "character.h" |
| 608 | #include "coding.h" | 609 | #include "coding.h" |
| 609 | #include "composite.h" | 610 | #include "composite.h" |
| @@ -1135,7 +1136,8 @@ xm_read_targets_table_rec (uint8_t *bytes, ptrdiff_t length, | |||
| 1135 | if (byteorder != XM_TARGETS_TABLE_CUR) | 1136 | if (byteorder != XM_TARGETS_TABLE_CUR) |
| 1136 | SWAPCARD16 (nitems); | 1137 | SWAPCARD16 (nitems); |
| 1137 | 1138 | ||
| 1138 | rec = xmalloc (sizeof *rec + nitems * 4); | 1139 | rec = xmalloc (FLEXSIZEOF (struct xm_targets_table_rec, |
| 1140 | targets, nitems * 4)); | ||
| 1139 | rec->n_targets = nitems; | 1141 | rec->n_targets = nitems; |
| 1140 | 1142 | ||
| 1141 | for (i = 0; i < nitems; ++i) | 1143 | for (i = 0; i < nitems; ++i) |
| @@ -1428,7 +1430,8 @@ xm_setup_dnd_targets (struct x_display_info *dpyinfo, | |||
| 1428 | header.total_data_size = 8 + 2 + ntargets * 4; | 1430 | header.total_data_size = 8 + 2 + ntargets * 4; |
| 1429 | 1431 | ||
| 1430 | recs = xmalloc (sizeof *recs); | 1432 | recs = xmalloc (sizeof *recs); |
| 1431 | recs[0] = xmalloc (sizeof **recs + ntargets * 4); | 1433 | recs[0] = xmalloc (FLEXSIZEOF (struct xm_targets_table_rec, |
| 1434 | targets, ntargets * 4)); | ||
| 1432 | 1435 | ||
| 1433 | recs[0]->n_targets = ntargets; | 1436 | recs[0]->n_targets = ntargets; |
| 1434 | 1437 | ||
| @@ -1448,7 +1451,9 @@ xm_setup_dnd_targets (struct x_display_info *dpyinfo, | |||
| 1448 | header.target_list_count++; | 1451 | header.target_list_count++; |
| 1449 | header.total_data_size += 2 + ntargets * 4; | 1452 | header.total_data_size += 2 + ntargets * 4; |
| 1450 | 1453 | ||
| 1451 | recs[header.target_list_count - 1] = xmalloc (sizeof **recs + ntargets * 4); | 1454 | recs[header.target_list_count - 1] |
| 1455 | = xmalloc (FLEXSIZEOF (struct xm_targets_table_rec, | ||
| 1456 | targets, ntargets * 4)); | ||
| 1452 | recs[header.target_list_count - 1]->n_targets = ntargets; | 1457 | recs[header.target_list_count - 1]->n_targets = ntargets; |
| 1453 | 1458 | ||
| 1454 | for (i = 0; i < ntargets; ++i) | 1459 | for (i = 0; i < ntargets; ++i) |