From 0dec2289211dd75e2dd99e4aad84ece845e69864 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 22 Sep 2015 15:45:50 -0700 Subject: [PATCH] Clean up /proc//maps sscanfs. sscanf will swallow whitespace for us. Change-Id: I59931cbad00f0144fd33ed4749ac0aaad15e6de6 --- libc/bionic/debug_mapinfo.cpp | 5 +---- tests/pthread_test.cpp | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libc/bionic/debug_mapinfo.cpp b/libc/bionic/debug_mapinfo.cpp index de72cb291..6fb8ebea3 100644 --- a/libc/bionic/debug_mapinfo.cpp +++ b/libc/bionic/debug_mapinfo.cpp @@ -50,14 +50,11 @@ static mapinfo_t* parse_maps_line(char* line) { uintptr_t offset; char permissions[4]; int name_pos; - if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %*x:%*x %*d%n", &start, + if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %*x:%*x %*d %n", &start, &end, permissions, &offset, &name_pos) < 2) { return NULL; } - while (isspace(line[name_pos])) { - name_pos += 1; - } const char* name = line + name_pos; size_t name_len = strlen(name); if (name_len && name[name_len - 1] == '\n') { diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp index 11afad141..d61c1cd5e 100644 --- a/tests/pthread_test.cpp +++ b/tests/pthread_test.cpp @@ -1163,9 +1163,9 @@ TEST(pthread, pthread_attr_getstack__main_thread) { char line[BUFSIZ]; while (fgets(line, sizeof(line), fp) != NULL) { uintptr_t lo, hi; - char name[10]; - sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d %10s", &lo, &hi, name); - if (strcmp(name, "[stack]") == 0) { + int name_pos; + sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d %n", &lo, &hi, &name_pos); + if (strcmp(line + name_pos, "[stack]\n") == 0) { maps_stack_hi = reinterpret_cast(hi); break; } -- 2.11.0