fix @embedFile reading garbage memory

closes #1547
master
Andrew Kelley 2018-09-18 10:25:37 -04:00
parent 93ff5024a4
commit 1fc2019031
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
1 changed files with 5 additions and 4 deletions

View File

@ -18187,17 +18187,18 @@ static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionE
&source_dir_path,
rel_file_path,
};
Buf file_path = os_path_resolve(resolve_paths, 2);
Buf *file_path = buf_alloc();
*file_path = os_path_resolve(resolve_paths, 2);
// load from file system into const expr
Buf *file_contents = buf_alloc();
int err;
if ((err = file_fetch(ira->codegen, &file_path, file_contents))) {
if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
if (err == ErrorFileNotFound) {
ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(&file_path)));
ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
return ira->codegen->builtin_types.entry_invalid;
} else {
ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(&file_path), err_str(err)));
ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
return ira->codegen->builtin_types.entry_invalid;
}
}