Subject: bug#74196: maint: assume proper behavior of tolower

From: Collin Funk <[email-masked]>
Date: Sun, 03 Nov 2024 15:47:22 -0800

Some pre-standard C implementations of tolower had undefined behavior if
the character passed to it was not an uppercase character.

This patch removes the isupper check before calling tolower since any
reasonable platform will behave correctly.

Collin

>From 118dba90c89a97c4343bbf6afd19c2c92919481f Mon Sep 17 00:00:00 2001
From: Collin Funk <[email-masked]>
Date: Sun, 3 Nov 2024 15:41:46 -0800
Subject: [PATCH] maint: assume proper behavior of tolower

* gzip.h (tolow): Remove macro.
* tailor.h (casemap): Use tolower instead of tolow.
* util.c (strlwr): Likewise.
---
 gzip.h   | 2 --
 tailor.h | 8 ++++----
 util.c   | 2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/gzip.h b/gzip.h
index c895674..606b2bc 100644
--- a/gzip.h
+++ b/gzip.h
@@ -226,8 +226,6 @@ extern int save_orig_name; /* set if original name must be saved */
 #define seekable()    0  /* force sequential output */
 #define translate_eol 0  /* no option -a yet */
 
-#define tolow(c)  (isupper (c) ? tolower (c) : (c))  /* force to lower case */
-
 /* Macros for getting two-byte and four-byte header values */
 #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
 #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
diff --git a/tailor.h b/tailor.h
index b2878b2..5f309a8 100644
--- a/tailor.h
+++ b/tailor.h
@@ -54,7 +54,7 @@
 #  define Z_SUFFIX "z"
 #  define NO_SIZE_CHECK
 #  define UNLINK_READONLY_BUG
-#  define casemap(c) tolow(c) /* Force file names to lower case */
+#  define casemap(c) tolower(c) /* Force file names to lower case */
 #  include <io.h>
 #  define OS_CODE  0x00
 #  define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
@@ -71,7 +71,7 @@
 #    define NO_MULTIPLE_DOTS
 #    define MAX_EXT_CHARS 3
 #    define Z_SUFFIX "z"
-#    define casemap(c) tolow(c)
+#    define casemap(c) tolower(c)
 #  endif
 #  define UNLINK_READONLY_BUG
 #  include <io.h>
@@ -107,7 +107,7 @@
 #    define NO_MULTIPLE_DOTS
 #    define MAX_EXT_CHARS 3
 #    define Z_SUFFIX "z"
-#    define casemap(c) tolow(c) /* Force file names to lower case */
+#    define casemap(c) tolower(c) /* Force file names to lower case */
 #  endif
 #  define OS_CODE  0x0b
 #endif
@@ -140,7 +140,7 @@
 #    define NO_MULTIPLE_DOTS
 #    define MAX_EXT_CHARS 3
 #    define Z_SUFFIX "z"
-#    define casemap(c) tolow(c) /* Force file names to lower case */
+#    define casemap(c) tolower(c) /* Force file names to lower case */
 #  endif
 #endif
 
diff --git a/util.c b/util.c
index 6fcbf67..86de1ba 100644
--- a/util.c
+++ b/util.c
@@ -228,7 +228,7 @@ strlwr (char *s)
 {
     char *t;
     for (t = s; *t; t++)
-      *t = tolow ((unsigned char) *t);
+      *t = tolower ((unsigned char) *t);
     return s;
 }
 
-- 
2.47.0