Skip to content

Commit f95a700

Browse files
committed
Correct return type of strlen function
strlen() returns the length of the input string, which is always non‑negative. Switching the return type to size_t is more accurately.
1 parent 6bccb72 commit f95a700

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/libc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ static inline int byte_is_match(uint32_t w, uint32_t pat)
2020
}
2121

2222
/* strlen that scans by words whenever possible for efficiency. */
23-
int32_t strlen(const char *s)
23+
size_t strlen(const char *s)
2424
{
2525
const char *p = s;
2626

2727
/* Align pointer to word boundary (4 bytes) */
2828
while ((uint32_t) p & 3) {
2929
if (!*p) /* If null terminator is found byte-by-byte */
30-
return (int32_t) (p - s);
30+
return (size_t) (p - s);
3131
p++;
3232
}
3333

@@ -42,7 +42,7 @@ int32_t strlen(const char *s)
4242
p = (const char *) w;
4343
while (*p) /* Scan byte-by-byte until the null terminator. */
4444
p++;
45-
return (int32_t) (p - s); /* Return total length. */
45+
return (size_t) (p - s); /* Return total length. */
4646
}
4747

4848
void *memcpy(void *dst, const void *src, uint32_t len)

0 commit comments

Comments
 (0)