From: Willy Tarreau Date: Sun, 17 May 2026 21:03:35 +0000 (+0200) Subject: CLEANUP: stick-table: uniformize the different action_inc_gpc*() X-Git-Tag: v3.4-dev13~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b44d60eb42865ac0ea15acd016f0d6d2d852a9ea;p=thirdparty%2Fhaproxy.git CLEANUP: stick-table: uniformize the different action_inc_gpc*() While action_inc_gpc1() explicitly checks if s->stkctr or sess->stkctr are set since 2.8 with commit 6c0117168 ("MEDIUM: stick-table: set the track-sc limit at boottime via tune.stick-counters"), action_inc_gpc0() and the generic action_inc_gpc() still stuck to the old approach of not checking them, causing confusion when reviewing the code. Upon closer inspection, the only case where the pointer may be NULL is when global.tune.nb_stk_ctr is zero, which happens when the global section contains "tune.stick-counters 0". However in this case, the config parser "parse_inc_gpc()" will reject any reference to any stick counter, so in theory there is no problem. Regardless, the difference of treatment between sibling functions remains confusing and the check is cheap, so let's generalize it, it will save a future reader from the need to inspect stream_new() and session_new(). --- diff --git a/src/stick_table.c b/src/stick_table.c index f94d674ba..dfe1cbae4 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -2675,10 +2675,12 @@ static enum act_return action_inc_gpc(struct act_rule *rule, struct proxy *px, struct stkctr *stkctr; /* Extract the stksess, return OK if no stksess available. */ - if (s) + if (s && s->stkctr) stkctr = &s->stkctr[rule->arg.gpc.sc]; - else + else if (sess->stkctr) stkctr = &sess->stkctr[rule->arg.gpc.sc]; + else + return ACT_RET_CONT; ts = stkctr_entry(stkctr); if (ts) { @@ -2716,10 +2718,12 @@ static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px, unsigned int period = 0; /* Extract the stksess, return OK if no stksess available. */ - if (s) + if (s && s->stkctr) stkctr = &s->stkctr[rule->arg.gpc.sc]; - else + else if (sess->stkctr) stkctr = &sess->stkctr[rule->arg.gpc.sc]; + else + return ACT_RET_CONT; ts = stkctr_entry(stkctr); if (ts) {