Commit af76ac8b authored by sudarsan N's avatar sudarsan N Committed by Daniel DeGrasse
Browse files

video: common: prevent divide-by-zero video_closest_frmival_stepwise()



Adds an assertion and runtime log to ensure 'step' is not zero before
using it in division,preventing undefined behavior without modifying
 the public API.

Avoids a signature change (void → int) to preserve API stability for
Zephyr 4.2.A more complete solution can be proposed for 4.3.

CID: 444378

Signed-off-by: default avatarsudarsan N <sudarsansamy2002@gmail.com>
parent 2c097a4c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -136,6 +136,11 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis
	step *= stepwise->min.denominator * stepwise->max.denominator * desired->denominator;
	goal *= stepwise->min.denominator * stepwise->max.denominator * stepwise->step.denominator;

	__ASSERT_NO_MSG(step != 0U);
	/* Prevent division by zero */
	if (step == 0U) {
		return;
	}
	/* Saturate the desired value to the min/max supported */
	goal = CLAMP(goal, min, max);