Skip to content

Commit 9e64601

Browse files
Unique-Usmanchriscool
authored andcommitted
version: replace manual ASCII checks with isprint() for clarity
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 <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]>
1 parent 5f8f708 commit 9e64601

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

version.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "git-compat-util.h"
22
#include "version.h"
33
#include "strbuf.h"
4+
#include "sane-ctype.h"
45

56
#ifndef GIT_VERSION_H
67
# include "version-def.h"
@@ -34,7 +35,7 @@ const char *git_user_agent_sanitized(void)
3435
strbuf_addstr(&buf, git_user_agent());
3536
strbuf_trim(&buf);
3637
for (size_t i = 0; i < buf.len; i++) {
37-
if (buf.buf[i] <= 32 || buf.buf[i] >= 127)
38+
if (!isprint(buf.buf[i]) || buf.buf[i] == ' ')
3839
buf.buf[i] = '.';
3940
}
4041
agent = buf.buf;

0 commit comments

Comments
 (0)