]> git.ipfire.org Git - thirdparty/git.git/commitdiff
version: replace manual ASCII checks with isprint() for clarity
authorUsman Akinyemi <usmanakinyemi202@gmail.com>
Sat, 15 Feb 2025 15:50:47 +0000 (21:20 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Feb 2025 17:05:12 +0000 (09:05 -0800)
Since the isprint() function checks for printable characters, let's
replace the existing hardcoded ASCII checks with it. However, since
the original checks also handled spaces, we need to account for spaces
explicitly in the new check.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
version.c

index 4d763ab48dd76c0445e5ea390ff4c1f35c1a4b12..6cfbb8ca5630480bf45990cbdd5e0084d8378774 100644 (file)
--- a/version.c
+++ b/version.c
@@ -2,6 +2,7 @@
 #include "version.h"
 #include "version-def.h"
 #include "strbuf.h"
+#include "sane-ctype.h"
 
 const char git_version_string[] = GIT_VERSION;
 const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
@@ -29,7 +30,7 @@ const char *git_user_agent_sanitized(void)
                strbuf_addstr(&buf, git_user_agent());
                strbuf_trim(&buf);
                for (size_t i = 0; i < buf.len; i++) {
-                       if (buf.buf[i] <= 32 || buf.buf[i] >= 127)
+                       if (!isprint(buf.buf[i]) || buf.buf[i] == ' ')
                                buf.buf[i] = '.';
                }
                agent = buf.buf;