From dec1811d20dc67af9618aff0355b93530f92b194 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Thu, 22 Feb 2024 15:45:09 -0500 Subject: [PATCH] Use automatic allocation for section data --- include/asm/section.hpp | 3 ++- src/asm/output.cpp | 2 +- src/asm/section.cpp | 9 ++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/asm/section.hpp b/include/asm/section.hpp index 6cb1d26a..7212634d 100644 --- a/include/asm/section.hpp +++ b/include/asm/section.hpp @@ -5,6 +5,7 @@ #include #include +#include #include "linkdefs.hpp" #include "platform.hpp" // NONNULL @@ -38,7 +39,7 @@ struct Section { uint8_t align; // Exactly as specified in `ALIGN[]` uint16_t alignOfs; std::deque patches; - uint8_t *data; + std::vector data; }; struct SectionSpec { diff --git a/src/asm/output.cpp b/src/asm/output.cpp index e1042b9e..be9ab8f3 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -135,7 +135,7 @@ static void writesection(struct Section const §, FILE *f) putlong(sect.alignOfs, f); if (sect_HasData(sect.type)) { - fwrite(sect.data, 1, sect.size, f); + fwrite(sect.data.data(), 1, sect.size, f); putlong(sect.patches.size(), f); for (struct Patch const &patch : sect.patches) diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 9cd10782..f60a6fdd 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -286,13 +286,8 @@ static struct Section *createSection(char const *name, enum SectionType type, sect.alignOfs = alignOffset; // It is only needed to allocate memory for ROM sections. - if (sect_HasData(type)) { - sect.data = (uint8_t *)malloc(sectionTypeInfo[type].size); - if (sect.data == NULL) - fatalerror("Not enough memory for section: %s\n", strerror(errno)); - } else { - sect.data = NULL; - } + if (sect_HasData(type)) + sect.data.resize(sectionTypeInfo[type].size); return § }