From c5a6147a1be440c2d5457f392775e583b2eba8f3 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 8 Jun 2015 15:56:33 +0100 Subject: overlay: Fix parsing of gem-objects for '[k]' clients Apparently '[]' are not non-whitespace characters and break '%s'. Signed-off-by: Chris Wilson --- overlay/gem-objects.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'overlay') diff --git a/overlay/gem-objects.c b/overlay/gem-objects.c index 4d60299a..8ecc61f5 100644 --- a/overlay/gem-objects.c +++ b/overlay/gem-objects.c @@ -137,8 +137,11 @@ int gem_objects_update(struct gem_objects *obj) while (*b != '\n') b--; + b++; do { + char *eol, *colon; + comm = freed; if (comm) freed = comm->next; @@ -148,11 +151,23 @@ int gem_objects_update(struct gem_objects *obj) break; /* Xorg: 35 objects, 16347136 bytes (0 active, 12103680 inactive, 0 unbound) */ - sscanf(++b, "%256s %lu objects, %lu bytes", - comm->name, &comm->count, &comm->bytes); + eol = strchr(b, '\n'); + if (eol) { + do { + *eol++ = '\0'; + } while (*eol == '\n'); + } + + colon = strchr(b, ':'); + memcpy(comm->name, b, colon-b+1); + comm->name[colon-b+1] = '\0'; + + sscanf(colon + 1, "%lu objects, %lu bytes", + &comm->count, &comm->bytes); insert_sorted(obj, comm); - } while ((b = strchr(b, '\n')) != NULL); + b = eol; + } while (b != NULL); done: while (freed) { -- cgit v1.2.3