@cryptotaxi247 / netdata-1 / commits / 2dbbfd678

Fix based on Coverity and Sonar audits (part 6) (#22334)

pulse: use int loop variable when negating to STREAM_HANDSHAKE enum Sonar c:S876: chart_by_reason() iterated with `size_t i` and passed `-i` to stream_handshake_error_to_string(STREAM_HANDSHAKE). The unary minus on the unsigned counter wrapped to a huge unsigned value that then narrowed to int through implementation-defined conversion (C99 6.3.1.3). It happens to produce the correct -i on two's-complement platforms but is fragile and unportable. Change the loop variable to `int`. The loop bound STREAM_HANDSHAKE_NEGATIVE_MAX is 40, well within int range, and the b->rd[] array has more than enough entries for the same index. The negation is now well-defined signed arithmetic. Co-authored-by: Costa Tsaousis <costa@netdata.cloud>

Stelios Fragkakis committed May 1, 2026 at 11:14 UTC 2dbbfd6787cf82e88a0db6f0f57ab9eeb22d84eb
1 file changed +1 -1
src/daemon/pulse/pulse-parents.c
+1 -1
@@ -305,7 +305,7 @@ static void chart_by_reason(struct by_reason *b, const char *id, const char *con
305 , RRDSET_TYPE_LINE
306 );
307
308 - for(size_t i = 0; i < STREAM_HANDSHAKE_NEGATIVE_MAX ;i++) {
308 + for(int i = 0; i < STREAM_HANDSHAKE_NEGATIVE_MAX ;i++) {
309 char buf[1024];
310 if(!i)
311 strncpyz(buf, "connected", sizeof(buf) - 1);