From 1b484566b3efd349b9e8baaa59a92d64a86f627d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Mar 2023 07:42:21 +0200 Subject: [PATCH 8/8] sdl2: Fix help NULL dereference for improvements with just negated reqs See osdn #47559 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/helpdlg.c | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/client/gui-sdl2/helpdlg.c b/client/gui-sdl2/helpdlg.c index ac0a07b558..d37d947bfd 100644 --- a/client/gui-sdl2/helpdlg.c +++ b/client/gui-sdl2/helpdlg.c @@ -238,11 +238,11 @@ void popup_impr_info(Impr_type_id impr) current_help_dlg = HELP_IMPROVEMENT; created = TRUE; - /* create dialog */ + /* Create dialog */ pHelpDlg = fc_calloc(1, sizeof(struct ADVANCED_DLG)); pStore = fc_calloc(1, sizeof(struct UNITS_BUTTONS)); - /* create window */ + /* Create window */ title = create_utf8_from_char(_("Help : Improvements"), adj_font(12)); title->style |= TTF_STYLE_BOLD; @@ -257,7 +257,7 @@ void popup_impr_info(Impr_type_id impr) area = pWindow->area; /* ------------------ */ - /* close button */ + /* Close button */ pCloseButton = create_themeicon(current_theme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); @@ -337,7 +337,7 @@ void popup_impr_info(Impr_type_id impr) #if 0 pListToggleButton->action = toggle_full_tree_mode_in_help_dlg_callback; if (pStore->show_tree) { - set_wstate(pListToggleButton, FC_WS_NORMAL); + set_wstate(pListToggleButton, FC_WS_NORMAL); } #endif @@ -403,33 +403,36 @@ void popup_impr_info(Impr_type_id impr) DownAdd(pRequirementLabel, pDock); pDock = pRequirementLabel; - if (requirement_vector_size(&pImpr_type->reqs) == 0) { + /* FIXME: this should show ranges, negated reqs, and all the + * MAX_NUM_REQS reqs. + * Currently it's limited to 1 req. Remember MAX_NUM_REQS is a compile-time + * definition. */ + requirement_vector_iterate(&pImpr_type->reqs, preq) { + if (!preq->present) { + continue; + } + pRequirementLabel2 = create_iconlabel_from_chars(NULL, pWindow->dst, + universal_name_translation(&preq->source, buffer, + sizeof(buffer)), + adj_font(12), WF_RESTORE_BACKGROUND); + if (preq->source.kind != VUT_ADVANCE) { + break; /* FIXME */ + } + pRequirementLabel2->ID = MAX_ID - advance_number(preq->source.value.advance); + pRequirementLabel2->string_utf8->fgcol + = *get_tech_color(advance_number(preq->source.value.advance)); + pRequirementLabel2->action = change_tech_callback; + set_wstate(pRequirementLabel2, FC_WS_NORMAL); + break; + } requirement_vector_iterate_end; + + if (pRequirementLabel2 == NULL) { pRequirementLabel2 = create_iconlabel_from_chars(NULL, pWindow->dst, Q_("?req:None"), adj_font(12), 0); pRequirementLabel2->ID = ID_LABEL; - } else { - /* FIXME: this should show ranges, negated reqs, and all the - * MAX_NUM_REQS reqs. - * Currently it's limited to 1 req. Remember MAX_NUM_REQS is a compile-time - * definition. */ - requirement_vector_iterate(&pImpr_type->reqs, preq) { - if (!preq->present) { - continue; - } - pRequirementLabel2 = create_iconlabel_from_chars(NULL, pWindow->dst, - universal_name_translation(&preq->source, buffer, sizeof(buffer)), - adj_font(12), WF_RESTORE_BACKGROUND); - if (preq->source.kind != VUT_ADVANCE) { - break; /* FIXME */ - } - pRequirementLabel2->ID = MAX_ID - advance_number(preq->source.value.advance); - pRequirementLabel2->string_utf8->fgcol = *get_tech_color(advance_number(preq->source.value.advance)); - pRequirementLabel2->action = change_tech_callback; - set_wstate(pRequirementLabel2, FC_WS_NORMAL); - break; - } requirement_vector_iterate_end; } + DownAdd(pRequirementLabel2, pDock); pDock = pRequirementLabel2; pStore->pRequirementButton = pRequirementLabel2; @@ -448,6 +451,7 @@ void popup_impr_info(Impr_type_id impr) break; } } requirement_vector_iterate_end; + if (obsTech == NULL) { pObsoleteByLabel2 = create_iconlabel_from_chars(NULL, pWindow->dst, _("Never"), adj_font(12), 0); -- 2.39.2