From 0a3f57e3ca503f832c381328ca1c678fe01429fa Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 2 Mar 2023 21:37:23 +0200 Subject: [PATCH 29/29] Refactor trade_routes_iterate_safe() Fix clang analyzer warnings See osdn #47449 Signed-off-by: Marko Lindqvist --- common/traderoutes.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/traderoutes.h b/common/traderoutes.h index 0de9fdb7e2..d4aed1a4e7 100644 --- a/common/traderoutes.h +++ b/common/traderoutes.h @@ -139,11 +139,14 @@ do { \ { \ struct city *c##_proute = c; \ int _routes##_size = trade_route_list_size(c##_proute->routes); \ + \ if (_routes##_size > 0) { \ struct trade_route *_routes##_saved[_routes##_size]; \ - int _routes##_index = 0; \ + int _routes##_index; \ + \ + _routes##_size = 0; \ trade_routes_iterate(c##_proute, _proute) { \ - _routes##_saved[_routes##_index++] = _proute; \ + _routes##_saved[_routes##_size++] = _proute; \ } trade_routes_iterate_end; \ for (_routes##_index = 0; \ _routes##_index < _routes##_size; \ @@ -237,4 +240,4 @@ bool city_receives_goods(const struct city *pcity, } #endif /* __cplusplus */ -#endif /* FC__TRADEROUTES_H */ +#endif /* FC__TRADEROUTES_H */ -- 2.39.2