There's not much to like about this function's implementation. The few scan-build warnings specific to this particular function suggested it should be put to pasture and replaced with something better.
Signed-off-by: Jason Gerecke <killert...@gmail.com> --- tools/xsetwacom.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c index 9c0f65b..614d476 100644 --- a/tools/xsetwacom.c +++ b/tools/xsetwacom.c @@ -44,6 +44,9 @@ #define TRACE(...) \ if (verbose) fprintf(stderr, "... " __VA_ARGS__) +#define safe_realloc(p, n, s) \ + ((size_t)-1 / (n) < (s) ? NULL : realloc((p), (n)*(s))) + static int verbose = False; enum printformat { @@ -1191,36 +1194,24 @@ static int special_map_keystrokes(Display *dpy, int argc, char **argv, unsigned */ static char** strjoinsplit(int argc, char **argv, int *nwords) { - char buff[1024] = { 0 }; - char **words = NULL; - char *tmp, *tok; - - while(argc--) - { - if (strlen(buff) + strlen(*argv) + 2 >= sizeof(buff)) - break; - - strcat(buff, *argv); - strcat(buff, " "); - argv++; - } + char **words = NULL; + int i, n; *nwords = 0; + for (i = 0; i < argc; i++) { + char *tok = strtok(argv[i], " "); + while (tok) { + char **p = safe_realloc(words, *nwords+1, sizeof(char*)); + if (!p) { + fprintf(stderr, "Unable to reallocate memory."); + break; + } - for (tmp = buff; tmp && *tmp != '\0'; tmp = index((const char*)tmp, ' ') + 1) - (*nwords)++; - - if (!*nwords) - return NULL; - else - words = calloc(*nwords, sizeof(char*)); - - *nwords = 0; - tok = strtok(buff, " "); - while(tok) - { - words[(*nwords)++] = strdup(tok); - tok = strtok(NULL, " "); + words = p; + words[*nwords] = strdup(tok); + (*nwords)++; + tok = strtok(NULL, " "); + } } return words; -- 2.1.0 ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel