Skip to content

Conversation

@alevy
Copy link

@alevy alevy commented Feb 21, 2025

mkfs uses the builtin strncpy, rather than kernel/strings.c, which, as of GCC-8, warns when n is the same size as the destination buffer, as it may not be able to add a NULL byte.

This is the desired behavior for xv6 directory entry names (which only require a NULL byte if they are shorter than DIRSIZ), but odd for normal uses of strncpy. So just ignore the warning to appease newer GCCs.

mkfs uses the builtin strncpy, rather than kernel/strings.c, which warns
when the `n` is the same size as the destination buffer, as it may not
be able to add a NULL byte. This is the desired behavior for directory
entry names (which only require a NULL byte if they are shorter than
DIRSIZ), so ignore the warning to appease newer GCCs.
@kaashoek
Copy link
Member

kaashoek commented Aug 5, 2025

The current version of gcc doesn't seem to generate this warning. But, I added the attribute((nonstring)) to the dirent struct to document that directory entries may not be null terminated.

@kaashoek kaashoek closed this Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants