Refactor key-val pair parsing

This commit is contained in:
Arun Prakash Jana 2020-06-14 00:31:48 +05:30
parent a1ec2236d8
commit b3076e35d6
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 6 additions and 5 deletions

View File

@ -3010,7 +3010,7 @@ static int xlink(char *prefix, char *path, char *curfname, char *buf, int *prese
static bool parsekvpair(kv **arr, char **envcpy, const uchar id, uchar *items) static bool parsekvpair(kv **arr, char **envcpy, const uchar id, uchar *items)
{ {
bool next = TRUE; bool new = TRUE;
const uchar INCR = 8; const uchar INCR = 8;
uint i = 0; uint i = 0;
kv *kvarr = NULL; kv *kvarr = NULL;
@ -3028,7 +3028,7 @@ static bool parsekvpair(kv **arr, char **envcpy, const uchar id, uchar *items)
ptr = *envcpy; ptr = *envcpy;
while (*ptr && i < 100) { while (*ptr && i < 100) {
if (next) { if (new) {
if (!(i & (INCR - 1))) { if (!(i & (INCR - 1))) {
kvarr = xrealloc(kvarr, sizeof(kv) * (i + INCR)); kvarr = xrealloc(kvarr, sizeof(kv) * (i + INCR));
*arr = kvarr; *arr = kvarr;
@ -3043,13 +3043,14 @@ static bool parsekvpair(kv **arr, char **envcpy, const uchar id, uchar *items)
return FALSE; return FALSE;
kvarr[i].off = ptr - *envcpy; kvarr[i].off = ptr - *envcpy;
++i; ++i;
new = FALSE;
} }
if (*ptr == ';') { if (*ptr == ';') {
*ptr = '\0'; *ptr = '\0';
next = TRUE; new = TRUE;
} else if (next) }
next = FALSE;
++ptr; ++ptr;
} }