sysinfo: Simplify remove_leading_whitespace()

Also fixes a possible overflow
This commit is contained in:
TingPing 2014-12-11 14:16:29 -05:00
parent f614a3c311
commit a537fa3ca7

View File

@ -63,28 +63,15 @@ char *pretty_freespace(const char *desc, unsigned long long *free_k, unsigned lo
void remove_leading_whitespace(char *buffer) void remove_leading_whitespace(char *buffer)
{ {
char *buffer2 = NULL; char *p;
int i = 0, j = 0, ews = 0;
buffer2 = (char*)malloc(strlen(buffer) * sizeof(char)); if (buffer == NULL)
if (buffer2 == NULL)
return; return;
memset (buffer2, (char)0, strlen(buffer)); for (p = buffer; *p && isspace (*p); p++)
while (i < strlen(buffer)) ;
{
/* count tabs, spaces as whitespace. */ memmove (buffer, p, strlen (p) + 1);
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);
} }
char *decruft_filename(char *buffer) char *decruft_filename(char *buffer)