Skip to content

Commit 87f17c0

Browse files
author
Noam Preil
committed
Detect error in linker
1 parent e659c24 commit 87f17c0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

linker/linker.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,13 @@ void link_objects(FILE *output, list_t *objects, linker_settings_t *settings) {
160160
list_t *symbols = create_list(); // TODO: Use a hash table
161161

162162
/* Create a new area for relocatable references */
163-
area_t *runtime;
163+
area_t *runtime = NULL;
164164
if (settings->automatic_relocation) {
165165
const char *sym_name = "__scas_relocatable_data";
166166
runtime = create_area("__scas_relocatable");
167167
symbol_t *sym = malloc(sizeof(symbol_t));
168168
sym->type = SYMBOL_LABEL;
169-
sym->name = malloc(strlen(sym_name) + 1);
170-
strcpy(sym->name, sym_name);
169+
sym->name = strdup(sym_name);
171170
sym->value = 0;
172171
sym->defined_address = 0;
173172
sym->exported = 0;
@@ -178,6 +177,11 @@ void link_objects(FILE *output, list_t *objects, linker_settings_t *settings) {
178177
}
179178

180179
object_t *merged = merge_objects(objects);
180+
if (!merged) {
181+
list_free(symbols);
182+
return;
183+
}
184+
181185
area_t *final = create_area("FINAL");
182186

183187
runtime = get_area_by_name(merged, "__scas_relocatable");

0 commit comments

Comments
 (0)