Fix empty string in updatestring()
If the update results in an empty string (return value GETSTRING_RET), the original string remains whereas it should be empty. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
9befae484d
commit
b7eb9a9e94
@ -280,7 +280,13 @@ enum getstr getstring(WINDOW * win, char *str, int l, int x, int y)
|
|||||||
return st.len == 0 ? GETSTRING_RET : GETSTRING_VALID;
|
return st.len == 0 ? GETSTRING_RET : GETSTRING_VALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update an already existing string. */
|
/*
|
||||||
|
* Safe edit of a dynamically allocated string.
|
||||||
|
* A copy of the original is edited. The internal buffer size
|
||||||
|
* is the only limit on the length of the edited string. After editing
|
||||||
|
* additional memory is allocated for the original if needed. The original
|
||||||
|
* remains intact if editing is interrupted.
|
||||||
|
*/
|
||||||
int updatestring(WINDOW * win, char **str, int x, int y)
|
int updatestring(WINDOW * win, char **str, int x, int y)
|
||||||
{
|
{
|
||||||
int len = strlen(*str);
|
int len = strlen(*str);
|
||||||
@ -299,8 +305,8 @@ int updatestring(WINDOW * win, char **str, int x, int y)
|
|||||||
*str = mem_realloc(*str, len + 1, 1);
|
*str = mem_realloc(*str, len + 1, 1);
|
||||||
EXIT_IF(*str == NULL, _("out of memory"));
|
EXIT_IF(*str == NULL, _("out of memory"));
|
||||||
memcpy(*str, buf, len + 1);
|
memcpy(*str, buf, len + 1);
|
||||||
}
|
} else if (ret == GETSTRING_RET)
|
||||||
|
**str = '\0';
|
||||||
mem_free(buf);
|
mem_free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user