Skip to contentSkip to conversation

master - coverity: remove redundant condition

PATCH Peter Rajnoha 1 participant 1 message Nov 12, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=eccc97f15a0f2e19f5ccc714cb4880644b4772df
Commit:        eccc97f15a0f2e19f5ccc714cb4880644b4772df
Parent:        ba2302346433af7150193025aa8a446fa3238445
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Nov 12 09:30:02 2014 +0100
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Nov 12 09:30:02 2014 +0100

coverity: remove redundant condition

LVM2.2.02.112/daemons/clvmd/clvmd.c:1131: warning[arrayIndexOutOfBoundsCond]: Array 'row[8]' accessed at index 8, which is out of bounds. Otherwise condition 'j==8' is redundant.

This code:

int i,j = 0;
...

for (i = 0; i < len; ++i) {
	...
	if ((j == 8) || (i + 1 == len)) {
		for (;j < 8; ++j) {
			...
		}
		...
		j = 0;
	}
}

Indeed - j is 0 at the beginning, then iterating till j < 8, then always zeroed@the end of the outer loop - so "j" never reaching value of 8 - the j == 8 condition is redundant.

---
 daemons/clvmd/clvmd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
daemons/clvmd/clvmd.c +1 -1
index 9b865f6..0c1cb44 100644
@@ -1128,7 +1128,7 @@ static void dump_message(char *buf, int len)
 		row[j] = buf[i];
 		str[j] = (isprint(buf[i])) ? buf[i] : ' ';
 
-		if ((j == 8) || (i + 1 == len)) {
+		if (i + 1 == len) {
 			for (;j < 8; ++j) {
 				row[j] = 0;
 				str[j] = ' ';