diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-23 22:40:30 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-23 22:40:30 +0300 |
commit | 29987adf34007c0fc60971db7746ea0815b0808a (patch) | |
tree | 10cc2eb8f91c6b547b272c20bb891d86e92e6710 /src | |
parent | 7231cb962e14a439635af60ecb94dec9b694c2e9 (diff) |
memview: store unknown region in named array
This makes view referseshes work without special casing
Diffstat (limited to 'src')
-rw-r--r-- | src/memview.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/memview.c b/src/memview.c index bd22305..49a503b 100644 --- a/src/memview.c +++ b/src/memview.c @@ -211,12 +211,6 @@ offset_is_in_named_region(const size_t offset, const struct named_region *named) static const struct named_region* named_region_for_offset(const size_t offset, const bool set_active) { - static struct named_region unknown; - unknown = (struct named_region){ .region = { .start = offset, .end = offset + 1 }, .name = "unknown" }; - - if (!ctx.num_regions) - return &unknown; - if (offset_is_in_named_region(offset, &ctx.named[ctx.active_region])) return &ctx.named[ctx.active_region]; @@ -233,7 +227,8 @@ named_region_for_offset(const size_t offset, const bool set_active) } } - return &unknown; + ctx.named[0].region = (struct region){ .start = offset, .end = offset + 1 }; + return &ctx.named[(ctx.active_region = 0)]; } static size_t @@ -787,7 +782,7 @@ write_bytes(void *arg) static void quit(void) { - for (size_t i = 0; i < ctx.num_regions; ++i) + for (size_t i = 1; i < ctx.num_regions; ++i) free((char*)ctx.named[i].name); mem_io_release(&ctx.io); @@ -896,9 +891,11 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "fopen(%s)", path); } + ctx.num_regions = 1; mem_io_uio_init(&ctx.io, pid); for_each_token_in_file(regions_file, '\n', region_cb, NULL); fclose(regions_file); + ctx.named[0] = (struct named_region){ .name = "unknown" }; ctx.hexview.offset = ctx.named[ctx.active_region].region.start; init(); |