From ab83e764f912862749bb8347b120a05324f81c35 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 20 Mar 2023 20:04:30 +0200 Subject: [PATCH 4/4] sdl/2: Fix tech help NULL dereference See osdn #47615 Signed-off-by: Marko Lindqvist --- client/gui-sdl/helpdlg.c | 12 ++++++------ client/gui-sdl2/helpdlg.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/client/gui-sdl/helpdlg.c b/client/gui-sdl/helpdlg.c index 309338c235..fb1adcdba5 100644 --- a/client/gui-sdl/helpdlg.c +++ b/client/gui-sdl/helpdlg.c @@ -1106,7 +1106,7 @@ static struct widget *create_tech_info(Tech_type_id tech, int width, struct widget *pWidget; struct widget *pLast, *pBudynki; struct widget *pDock = pStore->pDock; - int i, targets_count,sub_targets_count, max_width = 0; + int i, targets_count, sub_targets_count, max_width = 0; int start_x, start_y, imp_count, unit_count, flags_count, gov_count; char buffer[bufsz]; SDL_Surface *pSurf; @@ -1299,18 +1299,18 @@ static struct widget *create_tech_info(Tech_type_id tech, int width, start_y = pWidget->size.y + pWidget->size.h + adj_size(30); if (targets_count) { - int j, t0, t1; + int j = 0; i = 0; - j = 0; - t1 = MAX_ID - pStore->pSub_Targets[j]->ID; + while (i < 6 && pStore->pTargets[i]) { pStore->pTargets[i]->size.x = pWindow->size.x + start_x; pStore->pTargets[i]->size.y = start_y; if (pStore->pSub_Targets[j]) { - t0 = MAX_ID - pStore->pTargets[i]->ID; - t1 = MAX_ID - pStore->pSub_Targets[j]->ID; + int t0 = MAX_ID - pStore->pTargets[i]->ID; + int t1 = MAX_ID - pStore->pSub_Targets[j]->ID; + if (advance_required(t0, AR_ONE) == t1 || advance_required(t0, AR_TWO) == t1) { pStore->pSub_Targets[j]->size.x = pWindow->size.x + start_x + max_width + 60; diff --git a/client/gui-sdl2/helpdlg.c b/client/gui-sdl2/helpdlg.c index e47f9b9e3c..75606ff6a3 100644 --- a/client/gui-sdl2/helpdlg.c +++ b/client/gui-sdl2/helpdlg.c @@ -1113,7 +1113,7 @@ static struct widget *create_tech_info(Tech_type_id tech, int width, struct widget *pWidget; struct widget *pLast, *pBudynki; struct widget *pDock = pStore->pDock; - int i, targets_count,sub_targets_count, max_width = 0; + int i, targets_count, sub_targets_count, max_width = 0; int start_x, start_y, imp_count, unit_count, flags_count, gov_count; char buffer[bufsz]; SDL_Surface *pSurf; @@ -1306,18 +1306,18 @@ static struct widget *create_tech_info(Tech_type_id tech, int width, start_y = pWidget->size.y + pWidget->size.h + adj_size(30); if (targets_count) { - int j, t0, t1; + int j = 0; i = 0; - j = 0; - t1 = MAX_ID - pStore->pSub_Targets[j]->ID; + while (i < 6 && pStore->pTargets[i]) { pStore->pTargets[i]->size.x = pWindow->size.x + start_x; pStore->pTargets[i]->size.y = start_y; if (pStore->pSub_Targets[j]) { - t0 = MAX_ID - pStore->pTargets[i]->ID; - t1 = MAX_ID - pStore->pSub_Targets[j]->ID; + int t0 = MAX_ID - pStore->pTargets[i]->ID; + int t1 = MAX_ID - pStore->pSub_Targets[j]->ID; + if (advance_required(t0, AR_ONE) == t1 || advance_required(t0, AR_TWO) == t1) { pStore->pSub_Targets[j]->size.x = pWindow->size.x + start_x + max_width + 60; -- 2.39.2