Skip to content

Commit 79f6c1c

Browse files
committed
linux-pipewire: camera-portal: More robust size comparison
Cast the width to `uint64_t` before calculating the area of the rectangle, and instead of subtracting the two, go through the cases and return the result accordingly.
1 parent 2b613f4 commit 79f6c1c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

plugins/linux-pipewire/camera-portal.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,15 @@ static int sort_resolutions(gconstpointer a, gconstpointer b)
503503
{
504504
const struct spa_rectangle *resolution_a = a;
505505
const struct spa_rectangle *resolution_b = b;
506-
int64_t area_a = resolution_a->width * resolution_a->height;
507-
int64_t area_b = resolution_b->width * resolution_b->height;
508506

509-
return area_a - area_b;
507+
uint64_t area_a = (uint64_t)resolution_a->width * resolution_a->height;
508+
uint64_t area_b = (uint64_t)resolution_b->width * resolution_b->height;
509+
510+
if (area_a < area_b)
511+
return -1;
512+
if (area_a > area_b)
513+
return +1;
514+
return 0;
510515
}
511516

512517
static void resolution_list(struct camera_device *dev, uint32_t pixelformat, obs_property_t *prop)

0 commit comments

Comments
 (0)