diff options
author | Adam Jackson <ajax@redhat.com> | 2018-04-05 12:45:51 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2018-04-05 14:18:41 -0400 |
commit | 176f26e96ab9958c84c98c88f31729d0240c420e (patch) | |
tree | d0773d9a4c0d820e682a15c970841ff681102dce /hw/dmx | |
parent | be99072a1a20af44d2457b8c86bd9041f61efa79 (diff) |
dmx: Clean up some argument parsing code
This threw:
../hw/dmx/input/dmxarg.c: In function ‘dmxArgParse’:
../hw/dmx/input/dmxarg.c:128:5: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
strncpy(tmp, string, len);
^~~~~~~~~~~~~~~~~~~~~~~~~
../hw/dmx/input/dmxarg.c:126:11: note: length computed here
len = strlen(string) + 2;
^~~~~~~~~~~~~~
This code predates xstrtokenize, but that's no excuse.
Signed-off-by: Adam Jackson <ajax@redhat.com>
Acked-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'hw/dmx')
-rw-r--r-- | hw/dmx/input/dmxarg.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/hw/dmx/input/dmxarg.c b/hw/dmx/input/dmxarg.c index 6c21ae959..582ed3faa 100644 --- a/hw/dmx/input/dmxarg.c +++ b/hw/dmx/input/dmxarg.c @@ -114,30 +114,17 @@ dmxArgC(dmxArg a) dmxArg dmxArgParse(const char *string) { - char *tmp; - char *start, *pt; + int i = 0; dmxArg a = dmxArgCreate(); - int done; - int len; if (!string) return a; - len = strlen(string) + 2; - tmp = malloc(len); - strncpy(tmp, string, len); - - for (start = pt = tmp, done = 0; !done && *pt; start = ++pt) { - for (; *pt && *pt != ','; pt++); - if (!*pt) - done = 1; - *pt = '\0'; - dmxArgAdd(a, start); - } - if (!done) - dmxArgAdd(a, ""); /* Final comma */ - - free(tmp); + a->argv = (const char **)xstrtokenize(string, ","); + if (a->argv) + for (i = 0; a->argv[i] != NULL; i++); + a->argc = i; + return a; } |