cov: check for potential empty row list
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 30 Jun 2025 12:14:01 +0000 (14:14 +0200)
committerMarian Csontos <mcsontos@redhat.com>
Mon, 29 Sep 2025 16:07:44 +0000 (18:07 +0200)
Skip potential 0 length allocation and return early for empty list.

(cherry picked from commit 9fcc66316cd5f4b78b78ab1e0d50fafad362d499)

device_mapper/libdm-report.c
libdm/libdm-report.c

index 4c3f3266a09228da44403628589968e98a930f1e..343a7edbcba3811b3dac7a8dc751d2ead973bf2d 100644 (file)
@@ -4668,9 +4668,12 @@ static int _sort_rows(struct dm_report *rh)
        struct row *(*rows)[];
        uint32_t count = 0;
        struct row *row;
+       size_t cnt_rows;
 
-       if (!(rows = dm_pool_alloc(rh->mem, sizeof(**rows) *
-                               dm_list_size(&rh->rows)))) {
+       if (!(cnt_rows = dm_list_size(&rh->rows)))
+               return 1; /* nothing to sort */
+
+       if (!(rows = dm_pool_alloc(rh->mem, sizeof(**rows) * cnt_rows))) {
                log_error("dm_report: sort array allocation failed");
                return 0;
        }
index 36d99f7d7e3a8d09e113ddeb35e6cc9f17ec69f3..87c588c3cd8f3824e71b1c56b1f3feafd7e1b423 100644 (file)
@@ -4665,9 +4665,12 @@ static int _sort_rows(struct dm_report *rh)
        struct row *(*rows)[];
        uint32_t count = 0;
        struct row *row;
+       size_t cnt_rows;
 
-       if (!(rows = dm_pool_alloc(rh->mem, sizeof(**rows) *
-                               dm_list_size(&rh->rows)))) {
+       if (!(cnt_rows = dm_list_size(&rh->rows)))
+               return 1; /* nothing to sort */
+
+       if (!(rows = dm_pool_alloc(rh->mem, sizeof(**rows) * cnt_rows))) {
                log_error("dm_report: sort array allocation failed");
                return 0;
        }
This page took 0.086209 seconds and 5 git commands to generate.