[krbdev.mit.edu #7652] [PATCH] krb5 : tests, fix dbtest compilation warnings

Gilles Espinasse via RT rt-comment at krbdev.mit.edu
Fri May 31 11:55:29 EDT 2013


dbtest.c: In function 'main':
dbtest.c:187: warning: comparison between signed and unsigned integer expressions
dbtest.c:202: warning: comparison between signed and unsigned integer expressions
dbtest.c: In function 'get':
dbtest.c:379: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c:381: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c:389: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c: In function 'put':
dbtest.c:429: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c: In function 'rem':
dbtest.c:448: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c: In function 'seq':
dbtest.c:483: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c:485: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c:493: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c: In function 'dump':
dbtest.c:524: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c:526: warning: ignoring return value of 'write', declared with attribute warn_unused_result
dbtest.c: In function 'rfile':
dbtest.c:714: warning: ignoring return value of 'read', declared with attribute warn_unused_result

Casting to (void) does nothing with fortify in use for function declared __attribute__ ((warn_unused_result))
So check the returned value a minima.

Change XXlineno type to match lineno
Cast to ssize_t to fix remaining signed vs unsigned comparison

Signed-off-by: Gilles Espinasse <g.esp at free.fr>
---
 src/plugins/kdb/db2/libdb2/test/dbtest.c |   45 +++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/src/plugins/kdb/db2/libdb2/test/dbtest.c b/src/plugins/kdb/db2/libdb2/test/dbtest.c
index 210be87..7331be7 100644
--- a/src/plugins/kdb/db2/libdb2/test/dbtest.c
+++ b/src/plugins/kdb/db2/libdb2/test/dbtest.c
@@ -90,7 +90,7 @@ u_int flags;				/* Current DB flags. */
 int ofd = STDOUT_FILENO;		/* Standard output fd. */
 
 DB *XXdbp;				/* Global for gdb. */
-int XXlineno;				/* Fast breakpoint for gdb. */
+u_long XXlineno;			/* Fast breakpoint for gdb. */
 
 int
 main(argc, argv)
@@ -199,7 +199,7 @@ main(argc, argv)
 			/* Don't display the newline, if CR at EOL. */
 			if (p[len - 2] == '\r')
 				--len;
-			if (write(ofd, p + 1, len - 1) != len - 1 ||
+			if (write(ofd, p + 1, len - 1) != (ssize_t)len - 1 ||
 			    write(ofd, "\n", 1) != 1)
 				err("write: %s", strerror(errno));
 			break;
@@ -376,9 +376,11 @@ get(dbp, kp)
 
 	switch (dbp->get(dbp, kp, &data, flags)) {
 	case 0:
-		(void)write(ofd, data.data, data.size);
+		if (write(ofd, data.data, data.size) != (ssize_t)data.size)
+			err("write: %s", strerror(errno));
 		if (ofd == STDOUT_FILENO)
-			(void)write(ofd, "\n", 1);
+			if (write(ofd, "\n", 1) !=1)
+				err("write: %s", strerror(errno));
 		break;
 	case -1:
 		err("line %lu: get: %s", lineno, strerror(errno));
@@ -386,7 +388,8 @@ get(dbp, kp)
 	case 1:
 #define	NOSUCHKEY	"get failed, no such key\n"
 		if (ofd != STDOUT_FILENO) {
-			(void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
+			if (write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1) != sizeof(NOSUCHKEY) - 1)
+				err("write: %s", strerror(errno));
 			exit(1);
 		} else
 			(void)fprintf(stderr, "%lu: %.*s: %s",
@@ -426,7 +429,8 @@ put(dbp, kp, dp)
 		err("line %lu: put: %s", lineno, strerror(errno));
 		/* NOTREACHED */
 	case 1:
-		(void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1);
+		if (write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1) != sizeof(NOOVERWRITE) - 1)
+			err("write: %s", strerror(errno));
 		break;
 	}
 }
@@ -444,9 +448,10 @@ rem(dbp, kp)
 		/* NOTREACHED */
 	case 1:
 #define	NOSUCHKEY	"rem failed, no such key\n"
-		if (ofd != STDOUT_FILENO)
-			(void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
-		else if (flags != R_CURSOR)
+		if (ofd != STDOUT_FILENO) {
+			if (write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1) != sizeof(NOSUCHKEY) - 1)
+				err("write: %s", strerror(errno));
+		} else if (flags != R_CURSOR)
 			(void)fprintf(stderr, "%lu: %.*s: %s",
 			    lineno, (int) MIN(kp->size, 20), (char *) kp->data,
 				      NOSUCHKEY);
@@ -480,18 +485,21 @@ seq(dbp, kp)
 
 	switch (dbp->seq(dbp, kp, &data, flags)) {
 	case 0:
-		(void)write(ofd, data.data, data.size);
+		if (write(ofd, data.data, data.size) != (ssize_t)data.size)
+			err("write: %s", strerror(errno));
 		if (ofd == STDOUT_FILENO)
-			(void)write(ofd, "\n", 1);
+			if (write(ofd, "\n", 1) != 1)
+				err("write: %s", strerror(errno));
 		break;
 	case -1:
 		err("line %lu: seq: %s", lineno, strerror(errno));
 		/* NOTREACHED */
 	case 1:
 #define	NOSUCHKEY	"seq failed, no such key\n"
-		if (ofd != STDOUT_FILENO)
-			(void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
-		else if (flags == R_CURSOR)
+		if (ofd != STDOUT_FILENO) {
+			if (write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1) != sizeof(NOSUCHKEY) - 1)
+				err("write: %s", strerror(errno));
+		} else if (flags == R_CURSOR)
 			(void)fprintf(stderr, "%lu: %.*s: %s",
 			    lineno, (int) MIN(kp->size, 20), (char *) kp->data,
 				      NOSUCHKEY);
@@ -521,9 +529,11 @@ dump(dbp, rev)
 	for (;; lflags = nflags)
 		switch (dbp->seq(dbp, &key, &data, lflags)) {
 		case 0:
-			(void)write(ofd, data.data, data.size);
+			if (write(ofd, data.data, data.size) != (ssize_t)data.size)
+				err("write: %s", strerror(errno));
 			if (ofd == STDOUT_FILENO)
-				(void)write(ofd, "\n", 1);
+				if (write(ofd, "\n", 1) != 1)
+					err("write: %s", strerror(errno));
 			break;
 		case 1:
 			goto done;
@@ -711,7 +721,8 @@ rfile(name, lenp)
 #endif
 	if ((p = (void *)malloc((u_int)sb.st_size)) == NULL)
 		err("%s", strerror(errno));
-	(void)read(fd, p, (int)sb.st_size);
+	if (read(fd, p, (int)sb.st_size) == -1)
+		err("%s", strerror(errno));
 	*lenp = sb.st_size;
 	(void)close(fd);
 	return (p);
-- 
1.7.10.4




More information about the krb5-bugs mailing list