From d3c064df1b810f0c6b4678b4c867a2ae1425867c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 1 Sep 2022 04:50:17 +0300 Subject: [PATCH 25/25] Add inline advance_count() wrapper proving that it returns <= A_LAST Compiler was not happy with what it consider potential bigger than A_LAST return value from advance_count() See osdn #45541 Signed-off-by: Marko Lindqvist --- common/tech.c | 2 +- common/tech.h | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/tech.c b/common/tech.c index 1958fe871e..8e36583f56 100644 --- a/common/tech.c +++ b/common/tech.c @@ -75,7 +75,7 @@ const struct advance *advance_array_last(void) /************************************************************************** Return the number of advances/technologies. **************************************************************************/ -Tech_type_id advance_count(void) +Tech_type_id advance_count_real(void) { return game.control.num_tech_types; } diff --git a/common/tech.h b/common/tech.h index 9ab03cf55c..40da6bdf3c 100644 --- a/common/tech.h +++ b/common/tech.h @@ -158,7 +158,21 @@ struct advance { BV_DEFINE(bv_techs, A_LAST); /* General advance/technology accessor functions. */ -Tech_type_id advance_count(void); +Tech_type_id advance_count_real(void); + +/************************************************************************** + Inline wrapper for advance_count_real() that makes it clear to + the compiler that the value returned never exceeds A_LAST. + Making actual advance_count_real() inline would be more + complicated due to header interdependencies. +**************************************************************************/ +static inline Tech_type_id advance_count(void) +{ + Tech_type_id rc = advance_count_real(); + + return MIN(rc, A_LAST); +} + Tech_type_id advance_index(const struct advance *padvance); Tech_type_id advance_number(const struct advance *padvance); -- 2.35.1