diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-03-05 17:48:54 +0100 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-03-05 17:49:27 +0100 |
commit | 0e5a9f16201a926856668b3c6b2be1c69696009d (patch) | |
tree | df8fe60b12af7fad2ef8dab0d07a10010ec894f1 | |
parent | a7787067919d28a2e0564985e41dea42ea0321d8 (diff) | |
download | calcurse-0e5a9f16201a926856668b3c6b2be1c69696009d.zip |
Clean up updatestring() in "utils.c".
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r-- | src/utils.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/utils.c b/src/utils.c index 5a59556..3ce9898 100644 --- a/src/utils.c +++ b/src/utils.c @@ -372,23 +372,26 @@ getstring (WINDOW *win, char *str, int l, int x, int y) int updatestring (WINDOW *win, char **str, int x, int y) { - char *newstr; - int escape, len = strlen (*str) + 1; + int len = strlen (*str); + char *buf; + enum getstr ret; - EXIT_IF (len > BUFSIZ, _("Internal error: line too long")); + EXIT_IF (len + 1 > BUFSIZ, _("Internal error: line too long")); - newstr = mem_malloc (BUFSIZ); - (void) memcpy (newstr, *str, len); - escape = getstring (win, newstr, BUFSIZ, x, y); - if (!escape) - { - len = strlen (newstr) + 1; - *str = mem_realloc (*str, len, 1); - EXIT_IF (*str == 0, _("out of memory")); - (void) memcpy (*str, newstr, len); - } - mem_free (newstr); - return escape; + buf = mem_malloc (BUFSIZ); + (void)memcpy (buf, *str, len + 1); + + ret = getstring (win, buf, BUFSIZ, x, y); + + if (ret == GETSTRING_VALID) { + len = strlen (buf); + *str = mem_realloc (*str, len + 1, 1); + EXIT_IF (*str == 0, _("out of memory")); + (void)memcpy (*str, buf, len + 1); + } + + mem_free (buf); + return ret; } /* checks if a string is only made of digits */ |