From: John Darrington Date: Sun, 23 Jun 2019 04:37:45 +0000 (+0200) Subject: Don't crash when inserting variables into an empty sheet. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91ced0102521c876f1ac4602977fd15c73b25697;p=pspp Don't crash when inserting variables into an empty sheet. Fixes bug #56392. --- diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 63ce9d3308..84a89527e8 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -433,7 +433,8 @@ psppire_dict_generate_name (const PsppireDict *dict, char *name, size_t size) /* Insert a new variable at posn IDX, with the name NAME, and return the new variable. - If NAME is null, then a name will be automatically assigned. + IDX may take the special value -1, which will be treated the same as + zero. If NAME is null, then a name will be automatically assigned. */ struct variable * psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) @@ -441,7 +442,8 @@ psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) struct variable *var; char tmpname[64]; - g_return_val_if_fail (idx >= 0, NULL); + if (idx == -1) /* Note bug #56392. */ + idx = 0; g_return_val_if_fail (d, NULL); g_return_val_if_fail (PSPPIRE_IS_DICT (d), NULL);