Skip to content

Commit

Permalink
Changes made to find_proc_cmdline_key
Browse files Browse the repository at this point in the history
Used strspn based on feedback from similar function.
  • Loading branch information
ericcurtin committed Aug 22, 2023
1 parent 0cead3a commit 0f0f0a9
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/switchroot/ostree-mount-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,27 @@ cleanup_free (void *p)
static inline char *
find_proc_cmdline_key (const char *cmdline, const char *key)
{
char *ret = NULL;
size_t key_len = strlen (key);

const char *iter = cmdline;
while (iter != NULL)
const size_t key_len = strlen (key);
for (const char *iter = cmdline; iter;)
{
const char *next = strchr (iter, ' ');
const char *next_nonspc = next;
while (next_nonspc && *next_nonspc == ' ')
next_nonspc += 1;
if (next == NULL)
break;

if (strncmp (iter, key, key_len) == 0 && iter[key_len] == '=')
{
const char *start = iter + key_len + 1;
if (next)
ret = strndup (start, next - start);
else
ret = strdup (start);
break;
return strndup (start, next - start);

return strdup (start);
}
iter = next_nonspc;

next += strspn (next, " \t\n\r");
iter = next;
}

return ret;
return NULL;
}

/* This is an API for other projects to determine whether or not the
Expand Down

0 comments on commit 0f0f0a9

Please sign in to comment.