Skip to content

Commit 2883408

Browse files
committed
drivers: video: sw_generator: fix off-by-one in ARRAY_SIZE() comparison
The struct video_format_caps fmts[] is an array terminated by an empty entry which should not be used while searching or comparing the formats. If using ARRAY_SIZE(), this terminator entry should be subtracted from the list. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 01a0909 commit 2883408

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/video/video_sw_generator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ static int video_sw_generator_set_fmt(const struct device *dev, struct video_for
7373
struct video_sw_generator_data *data = dev->data;
7474
int i = 0;
7575

76-
for (i = 0; i < ARRAY_SIZE(fmts); ++i) {
76+
for (i = 0; i < ARRAY_SIZE(fmts) - 1; ++i) {
7777
if (fmt->pixelformat == fmts[i].pixelformat &&
7878
IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) &&
7979
IN_RANGE(fmt->height, fmts[i].height_min, fmts[i].height_max)) {
8080
break;
8181
}
8282
}
8383

84-
if (i == ARRAY_SIZE(fmts)) {
84+
if (i == ARRAY_SIZE(fmts) - 1) {
8585
LOG_ERR("Unsupported pixel format or resolution");
8686
return -ENOTSUP;
8787
}

0 commit comments

Comments
 (0)