Fix seg fault in update_rept()

Memory pointers must be initialized at the start in case memory is
freed (cleanup) before it is allocated.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2018-06-01 07:29:34 +02:00 committed by Lukas Fleischer
parent fa353e5eb7
commit b6cdc29255

View File

@ -215,6 +215,13 @@ static void update_desc(char **desc)
static void update_rept(struct rpt **rpt, const long start) static void update_rept(struct rpt **rpt, const long start)
{ {
/* Pointers to dynamically allocated memory. */
char *msg_rpt_current = NULL;
char *msg_rpt_asktype = NULL;
char *freqstr = NULL;
char *timstr = NULL;
char *outstr = NULL;
/* Update repetition type. */ /* Update repetition type. */
int newtype; int newtype;
const char *msg_rpt_prefix = _("Enter the new repetition type:"); const char *msg_rpt_prefix = _("Enter the new repetition type:");
@ -225,7 +232,6 @@ static void update_rept(struct rpt **rpt, const long start)
/* Find the current repetition type. */ /* Find the current repetition type. */
const char *rpt_current; const char *rpt_current;
char *msg_rpt_current;
switch (recur_def2char((*rpt)->type)) { switch (recur_def2char((*rpt)->type)) {
case 'D': case 'D':
rpt_current = msg_rpt_daily; rpt_current = msg_rpt_daily;
@ -244,7 +250,6 @@ static void update_rept(struct rpt **rpt, const long start)
rpt_current = msg_rpt_daily; rpt_current = msg_rpt_daily;
} }
asprintf(&msg_rpt_current, _("(currently using %s)"), rpt_current); asprintf(&msg_rpt_current, _("(currently using %s)"), rpt_current);
char *msg_rpt_asktype;
asprintf(&msg_rpt_asktype, "%s %s, %s, %s, %s? %s", msg_rpt_prefix, asprintf(&msg_rpt_asktype, "%s %s, %s, %s, %s? %s", msg_rpt_prefix,
msg_rpt_daily, msg_rpt_weekly, msg_rpt_monthly, msg_rpt_daily, msg_rpt_weekly, msg_rpt_monthly,
msg_rpt_yearly, msg_rpt_current); msg_rpt_yearly, msg_rpt_current);
@ -268,7 +273,6 @@ static void update_rept(struct rpt **rpt, const long start)
/* Update frequency. */ /* Update frequency. */
int newfreq; int newfreq;
char *freqstr = NULL;
const char *msg_wrong_freq = _("Invalid frequency."); const char *msg_wrong_freq = _("Invalid frequency.");
const char *msg_enter = _("Press [Enter] to continue"); const char *msg_enter = _("Press [Enter] to continue");
do { do {
@ -288,8 +292,6 @@ static void update_rept(struct rpt **rpt, const long start)
while (newfreq == 0); while (newfreq == 0);
/* Update end date. */ /* Update end date. */
char *timstr = NULL;
char *outstr = NULL;
time_t newuntil; time_t newuntil;
const char *msg_until_1 = const char *msg_until_1 =
_("Enter end date or duration ('?' for input formats):"); _("Enter end date or duration ('?' for input formats):");