aboutsummaryrefslogtreecommitdiffstats
path: root/src/intel/tools/i965_asm.c
diff options
context:
space:
mode:
authorMika Kuoppala <[email protected]>2019-02-20 16:47:01 -0800
committerMatt Turner <[email protected]>2019-05-07 14:33:48 -0700
commit1fb5ce0a11ccb8a0f8d41d0499f8a16b1dfef379 (patch)
treeb0bb9bc3c4f2e321282a652ac379717f2d6798b6 /src/intel/tools/i965_asm.c
parent85da1194ec58447afa49db229edc440a47099c89 (diff)
intel/tools: Initialize offset correctly for i965_asm
If we leave offset uninitialized, access to store will be random depending on stack value and can segfault. Signed-off-by: Mika Kuoppala <[email protected]> Reviewed-by: Sagar Ghuge <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/intel/tools/i965_asm.c')
-rw-r--r--src/intel/tools/i965_asm.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/intel/tools/i965_asm.c b/src/intel/tools/i965_asm.c
index 667f43da0d7..1a53568abb5 100644
--- a/src/intel/tools/i965_asm.c
+++ b/src/intel/tools/i965_asm.c
@@ -29,7 +29,7 @@
extern FILE *yyin;
struct brw_codegen *p;
static int c_literal_output = 0;
-char *input_filename;
+char *input_filename = NULL;
int errors;
static void
@@ -98,7 +98,7 @@ int main(int argc, char **argv)
bool help = false, compact = false;
void *store;
uint64_t pci_id = 0;
- int offset, err;
+ int offset = 0, err;
int start_offset = 0;
struct disasm_info *disasm_info;
struct gen_device_info *devinfo;
@@ -205,13 +205,11 @@ int main(int argc, char **argv)
brw_validate_instructions(p->devinfo, p->store, 0,
p->next_insn_offset, disasm_info);
- int nr_insn = (p->next_insn_offset - start_offset) / 16;
+ const int nr_insn = (p->next_insn_offset - start_offset) / 16;
if (compact)
brw_compact_instructions(p, start_offset, disasm_info);
- ralloc_free(disasm_info);
-
for (int i = 0; i < nr_insn; i++) {
const brw_inst *insn = store + offset;
bool compacted = false;
@@ -226,6 +224,8 @@ int main(int argc, char **argv)
print_instruction(output, compacted, insn);
}
+ ralloc_free(disasm_info);
+
if (c_literal_output)
fprintf(output, "}");
@@ -233,11 +233,8 @@ int main(int argc, char **argv)
goto end;
end:
- if (input_filename)
- free(input_filename);
-
- if (output_file)
- free(output_file);
+ free(input_filename);
+ free(output_file);
if (yyin)
fclose(yyin);