Skip to content

Commit 5e4d567

Browse files
committed
feat(util): Allow trailing newline when converting string to int/uint
1 parent 9f35c6a commit 5e4d567

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ str_to_uint(const char *str, unsigned int *out)
120120
errno = 0;
121121
value = strtoul(str, &str_endp, 0);
122122

123-
if (errno != 0 || str == str_endp || *str_endp != '\0') {
123+
if (errno != 0 || str == str_endp || (*str_endp != '\0' && *str_endp != '\n')) {
124124
return EINVAL;
125125
}
126126

@@ -141,7 +141,7 @@ str_to_int(const char *str, int *out)
141141
errno = 0;
142142
value = strtol(str, &str_endp, 0);
143143

144-
if (errno != 0 || str == str_endp || *str_endp != '\0') {
144+
if (errno != 0 || str == str_endp || (*str_endp != '\0' && *str_endp != '\n')) {
145145
return EINVAL;
146146
}
147147

0 commit comments

Comments
 (0)