CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:37:56 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix error handling of integer arguments

Previously, flashctl accepted the command 'erase 0x 0x' as valid, even
though the numbers are not valid hex numbers.

Pointed out by lint, which complained about the wrong type conversion
for tolower, isxdigit and isdigit.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:37:56 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix error handling of integer arguments

Previously, flashctl accepted the command 'erase 0x 0x' as valid, even
though the numbers are not valid hex numbers.

Pointed out by lint, which complained about the wrong type conversion
for tolower, isxdigit and isdigit.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.4 src/usr.sbin/flashctl/flashctl.c:1.5
--- src/usr.sbin/flashctl/flashctl.c:1.4	Tue May 24 13:01:53 2011
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:37:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.4 2011/05/24 13:01:53 joerg Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.5 2023/01/08 15:37:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -229,12 +229,12 @@ to_intmax(intmax_t *num, const char *str
 	char *endptr;
 
 	errno = 0;
-	if (str[0] == '0' && tolower((int )str[1]) == 'x') {
-		if (!isxdigit((int )str[0]))
+	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
+		if (!isxdigit((unsigned char)str[2]))
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 16);
 	} else {
-		if (!isdigit((int )str[0]))
+		if (!isdigit((unsigned char)str[0]))
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 10);
 	}



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:49:51 UTC 2023

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
flashctl: enable lint's strict bool mode

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/Makefile
diff -u src/usr.sbin/flashctl/Makefile:1.2 src/usr.sbin/flashctl/Makefile:1.3
--- src/usr.sbin/flashctl/Makefile:1.2	Sun Feb 27 17:51:45 2011
+++ src/usr.sbin/flashctl/Makefile	Sun Jan  8 15:49:51 2023
@@ -1,9 +1,10 @@
-# $NetBSD: Makefile,v 1.2 2011/02/27 17:51:45 ahoka Exp $
+# $NetBSD: Makefile,v 1.3 2023/01/08 15:49:51 rillig Exp $
 
 SRCS=		flashctl.c
 
 PROG=		flashctl
 MAN=		flashctl.8
+LINTFLAGS+=	-T		# strict bool mode
 
 WARNS=		4
 

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.5 src/usr.sbin/flashctl/flashctl.c:1.6
--- src/usr.sbin/flashctl/flashctl.c:1.5	Sun Jan  8 15:37:56 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:49:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.5 2023/01/08 15:37:56 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.6 2023/01/08 15:49:51 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -72,29 +72,29 @@ main(int argc, char **argv)
 		err(EXIT_FAILURE, "can't open flash device");
 	}
 
-	if (!strcmp("erase", command)) {
+	if (strcmp("erase", command) == 0) {
 		struct flash_info_params ip;
 		struct flash_erase_params ep;
 
 		error = ioctl(fd, FLASH_GET_INFO, &ip);
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_GET_INFO");
 			goto out;
 		}
 
 		if (argc == 2) {
 			error = to_intmax(&n, argv[0]);
-			if (error) {
+			if (error != 0) {
 warnx("%s", strerror(error));
 goto out;
 			}
 			ep.ep_addr = n;
 
-			if (!strcmp("all", argv[1])) {
+			if (strcmp("all", argv[1]) == 0) {
 ep.ep_len = ip.ip_flash_size;
 			} else {
 error = to_intmax(&n, argv[1]);
-if (error) {
+if (error != 0) {
 	warnx("%s", strerror(error));
 	goto out;
 }
@@ -105,20 +105,20 @@ main(int argc, char **argv)
 			error = 1;
 			goto out;
 		}
-		
+
 		printf("Erasing %jx bytes starting from %jx\n",
-		(uintmax_t )ep.ep_len, (uintmax_t )ep.ep_addr);
-		
+		(uintmax_t)ep.ep_len, (uintmax_t)ep.ep_addr);
+
 		error = ioctl(fd, FLASH_ERASE_BLOCK, &ep);
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_ERASE_BLOCK");
 			goto out;
 		}
-	} else if (!strcmp("identify", command)) {
+	} else if (strcmp("identify", command) == 0) {
 		struct flash_info_params ip;
-		
+
 		error = ioctl(fd, FLASH_GET_INFO, &ip);
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_GET_INFO");
 			goto out;
 		}
@@ -138,23 +138,23 @@ main(int argc, char **argv)
 
 		/* TODO: humanize */
 		printf("Capacity %jd Mbytes, %jd pages, %ju bytes/page\n", 
-		(intmax_t )ip.ip_flash_size / 1024 / 1024,
-		(intmax_t )ip.ip_flash_size / ip.ip_page_size,
-		(intmax_t )ip.ip_page_size);
+		(intmax_t)ip.ip_flash_size / 1024 / 1024,
+		(intmax_t)ip.ip_flash_size / ip.ip_page_size,
+		(intmax_t)ip.ip_page_size);
 
 		if (ip.ip_flash_type == FLASH_TYPE_NAND) {
 			printf("Block size %jd Kbytes, %jd pages/block\n",
-			(intmax_t )ip.ip_erase_size / 1024,
-			(intmax_t )ip.ip_erase_size / ip.ip_page_size);
+			(intmax_t)ip.ip_erase_size / 1024,
+			(intmax_t)ip.ip_erase_size / ip.ip_page_size);
 		}
-	} else if (!strcmp("badblocks", command)) {
+	} else if (strcmp("badblocks", command) == 0) {
 		struct flash_info_params ip;
 		struct flash_badblock_params bbp;
 		flash_off_t addr;
 		bool hasbad = false;
 
 		error = ioctl(fd, FLASH_GET_INFO, &ip);
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLASH_GET_INFO");
 			goto out;
 		}
@@ -164,9 +164,9 @@ main(int argc, char **argv)
 		addr = 0;
 		while (addr < ip.ip_flash_size) {
 			bbp.bbp_addr = addr;
-			
+
 			error = ioctl(fd, FLASH_BLOCK_ISBAD, &bbp);
-			if (error) {
+			if (error != 0) {
 warn("ioctl: FLASH_BLOCK_ISBAD");
 goto out;
 			}
@@ -184,7 +184,7 @@ main(int argc, char **argv)
 		} else {
 			printf("No bad blocks found.\n");
 		}
-	} else if (!strcmp("markbad", command)) {
+	} else if (strcmp("markbad", command) == 0) {
 		flash_off_t address;
 
 		/* TODO: maybe we should let the user specify
@@ -195,26 +195,26 @@ main(int argc, char **argv)
 			error = 1;
 			goto out;
 		}
-		
+
 		error = to_intmax(&n, argv[0]);
-		if (error) {
+		if (error != 0) {
 			warnx("%s", strerror(error));
 			goto out;
 		}
 
 		address = n;
-		
+
 		printf("Marking block 0x%jx as bad.\n",
-		(intmax_t )address);
+		(intmax_t)address);
 
 		error = ioctl(fd, FLASH_BLOCK_MARKBAD, &address);
-		if (error) {
+		if (error != 0) {
 			warn("ioctl: FLAS

CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:49:51 UTC 2023

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
flashctl: enable lint's strict bool mode

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:52:30 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: unexport local functions, add CVS ID

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:52:30 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: unexport local functions, add CVS ID

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.6 src/usr.sbin/flashctl/flashctl.c:1.7
--- src/usr.sbin/flashctl/flashctl.c:1.6	Sun Jan  8 15:49:51 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:52:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.6 2023/01/08 15:49:51 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -31,6 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#include 
+__RCSID("$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $");
+
 #include 
 #include 
 #include 
@@ -45,8 +48,8 @@
 #include 
 
 
-void usage(void);
-int to_intmax(intmax_t *, const char *);
+static void usage(void);
+static int to_intmax(intmax_t *, const char *);
 
 int
 main(int argc, char **argv)



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:55:26 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: remove trailing whitespace

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 15:55:26 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: remove trailing whitespace

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.7 src/usr.sbin/flashctl/flashctl.c:1.8
--- src/usr.sbin/flashctl/flashctl.c:1.7	Sun Jan  8 15:52:30 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 15:55:25 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.7 2023/01/08 15:52:30 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $");
 
 #include 
 #include 
@@ -140,7 +140,7 @@ main(int argc, char **argv)
 		printf("\n");
 
 		/* TODO: humanize */
-		printf("Capacity %jd Mbytes, %jd pages, %ju bytes/page\n", 
+		printf("Capacity %jd Mbytes, %jd pages, %ju bytes/page\n",
 		(intmax_t)ip.ip_flash_size / 1024 / 1024,
 		(intmax_t)ip.ip_flash_size / ip.ip_page_size,
 		(intmax_t)ip.ip_page_size);



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 16:01:50 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: use consistent markup in usage message


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2023-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  8 16:01:50 UTC 2023

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: use consistent markup in usage message


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.8 src/usr.sbin/flashctl/flashctl.c:1.9
--- src/usr.sbin/flashctl/flashctl.c:1.8	Sun Jan  8 15:55:25 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun Jan  8 16:01:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.8 2023/01/08 15:55:25 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $");
 
 #include 
 #include 
@@ -252,12 +252,12 @@ to_intmax(intmax_t *num, const char *str
 void
 usage(void)
 {
-	fprintf(stderr, "usage: %s device identify\n",
+	fprintf(stderr, "usage: %s  identify\n",
 	getprogname());
-	fprintf(stderr, "   %s device erase  |all\n",
+	fprintf(stderr, "   %s  erase  |all\n",
 	getprogname());
-	fprintf(stderr, "   %s device badblocks\n",
+	fprintf(stderr, "   %s  badblocks\n",
 	getprogname());
-	fprintf(stderr, "   %s device markbad \n",
+	fprintf(stderr, "   %s  markbad \n",
 	getprogname());
 }



CVS commit: src/usr.sbin/flashctl

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 19:03:55 UTC 2024

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix lint's strict bool mode with Clang preprocessor

Treating the return value from the  character classification
functions as an 'int' is neither elegant nor idiomatic, but it works for
now.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 19:03:55 UTC 2024

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix lint's strict bool mode with Clang preprocessor

Treating the return value from the  character classification
functions as an 'int' is neither elegant nor idiomatic, but it works for
now.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.9 src/usr.sbin/flashctl/flashctl.c:1.10
--- src/usr.sbin/flashctl/flashctl.c:1.9	Sun Jan  8 16:01:49 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun May 12 19:03:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $");
 
 #include 
 #include 
@@ -233,11 +233,11 @@ to_intmax(intmax_t *num, const char *str
 
 	errno = 0;
 	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
-		if (!isxdigit((unsigned char)str[2]))
+		if (isxdigit((unsigned char)str[2]) == 0)
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 16);
 	} else {
-		if (!isdigit((unsigned char)str[0]))
+		if (isdigit((unsigned char)str[0]) == 0)
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 10);
 	}



CVS commit: src/usr.sbin/flashctl

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 20:38:05 UTC 2024

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
usr.sbin/flashctl: skip lint's strict bool mode with Clang

The strict bool mode is already checked in GCC mode, so restore the
previous idiomatic code.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 20:38:05 UTC 2024

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
usr.sbin/flashctl: skip lint's strict bool mode with Clang

The strict bool mode is already checked in GCC mode, so restore the
previous idiomatic code.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/Makefile
diff -u src/usr.sbin/flashctl/Makefile:1.3 src/usr.sbin/flashctl/Makefile:1.4
--- src/usr.sbin/flashctl/Makefile:1.3	Sun Jan  8 15:49:51 2023
+++ src/usr.sbin/flashctl/Makefile	Mon May 13 20:38:05 2024
@@ -1,11 +1,12 @@
-# $NetBSD: Makefile,v 1.3 2023/01/08 15:49:51 rillig Exp $
+# $NetBSD: Makefile,v 1.4 2024/05/13 20:38:05 rillig Exp $
 
 SRCS=		flashctl.c
 
 PROG=		flashctl
 MAN=		flashctl.8
-LINTFLAGS+=	-T		# strict bool mode
+LINTFLAGS+=	${MKLLVM:U-T:D}	# strict bool mode
 
 WARNS=		4
 
 .include 
+

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.10 src/usr.sbin/flashctl/flashctl.c:1.11
--- src/usr.sbin/flashctl/flashctl.c:1.10	Sun May 12 19:03:55 2024
+++ src/usr.sbin/flashctl/flashctl.c	Mon May 13 20:38:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.11 2024/05/13 20:38:05 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.11 2024/05/13 20:38:05 rillig Exp $");
 
 #include 
 #include 
@@ -233,11 +233,11 @@ to_intmax(intmax_t *num, const char *str
 
 	errno = 0;
 	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
-		if (isxdigit((unsigned char)str[2]) == 0)
+		if (!isxdigit((unsigned char)str[2]))
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 16);
 	} else {
-		if (isdigit((unsigned char)str[0]) == 0)
+		if (!isdigit((unsigned char)str[0]))
 			return EINVAL;
 		*num = strtoimax(str, &endptr, 10);
 	}



Re: CVS commit: src/usr.sbin/flashctl

2024-05-13 Thread Taylor R Campbell
> Module Name:src
> Committed By:   rillig
> Date:   Sun May 12 19:03:55 UTC 2024
> 
> Modified Files:
> src/usr.sbin/flashctl: flashctl.c
> 
> Log Message:
> flashctl: fix lint's strict bool mode with Clang preprocessor
> 
> Treating the return value from the  character classification
> functions as an 'int' is neither elegant nor idiomatic, but it works for
> now.
> 
> -   if (!isxdigit((unsigned char)str[2]))
> +   if (isxdigit((unsigned char)str[2]) == 0)

Why is this change necessary?  Weren't you teaching lint to handle
this case without complaining?  We shouldn't change anything like

if (!isxdigit(...))
if (ferror(...))

to

if (isxdigit(...) == 0)
if (ferror(...) != 0)

The original is clearer and idiomatic code, even if it's a little
silly that the return value is declared as int and not bool
(presumably for historical reasons, if the interfaces were defined
before bool existed).


lint's strict bool mode (was: Re: CVS commit: src/usr.sbin/flashctl)

2024-05-13 Thread Roland Illig
Am 13.05.2024 um 16:06 schrieb Taylor R Campbell:
>> Module Name:src
>> Committed By:   rillig
>> Date:   Sun May 12 19:03:55 UTC 2024
>>
>> Modified Files:
>> src/usr.sbin/flashctl: flashctl.c
>>
>> Log Message:
>> flashctl: fix lint's strict bool mode with Clang preprocessor
>>
>> Treating the return value from the  character classification
>> functions as an 'int' is neither elegant nor idiomatic, but it works for
>> now.
>>
>> -   if (!isxdigit((unsigned char)str[2]))
>> +   if (isxdigit((unsigned char)str[2]) == 0)
>
> Why is this change necessary?  Weren't you teaching lint to handle
> this case without complaining?

Yes, I did. The thing is that I only ever tested lint's strict bool mode
with the GCC preprocessor, and that preprocessor marks every token from
a macro expansion as coming from a system header or coming from the
user's code. Therefore, lint could be more lenient when checking the
result of the isxdigit macro, as its main operator, the cast to '(int)',
is from a system header, so it's OK that it has the "wrong" type.

On the other hand, the strcmp function is not listed in "namespace.h"
and does not have a macro definition, and although the function
declaration comes from a system header, the GCC preprocessor does not
mark the function call expression as coming from a system header.

This is the difference by which lint treats 'isxdigit(ch)' as bool-like
but 'strcmp(s1, s2)' as strictly 'int'.

A few days or weeks ago, Christos started builds that have both
MKLLVM=yes and MKLINT=yes, thus using the Clang preprocessor as lint's
preprocessor. Apparently nobody else has done this in the last few
years. Clang's preprocessor's output does not mark the tokens from macro
expansions as coming from a system header or from the user's code. Due
to this, lint can no longer be lenient for system header macro
expansions as it doesn't get the system header information anymore.

> We shouldn't change anything like
>
>   if (!isxdigit(...))
>   if (ferror(...))
>
> to
>
>   if (isxdigit(...) == 0)
>   if (ferror(...) != 0)
>
> The original is clearer and idiomatic code, even if it's a little
> silly that the return value is declared as int and not bool
> (presumably for historical reasons, if the interfaces were defined
> before bool existed).

I agree. For usr.bin/error, I tried a different variant, namely to only
activate lint's strict bool mode when MKLLVM is undefined, thus when the
GCC preprocessor is used. I guess activating the strict bool mode only
in GCC mode is good enough to catch all type mismatches.

The combination of MKLLVM=yes MKLINT=yes is also the cause why lint now
allows do-while-0 even in strict bool mode, as the FD_ZERO macro uses
that idiom and I didn't dare to change the macro to do-while-false, as
that would either require , or to deviate from the idiom
by using 'do { ... } while (0 != 0)', as that would look suspicious.

I will switch usr.sbin/flashctl to the only-in-GCC-mode variant and
restore the previous idiomatic code.

Roland