bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

argp: Don't pass invalid arguments to isspace() and isalnum()


From: Bruno Haible
Subject: argp: Don't pass invalid arguments to isspace() and isalnum()
Date: Tue, 08 Dec 2020 19:24:38 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-193-generic; KDE/5.18.0; x86_64; ; )

isspace() and isalnum() should not be given arguments in the range
-0x80 .. -0x01, says POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/isspace.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/isalnum.html

This patch fixes argp-help.c accordingly. (Although, admittedly, most
people only pass ASCII strings as long options.)


2020-12-08  Bruno Haible  <bruno@clisp.org>

        argp: Don't pass invalid arguments to isspace() and isalnum().
        * lib/argp-help.c (canon_doc_option): Cast character to 'unsigned int'
        before passing it to isspace() or isalnum().

diff --git a/lib/argp-help.c b/lib/argp-help.c
index 03fc6c7..acab001 100644
--- a/lib/argp-help.c
+++ b/lib/argp-help.c
@@ -720,12 +720,12 @@ canon_doc_option (const char **name)
 {
   int non_opt;
   /* Skip initial whitespace.  */
-  while (isspace (**name))
+  while (isspace ((unsigned char) **name))
     (*name)++;
   /* Decide whether this looks like an option (leading '-') or not.  */
   non_opt = (**name != '-');
   /* Skip until part of name used for sorting.  */
-  while (**name && !isalnum (**name))
+  while (**name && !isalnum ((unsigned char) **name))
     (*name)++;
   return non_opt;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]