diff --git a/src/frontend/device.c b/src/frontend/device.c index a4ab3cf45..5498d149b 100644 --- a/src/frontend/device.c +++ b/src/frontend/device.c @@ -1124,9 +1124,10 @@ com_alter_common(wordlist *wl, int do_model) /* DIE 2009_02_06 */ char *argument; char **arglist; - int i = 0, step = 0, n, wlen, maxelem = 3; + int step = 0, n, wlen, maxelem = 3; wordlist *wl2 = NULL, *wlin, *rhs; bool eqfound = FALSE; + char *eqptr = NULL; if (!ft_curckt) { fprintf(cp_err, "Error: no circuit loaded\n"); @@ -1152,16 +1153,14 @@ com_alter_common(wordlist *wl, int do_model) while (wl) { argument = wl->wl_word; /* searching for '=' ... */ - i = 0; - while (argument[i] != '=' && argument[i] != '\0') - i++; + eqptr = strchr(argument, '='); /* argument may be '=', then do nothing or =token or token= or token1=token2 ...and if found split argument into three chars and make a new wordlist */ - if (argument[i] != '\0') { + if (eqptr) { /* We found '=' */ eqfound = TRUE; if (strlen(argument) == 1) { @@ -1170,16 +1169,13 @@ com_alter_common(wordlist *wl, int do_model) wl2 = wlin; } else if (strlen(argument) > 1) { arglist = TMALLOC(char*, 4); - arglist[3] = NULL; - arglist[0] = TMALLOC(char, i + 1); - arglist[2] = TMALLOC(char, strlen(&argument[i + 1]) + 1); /* copy argument */ - strncpy(arglist[0], argument, (size_t) i); - arglist[0][i] = '\0'; + arglist[0] = copy_substring(argument, eqptr); /* copy equal sign */ arglist[1] = copy("="); /* copy expression */ - strncpy(arglist[2], &argument[i+1], strlen(&argument[i+1])+1); + arglist[2] = copy(eqptr + 1); + arglist[3] = NULL; /* create a new wordlist from array arglist */ wl2 = wl_build(arglist);