From c5724c46a0f2bc4db5e29887b84c1dc25e3d86b0 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 9 Apr 2021 18:01:50 +0100 Subject: [PATCH] unifontsel: add extra double-checks of fontinfo values. Coverity objected to several similar cases in this code in which I'd checked a pointer for NULL after already having done things to it. I think all the cases are benign, in that (as the comments tersely mention) those checks could only fail if the unifontsel system had got _really_ confused, in which case probably some other bug would have been on the point of manifesting anyway. But Coverity has a point anyway: if I'm _going_ to check those values for NULL, let's check them consistently. --- unix/gtkfont.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/unix/gtkfont.c b/unix/gtkfont.c index 42aadd2d..b910d14b 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -2627,6 +2627,10 @@ static void unifontsel_setup_sizelist(unifontsel_internal *fs, */ for (i = start; i < end; i++) { info = (fontinfo *)index234(fs->fonts_by_selorder, i); + if (!info) { + /* _shouldn't_ happen unless font list is completely funted */ + break; + } if (info->flags &~ fs->filter_flags) { info->sizeindex = -1; continue; /* we're filtering out this font */ @@ -3135,9 +3139,11 @@ static void family_changed(GtkTreeSelection *treeselection, gpointer data) gtk_tree_model_get(treemodel, &treeiter, 1, &minval, -1); info = (fontinfo *)index234(fs->fonts_by_selorder, minval); - info = update_for_intended_size(fs, info); if (!info) return; /* _shouldn't_ happen unless font list is completely funted */ + info = update_for_intended_size(fs, info); + if (!info) + return; /* similarly shouldn't happen */ if (!info->size) fs->selsize = fs->intendedsize; /* font is scalable */ unifontsel_select_font(fs, info, info->size ? info->size : fs->selsize, @@ -3162,9 +3168,11 @@ static void style_changed(GtkTreeSelection *treeselection, gpointer data) if (minval < 0) return; /* somehow a charset heading got clicked */ info = (fontinfo *)index234(fs->fonts_by_selorder, minval); - info = update_for_intended_size(fs, info); if (!info) return; /* _shouldn't_ happen unless font list is completely funted */ + info = update_for_intended_size(fs, info); + if (!info) + return; /* similarly shouldn't happen */ if (!info->size) fs->selsize = fs->intendedsize; /* font is scalable */ unifontsel_select_font(fs, info, info->size ? info->size : fs->selsize, @@ -3187,6 +3195,8 @@ static void size_changed(GtkTreeSelection *treeselection, gpointer data) gtk_tree_model_get(treemodel, &treeiter, 1, &minval, 2, &size, -1); info = (fontinfo *)index234(fs->fonts_by_selorder, minval); + if (!info) + return; /* _shouldn't_ happen unless font list is completely funted */ unifontsel_select_font(fs, info, info->size ? info->size : size, 3, true); }