diff --git a/source/build.c b/source/build.c
index 7e410aa..91a2a40 100644
--- a/source/build.c
+++ b/source/build.c
@@ -198,9 +198,9 @@ void build(void) {
 	/* normalize the current directory relative to the home directory so
 	   the cross-reference is not rebuilt when the user's login is moved */
 	strcpy(newdir, currentdir);
-	if(strcmp(currentdir, home) == 0) {
+	if(!strcmp(currentdir, home)) {
 		strcpy(newdir, "$HOME");
-	} else if(strncmp(currentdir, home, strlen(home)) == 0) {
+	} else if(!strncmp(currentdir, home, strlen(home))) {
 		snprintf(newdir, sizeof(newdir), "$HOME%s", currentdir + strlen(home));
 	}
 	/* sort the source file names (needed for rebuilding) */
@@ -521,21 +521,21 @@ void putheader(char *dir) {
 }
 
 /* put the name list into the cross-reference file */
-	int i, size = 0;
 static
 void putlist(char **names, int count) {
+	int size = 0;
 
 	fprintf(newrefs, "%d\n", count);
 	if(names == srcfiles) {
-
 		/* calculate the string space needed */
-		for(i = 0; i < count; ++i) {
+		for(int i = 0; i < count; ++i) {
 			size += strlen(names[i]) + 1;
 		}
 		fprintf(newrefs, "%d\n", size);
 	}
-	for(i = 0; i < count; ++i) {
-		if(fputs(names[i], newrefs) == EOF || putc('\n', newrefs) == EOF) {
+	for(int i = 0; i < count; i++) {
+		if(fputs(names[i], newrefs) == EOF
+        || putc('\n', newrefs) == EOF) {
 			cannotwrite(newreffile);
 			/* NOTREACHED */
 		}
diff --git a/source/dir.c b/source/dir.c
index 4f44016..10546be 100644
--- a/source/dir.c
+++ b/source/dir.c
@@ -220,7 +220,6 @@ void makefilelist(void) {
 	char		 line[PATHLEN * 10];
 	char		*file;
 	char		*s;
-	unsigned int i;
 
 	makevpsrcdirs(); /* make the view source directory list */
 
@@ -228,7 +227,7 @@ void makefilelist(void) {
 	if(namefile == NULL && fileargc > 0) {
 
 		/* put them in a list that can be expanded */
-		for(i = 0; i < fileargc; ++i) {
+		for(unsigned i = 0; i < fileargc; i++) {
 			file = fileargv[i];
 			if(infilelist(file) == false) {
 				if((s = inviewpath(file)) != NULL) {
@@ -291,7 +290,7 @@ void makefilelist(void) {
 					unfinished_option = 0;
 				}
 
-				i = path[1];
+				int i = path[1];
 				switch(i) {
 					case 'c': /* ASCII characters only in crossref */
 						compress = false;
@@ -444,13 +443,15 @@ static void scan_dir(const char *adir, bool recurse_dir) {
 					PATHLEN - 2 - adir_len,
 					entry->d_name);
 
-				if(lstat(path, &buf) == 0) {
-					if(recurse_dir && S_ISDIR(buf.st_mode)) {
-						scan_dir(path, recurse_dir);
-					} else if(issrcfile(path) && infilelist(path) == false &&
-							  access(path, R_OK) == 0) {
-						addsrcfile(path);
-					}
+				if(lstat(path, &buf)) { continue; }
+
+				if(recurse_dir && S_ISDIR(buf.st_mode)) {
+					scan_dir(path, recurse_dir);
+				} else
+                if(issrcfile(path)
+                && !infilelist(path)
+                && access(path, R_OK) == 0) {
+					addsrcfile(path);
 				}
 			}
 		}
diff --git a/source/lookup.c b/source/lookup.c
index dc0c738..945cd7b 100644
--- a/source/lookup.c
+++ b/source/lookup.c
@@ -128,11 +128,14 @@ char * lookup(char *ident, bool do_compressed) {
 }
 
 /* form hash value for string */
-int hash(char *ss) {
-	int			   i;
+int hash(const char * ss) {
+	int			   i = 0;
 	unsigned char *s = (unsigned char *)ss;
 
-	for(i = 0; *s != '\0';)
+    while (*s != '\0') {
 		i += *s++; /* += is faster than <<= for cscope */
+
+    }
+
 	return (i);
 }