From 42843e2c444edc98632e8e5b8073c184332bdd94 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Tue, 23 Oct 2018 20:29:13 +0300 Subject: memview: Fix region names The old way failed for spaces, this is much better anyways --- src/memview.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/memview.c b/src/memview.c index e9a9d10..c64d9fd 100644 --- a/src/memview.c +++ b/src/memview.c @@ -764,6 +764,13 @@ basename(const char *path) return (base ? base + 1 : path); } +static const char* +skip_ws(const char *str) +{ + const size_t skipped = strspn(str, " \t\n"); + return str + skipped; +} + static void region_cb(const char *line, void *data) { @@ -777,10 +784,9 @@ region_cb(const char *line, void *data) if (!region_parse(&ctx.named[ctx.num_regions].region, line)) return; - char path[255] = {0}; int region_len_without_name = strlen(line); - sscanf(line, "%*s %*s %*s %*s %*s%n %254s", ®ion_len_without_name, path); - const char *base = basename(path); + sscanf(line, "%*s %*s %*s %*s %*s%n", ®ion_len_without_name); + const char *base = basename(skip_ws(line + region_len_without_name)); char *name; size_t name_sz = region_len_without_name + 1 + strlen(base) + 1; -- cgit v1.2.3