[lvm-devel] master - coverity: just make impossible division by zero

Zdenek Kabelac zkabelac at sourceware.org
Fri Jun 30 19:13:59 UTC 2017


Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2ceb5a0abbbdc3753cfcaff76251d6477a9ea088
Commit:        2ceb5a0abbbdc3753cfcaff76251d6477a9ea088
Parent:        3d08b0971f5f2610459343d0ae2a524d272142d2
Author:        Zdenek Kabelac <zkabelac at redhat.com>
AuthorDate:    Fri Jun 30 19:44:06 2017 +0200
Committer:     Zdenek Kabelac <zkabelac at redhat.com>
CommitterDate: Fri Jun 30 20:39:23 2017 +0200

coverity: just make impossible division by zero

Visible for analyzer  code will not try to use 0 for division.
---
 lib/metadata/raid_manip.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index df7e062..a22b529 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -844,7 +844,7 @@ static int _reorder_raid10_near_seg_areas(struct lv_segment *seg, enum raid0_rai
 
 	if (!(idx = dm_pool_zalloc(seg_lv(seg, 0)->vg->vgmem, seg->area_count * sizeof(*idx)))) {
 		log_error("Memory allocation failed.");
-		return_0;
+		return 0;
 	}
 
 	/* Set up positional index array */
@@ -874,6 +874,11 @@ static int _reorder_raid10_near_seg_areas(struct lv_segment *seg, enum raid0_rai
 		 * _reorder_raid10_near_seg_areas 2137 idx[8]=8
 		 */
 		/* idx[from] = to */
+		if (!stripes) {
+			log_error(INTERNAL_ERROR "LV %s is missing stripes.",
+				  display_lvname(seg->lv));
+			return 0;
+		}
 		for (s = ss = 0; s < seg->area_count; s++)
 			if (s < stripes)
 				idx[s] = s * data_copies;




More information about the lvm-devel mailing list