mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 17:52:56 +00:00
Dynamically resize buffer as needed
svn path=/trunk/; revision=12350
This commit is contained in:
parent
8bbd20efdc
commit
e4514c3fed
1 changed files with 21 additions and 12 deletions
|
@ -706,7 +706,7 @@ int main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Allocate buffer */
|
||||
dwSize = 1024;
|
||||
dwSize = 2048;
|
||||
lpBuffer = malloc(dwSize);
|
||||
if (lpBuffer == NULL)
|
||||
{
|
||||
|
@ -715,19 +715,28 @@ int main (int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
lError = RegQueryValueEx(hPnpKey,
|
||||
"Configuration Data",
|
||||
NULL,
|
||||
&dwType,
|
||||
(LPBYTE)lpBuffer,
|
||||
&dwSize);
|
||||
do
|
||||
{
|
||||
lError = RegQueryValueEx(hPnpKey,
|
||||
"Configuration Data",
|
||||
NULL,
|
||||
&dwType,
|
||||
(LPBYTE)lpBuffer,
|
||||
&dwSize);
|
||||
if (lError == ERROR_MORE_DATA)
|
||||
{
|
||||
lpBuffer = realloc(lpBuffer, dwSize);
|
||||
if (lpBuffer == NULL)
|
||||
{
|
||||
printf("Error: realloc() of %u bytes failed\n", (unsigned) dwSize);
|
||||
RegCloseKey(hPnpKey);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (lError == ERROR_MORE_DATA);
|
||||
if (lError != ERROR_SUCCESS)
|
||||
{
|
||||
if (lError == ERROR_MORE_DATA)
|
||||
{
|
||||
printf("Need to resize buffer to %lu\n", dwSize);
|
||||
}
|
||||
|
||||
printf("Failed to read 'Configuration Data' value\n");
|
||||
free(lpBuffer);
|
||||
RegCloseKey(hPnpKey);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue