Module Name:    src
Committed By:   rillig
Date:           Mon Oct  5 20:21:30 UTC 2020

Modified Files:
        src/usr.bin/make: dir.c dir.h for.c hash.c hash.h

Log Message:
make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/usr.bin/make/dir.c
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/make/dir.h
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/make/for.c
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/make/hash.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/hash.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.159 src/usr.bin/make/dir.c:1.160
--- src/usr.bin/make/dir.c:1.159	Mon Oct  5 19:30:37 2020
+++ src/usr.bin/make/dir.c	Mon Oct  5 20:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.159 2020/10/05 19:30:37 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.160 2020/10/05 20:21:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -135,7 +135,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.159 2020/10/05 19:30:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.160 2020/10/05 20:21:30 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -1377,7 +1377,7 @@ Dir_FindFile(const char *name, SearchPat
  */
 Boolean
 Dir_FindHereOrAbove(const char *here, const char *search_path,
-		    char *result, int result_len)
+		    char *result, size_t result_len)
 {
     struct make_stat mst;
     char dirbase[MAXPATHLEN + 1], *dirbase_end;
@@ -1446,7 +1446,7 @@ Dir_FindHereOrAbove(const char *here, co
  *	found one for it, the full name is placed in the path slot.
  *-----------------------------------------------------------------------
  */
-int
+time_t
 Dir_MTime(GNode *gn, Boolean recheck)
 {
     char *fullName;		/* the full pathname of name */

Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.27 src/usr.bin/make/dir.h:1.28
--- src/usr.bin/make/dir.h:1.27	Sun Sep 27 22:17:07 2020
+++ src/usr.bin/make/dir.h	Mon Oct  5 20:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.27 2020/09/27 22:17:07 rillig Exp $	*/
+/*	$NetBSD: dir.h,v 1.28 2020/10/05 20:21:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,8 +99,8 @@ void Dir_SetPATH(void);
 Boolean Dir_HasWildcards(const char *);
 void Dir_Expand(const char *, SearchPath *, StringList *);
 char *Dir_FindFile(const char *, SearchPath *);
-Boolean Dir_FindHereOrAbove(const char *, const char *, char *, int);
-int Dir_MTime(GNode *, Boolean);
+Boolean Dir_FindHereOrAbove(const char *, const char *, char *, size_t);
+time_t Dir_MTime(GNode *, Boolean);
 CachedDir *Dir_AddDir(SearchPath *, const char *);
 char *Dir_MakeFlags(const char *, SearchPath *);
 void Dir_ClearPath(SearchPath *);

Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.92 src/usr.bin/make/for.c:1.93
--- src/usr.bin/make/for.c:1.92	Mon Oct  5 19:27:47 2020
+++ src/usr.bin/make/for.c	Mon Oct  5 20:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.92 2020/10/05 19:27:47 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.93 2020/10/05 20:21:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -61,7 +61,7 @@
 #include    "strlist.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.92 2020/10/05 19:27:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.93 2020/10/05 20:21:30 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -83,7 +83,7 @@ typedef struct For {
      * are substituted, the parser must handle $V expressions as well, not
      * only ${V} and $(V). */
     Boolean short_var;
-    int sub_next;
+    unsigned int sub_next;
 } For;
 
 static For *accumFor;		/* Loop being accumulated */
@@ -149,7 +149,7 @@ For_Eval(const char *line)
     new_for->sub_next = 0;
 
     /* Grab the variables. Terminate on "in". */
-    while (TRUE) {
+    for (;;) {
 	size_t len;
 
 	cpp_skip_whitespace(&ptr);
@@ -168,7 +168,8 @@ For_Eval(const char *line)
 	if (len == 1)
 	    new_for->short_var = TRUE;
 
-	strlist_add_str(&new_for->vars, bmake_strldup(ptr, len), len);
+	strlist_add_str(&new_for->vars, bmake_strldup(ptr, len),
+			(unsigned int)len);
 	ptr += len;
     }
 
@@ -325,8 +326,8 @@ for_substitute(Buffer *cmds, strlist_t *
 
     /* If there were no escapes, or the only escape is the other variable
      * terminator, then just substitute the full string */
-    if (!(escapes &
-	  (ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) {
+    if (!(escapes & (ech == ')' ? ~(unsigned)FOR_SUB_ESCAPE_BRACE
+				: ~(unsigned)FOR_SUB_ESCAPE_PAREN))) {
 	Buf_AddStr(cmds, item);
 	return;
     }
@@ -352,7 +353,7 @@ static char *
 ForIterate(void *v_arg, size_t *ret_len)
 {
     For *arg = v_arg;
-    int i;
+    unsigned int i;
     char *var;
     const char *cp;
     const char *cmd_cp;

Index: src/usr.bin/make/hash.c
diff -u src/usr.bin/make/hash.c:1.43 src/usr.bin/make/hash.c:1.44
--- src/usr.bin/make/hash.c:1.43	Mon Oct  5 19:27:47 2020
+++ src/usr.bin/make/hash.c	Mon Oct  5 20:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.43 2020/10/05 19:27:47 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.44 2020/10/05 20:21:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -79,7 +79,7 @@
 #include "make.h"
 
 /*	"@(#)hash.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: hash.c,v 1.43 2020/10/05 19:27:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.44 2020/10/05 20:21:30 rillig Exp $");
 
 /*
  * The ratio of # entries to # buckets at which we rebuild the table to
@@ -104,7 +104,7 @@ static Hash_Entry *
 HashTable_Find(Hash_Table *t, unsigned int h, const char *key)
 {
 	Hash_Entry *e;
-	int chainlen = 0;
+	unsigned int chainlen = 0;
 
 #ifdef DEBUG_HASH_LOOKUP
 	DEBUG4(HASH, "%s: %p h=%x key=%s\n", __func__, t, h, key);
@@ -126,7 +126,7 @@ HashTable_Find(Hash_Table *t, unsigned i
 void
 Hash_InitTable(Hash_Table *t)
 {
-	size_t n = 16, i;
+	unsigned int n = 16, i;
 	struct Hash_Entry **hp;
 
 	t->numEntries = 0;
@@ -146,7 +146,7 @@ Hash_DeleteTable(Hash_Table *t)
 	struct Hash_Entry **hp, *h, *nexth = NULL;
 	int i;
 
-	for (hp = t->buckets, i = t->bucketsSize; --i >= 0;) {
+	for (hp = t->buckets, i = (int)t->bucketsSize; --i >= 0;) {
 		for (h = *hp++; h != NULL; h = nexth) {
 			nexth = h->next;
 			free(h);
@@ -191,19 +191,20 @@ static void
 RebuildTable(Hash_Table *t)
 {
 	Hash_Entry *e, *next = NULL, **hp, **xp;
-	int i, mask;
+	int i;
+	unsigned int mask, oldsize, newsize;
 	Hash_Entry **oldhp;
-	int oldsize;
 
 	oldhp = t->buckets;
-	oldsize = i = t->bucketsSize;
-	i <<= 1;
-	t->bucketsSize = i;
-	t->bucketsMask = mask = i - 1;
-	t->buckets = hp = bmake_malloc(sizeof(*hp) * i);
+	oldsize = t->bucketsSize;
+	newsize = oldsize << 1;
+	t->bucketsSize = (unsigned int)newsize;
+	t->bucketsMask = mask = newsize - 1;
+	t->buckets = hp = bmake_malloc(sizeof(*hp) * newsize);
+	i = (int)newsize;
 	while (--i >= 0)
 		*hp++ = NULL;
-	for (hp = oldhp, i = oldsize; --i >= 0;) {
+	for (hp = oldhp, i = (int)oldsize; --i >= 0;) {
 		for (e = *hp++; e != NULL; e = next) {
 			next = e->next;
 			xp = &t->buckets[e->namehash & mask];
@@ -349,6 +350,6 @@ Hash_ForEach(Hash_Table *t, void (*actio
 void
 Hash_DebugStats(Hash_Table *t, const char *name)
 {
-	DEBUG4(HASH, "Hash_Table %s: size=%d numEntries=%d maxchain=%d\n",
+	DEBUG4(HASH, "Hash_Table %s: size=%u numEntries=%u maxchain=%u\n",
 	       name, t->bucketsSize, t->numEntries, t->maxchain);
 }

Index: src/usr.bin/make/hash.h
diff -u src/usr.bin/make/hash.h:1.25 src/usr.bin/make/hash.h:1.26
--- src/usr.bin/make/hash.h:1.25	Sun Sep 27 21:35:16 2020
+++ src/usr.bin/make/hash.h	Mon Oct  5 20:21:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.h,v 1.25 2020/09/27 21:35:16 rillig Exp $	*/
+/*	$NetBSD: hash.h,v 1.26 2020/10/05 20:21:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -90,10 +90,10 @@ typedef struct Hash_Entry {
 typedef struct Hash_Table {
     Hash_Entry **buckets;	/* Pointers to Hash_Entry, one
 				 * for each bucket in the table. */
-    int bucketsSize;
-    int numEntries;		/* Number of entries in the table. */
-    int bucketsMask;		/* Used to select the bucket for a hash. */
-    int maxchain;		/* max length of chain detected */
+    unsigned int bucketsSize;
+    unsigned int numEntries;	/* Number of entries in the table. */
+    unsigned int bucketsMask;	/* Used to select the bucket for a hash. */
+    unsigned int maxchain;	/* max length of chain detected */
 } Hash_Table;
 
 /*
@@ -102,7 +102,7 @@ typedef struct Hash_Table {
  */
 typedef struct Hash_Search {
     Hash_Table *table;		/* Table being searched. */
-    int nextBucket;		/* Next bucket to check (after current). */
+    unsigned int nextBucket;	/* Next bucket to check (after current). */
     Hash_Entry *entry;		/* Next entry to check in current bucket. */
 } Hash_Search;
 

Reply via email to