From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> Simplify the function add_guest by using a local variable to point to the array element instead of dereferencing the array every time. Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- tracecmd/trace-vm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c index 281843b223f6..f0513950aa26 100644 --- a/tracecmd/trace-vm.c +++ b/tracecmd/trace-vm.c @@ -56,18 +56,22 @@ bool trace_have_guests_pid(void) static struct trace_guest *add_guest(unsigned int cid, const char *name) { + struct trace_guest *guest; + guests = realloc(guests, (guests_len + 1) * sizeof(*guests)); if (!guests) die("allocating new guest"); - memset(&guests[guests_len], 0, sizeof(struct trace_guest)); - guests[guests_len].name = strdup(name); - if (!guests[guests_len].name) + + guest = &guests[guests_len++]; + + memset(guest, 0, sizeof(*guest)); + guest->name = strdup(name); + if (!guest->name) die("allocating guest name"); - guests[guests_len].cid = cid; - guests[guests_len].pid = -1; - guests_len++; + guest->cid = cid; + guest->pid = -1; - return &guests[guests_len - 1]; + return guest; } static struct tracefs_instance *start_trace_connect(void) -- 2.35.1