Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a memory overrun which was causing the CI failures. #302

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions mach/proto/mcg/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ static bool istext(char c)
return isprint(c) && (c != '"');
}

void data_block(const uint8_t* data, size_t size, bool is_ro)
void data_block(const uint8_t* data, size_t datalen, size_t size, bool is_ro)
{
const uint8_t* start = data;
const uint8_t* end = data + size;
const uint8_t* end = data + datalen;
const uint8_t* p = data;

emit_header(is_ro ? SECTION_ROM : SECTION_DATA);
Expand All @@ -100,7 +100,9 @@ void data_block(const uint8_t* data, size_t size, bool is_ro)
fprintf(outputfile, "\t.ascii \"");
while (start < p)
{
fprintf(outputfile, "%c", *start);
if ((*start == '\\') || (*start == '"'))
fputc('\\', outputfile);
fputc(*start, outputfile);
start++;
}
fprintf(outputfile, "\"\n");
Expand All @@ -125,6 +127,9 @@ void data_block(const uint8_t* data, size_t size, bool is_ro)
fprintf(outputfile, "\n");
}
}

for (size_t zeroes = 0; zeroes < (size - datalen); zeroes++)
fprintf(outputfile, "\t.data1 0\n");
}

void data_offset(const char* label, arith offset, bool is_ro)
Expand Down
2 changes: 1 addition & 1 deletion mach/proto/mcg/mcg.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extern struct symbol* symbol_walk(symbol_walker_t* walker, void* user);
extern void data_label(const char* name);
extern void data_int(arith data, size_t size, bool is_ro);
extern void data_float(const char* data, size_t size, bool is_ro);
extern void data_block(const uint8_t* data, size_t size, bool is_ro);
extern void data_block(const uint8_t* data, size_t datalen, size_t size, bool is_ro);
extern void data_offset(const char* label, arith offset, bool is_ro);
extern void data_bss(arith size, int init);

Expand Down
2 changes: 1 addition & 1 deletion mach/proto/mcg/parse_em.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static void parse_pseu(void)
}

case str_ptyp:
data_block((const uint8_t*) strdup(em.em_string), em.em_size, ro);
data_block((const uint8_t*) em.em_string, strlen(em.em_string), em.em_size, ro);
break;

case cst_ptyp:
Expand Down
Loading