From 7a1777302ff21bbc7cd81a1141f9c88c8fac2511 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 18 Apr 2014 15:17:57 +0200 Subject: [PATCH] cleanup: dmeventd simplify restart message parsing Since we already check every characted in the message, skip extra callback to strlen, and do the implicit message length checking. --- daemons/dmeventd/dmeventd.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index 7decbcb11..dcde7b10f 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -1918,7 +1918,6 @@ static void restart(void) struct dm_event_daemon_message msg = { 0 }; int i, count = 0; char *message; - int length; int version; const char *e; @@ -1943,16 +1942,12 @@ static void restart(void) if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0)) goto bad; - message = msg.data; - message = strchr(message, ' '); - ++ message; - length = strlen(msg.data); - for (i = 0; i < length; ++i) { + message = strchr(msg.data, ' ') + 1; + for (i = 0; msg.data[i]; ++i) if (msg.data[i] == ';') { msg.data[i] = 0; ++count; } - } if (!(_initial_registrations = dm_malloc(sizeof(char*) * (count + 1)))) { fprintf(stderr, "Memory allocation registration failed.\n");