From: Hervé Poussineau Date: Tue, 23 Aug 2005 17:38:14 +0000 (+0000) Subject: Fix special case in SetupGetLineTextA/W and SetupGetStringFieldA/W when Buffer is... X-Git-Tag: ReactOS-0.2.8~922 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=d373f6bfb03fc11c453ed37767a89bdfc58771a8 Fix special case in SetupGetLineTextA/W and SetupGetStringFieldA/W when Buffer is NULL and BufferSize is 0, by reverting part of r17162 Fixes bug #724, spotted by GvG Do according changes in SetupDiBuildDriverInfoList svn path=/trunk/; revision=17483 --- diff --git a/reactos/lib/setupapi/devinst.c b/reactos/lib/setupapi/devinst.c index 6c3b443420d..2c87904d055 100644 --- a/reactos/lib/setupapi/devinst.c +++ b/reactos/lib/setupapi/devinst.c @@ -3564,8 +3564,9 @@ SetupDiBuildDriverInfoList( 0, /* Field index */ NULL, 0, &RequiredSize); - if (!Result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) + if (Result) { + /* We got the needed size for the buffer */ ManufacturerName = HeapAlloc(GetProcessHeap(), 0, RequiredSize * sizeof(WCHAR)); if (!ManufacturerName) { @@ -3583,8 +3584,9 @@ SetupDiBuildDriverInfoList( 1, /* Field index */ NULL, 0, &RequiredSize); - if (!Result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) + if (Result) { + /* We got the needed size for the buffer */ ManufacturerSection = HeapAlloc(GetProcessHeap(), 0, RequiredSize * sizeof(WCHAR)); if (!ManufacturerSection) { diff --git a/reactos/lib/setupapi/parser.c b/reactos/lib/setupapi/parser.c index e14e7fb479d..387606a907f 100644 --- a/reactos/lib/setupapi/parser.c +++ b/reactos/lib/setupapi/parser.c @@ -1523,13 +1523,13 @@ BOOL WINAPI SetupGetLineTextW( PINFCONTEXT context, HINF hinf, PCWSTR section_na total += PARSER_string_substW( file, field->text, NULL, 0 ) + 1; if (required) *required = total; - if (total > size) - { - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - return FALSE; - } if (buffer) { + if (total > size) + { + SetLastError( ERROR_INSUFFICIENT_BUFFER ); + return FALSE; + } for (i = 0, field = &file->fields[line->first_field]; i < line->nb_fields; i++, field++) { unsigned int len = PARSER_string_substW( file, field->text, buffer, size ); @@ -1574,13 +1574,13 @@ BOOL WINAPI SetupGetLineTextA( PINFCONTEXT context, HINF hinf, PCSTR section_nam total += PARSER_string_substA( file, field->text, NULL, 0 ) + 1; if (required) *required = total; - if (total > size) - { - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - return FALSE; - } if (buffer) { + if (total > size) + { + SetLastError( ERROR_INSUFFICIENT_BUFFER ); + return FALSE; + } for (i = 0, field = &file->fields[line->first_field]; i < line->nb_fields; i++, field++) { unsigned int len = PARSER_string_substA( file, field->text, buffer, size ); @@ -1619,13 +1619,13 @@ BOOL WINAPI SetupGetStringFieldA( PINFCONTEXT context, DWORD index, PSTR buffer, if (!field) return FALSE; len = PARSER_string_substA( file, field->text, NULL, 0 ); if (required) *required = len + 1; - if (size <= len) - { - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - return FALSE; - } if (buffer) { + if (size <= len) + { + SetLastError( ERROR_INSUFFICIENT_BUFFER ); + return FALSE; + } PARSER_string_substA( file, field->text, buffer, size ); TRACE( "context %p/%p/%d/%d index %ld returning %s\n", @@ -1650,13 +1650,13 @@ BOOL WINAPI SetupGetStringFieldW( PINFCONTEXT context, DWORD index, PWSTR buffer if (!field) return FALSE; len = PARSER_string_substW( file, field->text, NULL, 0 ); if (required) *required = len + 1; - if (size <= len) - { - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - return FALSE; - } if (buffer) { + if (size <= len) + { + SetLastError( ERROR_INSUFFICIENT_BUFFER ); + return FALSE; + } PARSER_string_substW( file, field->text, buffer, size ); TRACE( "context %p/%p/%d/%d index %ld returning %s\n",