fix procfs_pargs in the case of an empty argument

This commit is contained in:
Doug MacEachern 2006-04-03 02:17:54 +00:00
parent dbe0355f70
commit 933b7734a6
1 changed files with 3 additions and 4 deletions

View File

@ -269,7 +269,7 @@ int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid,
buf[total] = '\0'; buf[total] = '\0';
ptr = buf; ptr = buf;
while (*ptr) { while (total > 0) {
int alen = strlen(ptr)+1; int alen = strlen(ptr)+1;
char *arg = malloc(alen); char *arg = malloc(alen);
@ -279,11 +279,10 @@ int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid,
procargs->data[procargs->number++] = arg; procargs->data[procargs->number++] = arg;
total -= alen; total -= alen;
if (total <= 0) { if (total > 0) {
break;
}
ptr += alen; ptr += alen;
} }
}
free(buf); free(buf);