Adjust all struct dirent creations (again), this time to use offsetof().
The dirent struct is not packed, so offsetof(dirent, d_name) != sizeof(dirent). Thus in order not to waste the alignment bytes (which are significant, on x86_64 at least, sizeof(dirent)==32, but offsetof(...)=26.) This is also the most portable way to handle things, and should work just fine in cross-platform code that has a non-zero-sized d_name.
This commit is contained in:
@@ -1737,7 +1737,7 @@ bfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
|
||||
while (count < maxCount && bufferSize > sizeof(struct dirent)) {
|
||||
ino_t id;
|
||||
uint16 length;
|
||||
size_t nameBufferSize = bufferSize - sizeof(struct dirent);
|
||||
size_t nameBufferSize = bufferSize - offsetof(struct dirent, d_name);
|
||||
|
||||
status_t status = iterator->GetNextEntry(dirent->d_name, &length,
|
||||
nameBufferSize, &id);
|
||||
@@ -1759,7 +1759,7 @@ bfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
|
||||
|
||||
dirent->d_dev = volume->ID();
|
||||
dirent->d_ino = id;
|
||||
dirent->d_reclen = sizeof(struct dirent) + length + 1;
|
||||
dirent->d_reclen = offsetof(struct dirent, d_name) + length + 1;
|
||||
|
||||
bufferSize -= dirent->d_reclen;
|
||||
dirent = (struct dirent*)((uint8*)dirent + dirent->d_reclen);
|
||||
@@ -1867,7 +1867,7 @@ bfs_read_attr_dir(fs_volume* _volume, fs_vnode* node, void* _cookie,
|
||||
Volume* volume = (Volume*)_volume->private_volume;
|
||||
|
||||
dirent->d_dev = volume->ID();
|
||||
dirent->d_reclen = sizeof(struct dirent) + length + 1;
|
||||
dirent->d_reclen = offsetof(struct dirent, d_name) + length + 1;
|
||||
|
||||
*_num = 1;
|
||||
return B_OK;
|
||||
|
||||
Reference in New Issue
Block a user