From b23137b0e6e8f0e9289e9bea6be66f3be99936b2 Mon Sep 17 00:00:00 2001 From: hanjinpeng Date: Thu, 17 Sep 2026 02:34:28 -0400 Subject: [PATCH] main.c: do not print a NULL charset name When listing with a format or with --known but without a charset, recode(1) uses the default charset. If that charset is unknown, the error message used argv[optind], which is NULL at that point: $ DEFAULT_CHARSET=no-such-charset recode -ld recode: Charset `(null)' is unknown or ambiguous Report the default charset name instead. --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 01e7dc9..a370093 100644 --- a/src/main.c +++ b/src/main.c @@ -670,8 +670,13 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"), if (!alias) { + /* No charset was given: report the default one. */ + const char *name = getenv ("DEFAULT_CHARSET"); + + if (!name || !*name) + name = locale_charset (); error (0, 0, _("Charset `%s' is unknown or ambiguous"), - argv[optind]); + name ? name : ""); usage (EXIT_FAILURE, 1); }