Skip to content

Correct return type of strlen function #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ static inline int byte_is_match(uint32_t w, uint32_t pat)
}

/* strlen that scans by words whenever possible for efficiency. */
int32_t strlen(const char *s)
size_t strlen(const char *s)
{
const char *p = s;

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

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

void *memcpy(void *dst, const void *src, uint32_t len)
Expand Down