[core] fix listing of devices when all 26 drive letters are in use

* Issue reported by Alex
This commit is contained in:
Pete Batard 2014-09-08 18:23:50 +01:00
parent 533d49a950
commit 104ef277b7
2 changed files with 17 additions and 10 deletions

View File

@ -308,7 +308,7 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
HANDLE hDrive = INVALID_HANDLE_VALUE;
UINT _drive_type;
int i = 0, drive_number;
char *drive, drives[26*4]; /* "D:\", "E:\", etc. */
char *drive, drives[26*4 + 1]; /* "D:\", "E:\", etc., plus one NUL */
char logical_drive[] = "\\\\.\\#:";
if (drive_letters != NULL)
@ -317,13 +317,20 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
*drive_type = DRIVE_UNKNOWN;
CheckDriveIndex(DriveIndex);
// This call is weird... The buffer needs to have an extra NUL, but you're
// supposed to provide the size without the extra NUL. And the returned size
// does not include the NUL either *EXCEPT* if your buffer is too small...
// But then again, this doesn't hold true if you have a 105 byte buffer and
// pass a 4*26=104 size, as the the call will return 105 (i.e. *FAILURE*)
// instead of 104 as it should => screw Microsoft: We'll include the NUL
// always, as each drive string is at least 4 chars long anyway.
size = GetLogicalDriveStringsA(sizeof(drives), drives);
if (size == 0) {
uprintf("GetLogicalDriveStrings failed: %s\n", WindowsErrorString());
goto out;
}
if (size > sizeof(drives)) {
uprintf("GetLogicalDriveStrings: buffer too small (required %d vs %d)\n", size, sizeof(drives));
uprintf("GetLogicalDriveStrings: Buffer too small (required %d vs. %d)\n", size, sizeof(drives));
goto out;
}
@ -390,7 +397,7 @@ UINT GetDriveTypeFromIndex(DWORD DriveIndex)
char GetUnusedDriveLetter(void)
{
DWORD size;
char drive_letter = 'Z'+1, *drive, drives[26*4]; /* "D:\", "E:\", etc. */
char drive_letter = 'Z'+1, *drive, drives[26*4 + 1]; /* "D:\", "E:\", etc., plus one NUL */
size = GetLogicalDriveStringsA(sizeof(drives), drives);
if (size == 0) {
@ -398,7 +405,7 @@ char GetUnusedDriveLetter(void)
goto out;
}
if (size > sizeof(drives)) {
uprintf("GetLogicalDriveStrings: buffer too small (required %d vs %d)\n", size, sizeof(drives));
uprintf("GetLogicalDriveStrings: Buffer too small (required %d vs. %d)\n", size, sizeof(drives));
goto out;
}

View File

@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 1.4.10.514"
CAPTION "Rufus 1.4.10.515"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -165,7 +165,7 @@ END
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 1.4.10.514"
CAPTION "Rufus 1.4.10.515"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -428,8 +428,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,10,514
PRODUCTVERSION 1,4,10,514
FILEVERSION 1,4,10,515
PRODUCTVERSION 1,4,10,515
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -446,13 +446,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.4.10.514"
VALUE "FileVersion", "1.4.10.515"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.4.10.514"
VALUE "ProductVersion", "1.4.10.515"
END
END
BLOCK "VarFileInfo"