codebase-wide: use flexible arrays where appropriate

In platforms with bounds-checking enabled, placeholder values for array sizes in structs that may be exceeded always result in a sigtrap.

This patch updates the following classes to use flexible arrays at the end of structs:
- database
  - Label
  - PropertyRecord (union of three flexible arrays and a pointer*)
  - cellUE
- extflat
  - HierName
  - EFAttr
  - Dev
- utils
  - HashEntry (union of two flexible arrays and a pointer*)
   - internalUndoEvent: Was a plain int, replaced with a flexible char array

Additionally, the database struct editUE, which would have just a single flexible-array member, was removed and simply replaced with a character pointer.

Where possible, allocation size macros have been introduced.

---

* It is noted flexible-length arrays as part of unions are not part of the C language spec and are a GNU99 extension, however, it is supported by both GCC and Clang.
This commit is contained in:
Mohamed Gaber
2026-07-01 12:37:44 -04:00
committed by R. Timothy Edwards
parent dc2ecf35f8
commit 6638949233
20 changed files with 132 additions and 152 deletions
+9 -11
View File
@@ -2567,8 +2567,7 @@ CmdDoProperty(
if (proptype == PROPERTY_TYPE_STRING)
{
proplen = strlen(cmd->tx_argv[argstart + 1]);
proprec = (PropertyRecord *)mallocMagic(sizeof(PropertyRecord) -
7 + proplen);
proprec = (PropertyRecord *)mallocMagic(strPropertyRecordSize(proplen));
proprec->prop_type = proptype;
proprec->prop_len = proplen;
strcpy(proprec->prop_value.prop_string, cmd->tx_argv[argstart + 1]);
@@ -2586,17 +2585,17 @@ CmdDoProperty(
{
proplen = locargc - 2;
if (proptype == PROPERTY_TYPE_DOUBLE)
proprec = (PropertyRecord *)mallocMagic(sizeof(PropertyRecord) +
(proplen - 1)*sizeof(dlong));
proprec = (PropertyRecord *)mallocMagic(
dlongPropertyRecordSize(proplen));
else if (proptype == PROPERTY_TYPE_PLANE)
{
proprec = (PropertyRecord *)mallocMagic(sizeof(PropertyRecord));
plane = DBNewPlane((ClientData)TT_SPACE);
proprec->prop_value.prop_plane = plane;
plane = DBNewPlane((ClientData)TT_SPACE);
proprec->prop_value.prop_plane = plane;
}
else
proprec = (PropertyRecord *)mallocMagic(sizeof(PropertyRecord) +
(proplen - 2)*sizeof(int));
proprec = (PropertyRecord *)mallocMagic(
intPropertyRecordSize(proplen));
proprec->prop_type = proptype;
proprec->prop_len = proplen;
@@ -2680,9 +2679,8 @@ CmdDoProperty(
plane = DBNewPlane((ClientData)TT_SPACE);
proprec->prop_value.prop_plane = plane;
} else {
proprec = (PropertyRecord *)mallocMagic(
sizeof(PropertyRecord) +
(proplen - 2) * sizeof(int));
proprec = (PropertyRecord *)mallocMagic(
intPropertyRecordSize(proplen));
}
proprec->prop_type = proptype;
proprec->prop_len = proplen;