diff --git a/include/asm/output.hpp b/include/asm/output.hpp index bfe0793f..c548c906 100644 --- a/include/asm/output.hpp +++ b/include/asm/output.hpp @@ -18,7 +18,7 @@ void out_RegisterNode(struct FileStackNode *node); void out_ReplaceNode(struct FileStackNode *node); void out_SetFileName(char *s); void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs, uint32_t pcShift); -bool out_CreateAssert(enum AssertionType type, struct Expression const *expr, +void out_CreateAssert(enum AssertionType type, struct Expression const *expr, char const *message, uint32_t ofs); void out_WriteObject(void); diff --git a/src/asm/output.cpp b/src/asm/output.cpp index aa41be34..71738e34 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -40,7 +41,7 @@ struct Patch { struct Assertion { struct Patch *patch; struct Section *section; - char *message; + std::string message; }; const char *objectName; @@ -50,7 +51,7 @@ std::deque sectionList; // List of symbols to put in the object file static std::vector objectSymbols; -static std::deque assertions; +static std::deque assertions; static std::deque fileStackNodes; @@ -352,37 +353,26 @@ void out_CreatePatch(uint32_t type, struct Expression const *expr, uint32_t ofs, } // Creates an assert that will be written to the object file -bool out_CreateAssert(enum AssertionType type, struct Expression const *expr, +void out_CreateAssert(enum AssertionType type, struct Expression const *expr, char const *message, uint32_t ofs) { - struct Assertion *assertion = (struct Assertion *)malloc(sizeof(*assertion)); - - if (!assertion) - return false; - - assertion->patch = allocpatch(type, expr, ofs); - assertion->message = strdup(message); - if (!assertion->message) { - free(assertion); - return false; - } - - assertions.push_front(assertion); - - return true; + assertions.push_front({ + .patch = allocpatch(type, expr, ofs), + .section = NULL, + .message = message, + }); } -static void writeassert(struct Assertion *assert, FILE *f) +static void writeassert(struct Assertion &assert, FILE *f) { - writepatch(assert->patch, f); - putstring(assert->message, f); + writepatch(assert.patch, f); + putstring(assert.message.c_str(), f); } -static void freeassert(struct Assertion *assert) +static void freeassert(struct Assertion &assert) { - free(assert->patch->rpn); - free(assert->patch); - free(assert); + free(assert.patch->rpn); + free(assert.patch); } static void writeFileStackNode(struct FileStackNode const *node, FILE *f) @@ -456,7 +446,7 @@ void out_WriteObject(void) putlong(assertions.size(), f); - for (struct Assertion *assert : assertions) { + for (struct Assertion &assert : assertions) { writeassert(assert, f); freeassert(assert); } diff --git a/src/asm/parser.y b/src/asm/parser.y index dbd71f27..013f7161 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -1089,10 +1089,7 @@ assert_type : %empty { $$ = ASSERT_ERROR; } assert : T_POP_ASSERT assert_type relocexpr { if (!rpn_isKnown(&$3)) { - if (!out_CreateAssert($2, &$3, "", - sect_GetOutputOffset())) - error("Assertion creation failed: %s\n", - strerror(errno)); + out_CreateAssert($2, &$3, "", sect_GetOutputOffset()); } else if ($3.val == 0) { failAssert($2); } @@ -1100,10 +1097,7 @@ assert : T_POP_ASSERT assert_type relocexpr { } | T_POP_ASSERT assert_type relocexpr T_COMMA string { if (!rpn_isKnown(&$3)) { - if (!out_CreateAssert($2, &$3, $5, - sect_GetOutputOffset())) - error("Assertion creation failed: %s\n", - strerror(errno)); + out_CreateAssert($2, &$3, $5, sect_GetOutputOffset()); } else if ($3.val == 0) { failAssertMsg($2, $5); }