KPath: Use a default buffer size of B_PATH_NAME_LENGTH without + 1.

B_PATH_NAME_LENGTH == PATH_MAX, and PATH_MAX is inclusive of the final
NULL terminator, so we don't need a + 1 here.

The original KPath default was to not use + 1, but that was changed in
42e3c6f978 due to all the consumers that did.

But all those consumers are wrong, it appears; they should just be
using the default length instead. So now we do that.
This commit is contained in:
Augustin Cavalier 2024-11-22 16:56:15 -05:00
parent cc9ea55c59
commit 9708b08060
3 changed files with 11 additions and 8 deletions

View File

@ -22,15 +22,16 @@ public:
TRAVERSE_LEAF_LINK = 0x02,
LAZY_ALLOC = 0x04
};
public:
KPath(size_t bufferSize = B_PATH_NAME_LENGTH + 1);
KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
KPath(const char* path, int32 flags = DEFAULT,
size_t bufferSize = B_PATH_NAME_LENGTH + 1);
size_t bufferSize = B_PATH_NAME_LENGTH);
KPath(const KPath& other);
~KPath();
status_t SetTo(const char* path, int32 flags = DEFAULT,
size_t bufferSize = B_PATH_NAME_LENGTH + 1);
size_t bufferSize = B_PATH_NAME_LENGTH);
void Adopt(KPath& other);
status_t InitCheck() const;

View File

@ -80,7 +80,7 @@ status_t
KPath::SetTo(const char* path, int32 flags, size_t bufferSize)
{
if (bufferSize == 0)
bufferSize = B_PATH_NAME_LENGTH + 1;
bufferSize = B_PATH_NAME_LENGTH;
// free the previous buffer, if the buffer size differs
if (fBuffer != NULL && fBufferSize != bufferSize) {
@ -249,11 +249,13 @@ KPath::DetachBuffer()
{
char* buffer = fBuffer;
if (fBufferSize == (B_PATH_NAME_LENGTH + 1)) {
#ifdef _KERNEL_MODE
if (fBufferSize == B_PATH_NAME_LENGTH) {
buffer = (char*)malloc(fBufferSize);
memcpy(buffer, fBuffer, fBufferSize);
_FreeBuffer();
}
#endif
if (fBuffer != NULL) {
fBuffer = NULL;
@ -427,7 +429,7 @@ KPath::_AllocateBuffer()
{
if (fBuffer == NULL && fBufferSize != 0) {
#ifdef _KERNEL_MODE
if (fBufferSize == (B_PATH_NAME_LENGTH + 1))
if (fBufferSize == B_PATH_NAME_LENGTH)
fBuffer = (char*)object_cache_alloc(sPathNameCache, 0);
else
#endif
@ -448,7 +450,7 @@ void
KPath::_FreeBuffer()
{
#ifdef _KERNEL_MODE
if (fBufferSize == (B_PATH_NAME_LENGTH + 1))
if (fBufferSize == B_PATH_NAME_LENGTH)
object_cache_free(sPathNameCache, fBuffer, 0);
else
#endif

View File

@ -5284,7 +5284,7 @@ vfs_init(kernel_args* args)
panic("vfs_init: error creating mounts hash table\n");
sPathNameCache = create_object_cache("vfs path names",
B_PATH_NAME_LENGTH + 1, 8, NULL, NULL, NULL);
B_PATH_NAME_LENGTH, 8, NULL, NULL, NULL);
if (sPathNameCache == NULL)
panic("vfs_init: error creating path name object_cache\n");