Module Name: src Committed By: rillig Date: Tue Oct 26 21:37:27 UTC 2021
Modified Files: src/tests/usr.bin/indent: token_comment.c src/usr.bin/indent: indent.c pr_comment.c Log Message: indent: clean up process_comment There is no undefined behavior since the compared characters are always from the basic execution character set. All other cases are covered by the condition above for now_len. Fix debug logging for non-ASCII characters, previously a character was output as \xffffffc3. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/token_comment.c cvs rdiff -u -r1.161 -r1.162 src/usr.bin/indent/indent.c cvs rdiff -u -r1.86 -r1.87 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/indent/token_comment.c diff -u src/tests/usr.bin/indent/token_comment.c:1.7 src/tests/usr.bin/indent/token_comment.c:1.8 --- src/tests/usr.bin/indent/token_comment.c:1.7 Sun Oct 24 21:55:07 2021 +++ src/tests/usr.bin/indent/token_comment.c Tue Oct 26 21:37:27 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: token_comment.c,v 1.7 2021/10/24 21:55:07 rillig Exp $ */ +/* $NetBSD: token_comment.c,v 1.8 2021/10/26 21:37:27 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -729,3 +729,15 @@ end */ #indent end #indent run-equals-input -nfc1 + + +#indent input +/* comment comment comment comment Ümläute */ +#indent end + +#indent run -l40 +/* + * comment comment comment comment + * Ümläute + */ +#indent end Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.161 src/usr.bin/indent/indent.c:1.162 --- src/usr.bin/indent/indent.c:1.161 Tue Oct 26 20:43:35 2021 +++ src/usr.bin/indent/indent.c Tue Oct 26 21:37:27 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.161 2021/10/26 20:43:35 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.162 2021/10/26 21:37:27 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.161 2021/10/26 20:43:35 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.162 2021/10/26 21:37:27 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -1562,7 +1562,7 @@ debug_vis_range(const char *prefix, cons else if (*p == '\t') debug_printf("\\t"); else - debug_printf("\\x%02x", *p); + debug_printf("\\x%02x", (unsigned char)*p); } debug_printf("%s", suffix); } Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.86 src/usr.bin/indent/pr_comment.c:1.87 --- src/usr.bin/indent/pr_comment.c:1.86 Tue Oct 26 21:23:52 2021 +++ src/usr.bin/indent/pr_comment.c Tue Oct 26 21:37:27 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.86 2021/10/26 21:23:52 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.87 2021/10/26 21:37:27 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,12 +43,13 @@ static char sccsid[] = "@(#)pr_comment.c #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.86 2021/10/26 21:23:52 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.87 2021/10/26 21:37:27 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif #include <assert.h> +#include <ctype.h> #include <stdio.h> #include <string.h> @@ -333,8 +334,7 @@ process_comment(void) if (now_len <= adj_max_line_length || !may_wrap) break; - /* XXX: signed character comparison '>' does not work for UTF-8 */ - if (com.e[-1] <= ' ') + if (isspace((unsigned char)com.e[-1])) break; if (last_blank == -1) { /* only a single word in this line */