summary refs log tree commit diff stats
path: root/plugins/sysinfo
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-12-11 14:16:29 -0500
committerTingPing <tingping@tingping.se>2014-12-11 14:17:12 -0500
commita537fa3ca7cc7510f74d2a72964f5c9b99ec8beb (patch)
tree9a9b71f3c20de262cc850abc313cf119e87481e4 /plugins/sysinfo
parentf614a3c311f78dceceaa96112a4453746cf622a9 (diff)
sysinfo: Simplify remove_leading_whitespace()
Also fixes a possible overflow
Diffstat (limited to 'plugins/sysinfo')
-rw-r--r--plugins/sysinfo/match.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/plugins/sysinfo/match.c b/plugins/sysinfo/match.c
index f8a8cf96..ae850b5b 100644
--- a/plugins/sysinfo/match.c
+++ b/plugins/sysinfo/match.c
@@ -63,28 +63,15 @@ char *pretty_freespace(const char *desc, unsigned long long *free_k, unsigned lo
 
 void remove_leading_whitespace(char *buffer)
 {
-	char *buffer2 = NULL;
-	int i = 0, j = 0, ews = 0;
+	char *p;
 
-	buffer2 = (char*)malloc(strlen(buffer) * sizeof(char));
-	if (buffer2 == NULL)
+	if (buffer == NULL)
 		return;
 
-	memset (buffer2, (char)0, strlen(buffer));
-	while (i < strlen(buffer))
-	{
-		/* count tabs, spaces as whitespace. */
-		if (!(buffer[i] == (char)32 || buffer[i] == (char)9) || ews == 1)
-		{
-			ews = 1;
-			buffer2[j] = buffer[i];
-			j++;
-		}
-		i++;
-	}
-	memset (buffer, (char)0, strlen(buffer));
-	strcpy (buffer, buffer2);
-	free (buffer2);
+	for (p = buffer; *p && isspace (*p); p++)
+	;
+
+	memmove (buffer, p, strlen (p) + 1);
 }
 
 char *decruft_filename(char *buffer)