]> git.eshelyaron.com Git - emacs.git/commitdiff
Compute size of structs with flexible arrays correctly in Motif DND code
authorPo Lu <luangruo@yahoo.com>
Sat, 2 Apr 2022 08:38:19 +0000 (16:38 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 2 Apr 2022 08:38:19 +0000 (16:38 +0800)
* src/xterm.c (xm_read_targets_table_rec, xm_setup_dnd_targets):
Use FLEXSIZEOF instead of sizeof on struct xm_targets_table_rec.

src/xterm.c

index 48c054c478ed4cbacc9f4f48a702c174ea8d2a2e..08e3a956336aa9e320180ddad6bc22cd478ee021 100644 (file)
@@ -604,6 +604,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <flexmember.h>
 #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)