Skip to contentSkip to conversation

master - coverity: just make impossible division by zero

PATCH Zdenek Kabelac 1 participant 1 message Jun 30, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2ceb5a0abbbdc3753cfcaff76251d6477a9ea088
Commit:        2ceb5a0abbbdc3753cfcaff76251d6477a9ea088
Parent:        3d08b0971f5f2610459343d0ae2a524d272142d2
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Fri Jun 30 19:44:06 2017 +0200
Committer:     Zdenek Kabelac <[email protected]>
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(-)
lib/metadata/raid_manip.c +6 -1
index df7e062..a22b529 100644
@@ -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;