-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
There's an issue in disk.c line 280:
ret = GetVolumeInformation(
(LPCTSTR)drive_letter,
NULL,
_ARRAYSIZE(drive_letter),
...Using clang-cl, it warns:
psutil/arch/windows/disk.c(280,13): warning: 'sizeof (drive_letter)' will return the size of the pointer, not the array itself
[-Wsizeof-pointer-div]
280 | _ARRAYSIZE(drive_letter),
| ^~~~~~~~~~~~~~~~~~~~~~~~
And Co-Pilot concurs:
Highlighted Snippet
ret = GetVolumeInformation(
(LPCTSTR)drive_letter, [<- start of snippet]
NULL,
_ARRAYSIZE(drive_letter),
NULL,
&lpMaximumComponentLength,
&pflags,
(LPTSTR)fs_type,
_ARRAYSIZE(fs_type)
);
[<- end of snippet]1. Code Smells / Antipatterns
a. Potential Misuse of _ARRAYSIZE with Pointer
_ARRAYSIZE(drive_letter)is being used, butdrive_letteris a pointer, not an array. This macro works as intended only for actual arrays, not pointers, leading to incorrect buffer sizes.
...
A simple fix would be:
--- a/psutil/arch/windows/disk.c 2025-12-17 11:32:53
+++ psutil/arch/windows/disk.c 2025-12-17 12:39:37
@@ -277,7 +277,7 @@
ret = GetVolumeInformation(
(LPCTSTR)drive_letter,
NULL,
- _ARRAYSIZE(drive_letter),
+ _ARRAYSIZE(drive_strings),
NULL,
&lpMaximumComponentLength,
&pflags,