From e4514c3fed8b9da77886737ec583e5c44c56e253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Sun, 26 Dec 2004 23:31:00 +0000 Subject: [PATCH] Dynamically resize buffer as needed svn path=/trunk/; revision=12350 --- reactos/apps/utils/pnpdump/pnpdump.c | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/reactos/apps/utils/pnpdump/pnpdump.c b/reactos/apps/utils/pnpdump/pnpdump.c index 5fb804ced7d..b02bc2bb1d6 100644 --- a/reactos/apps/utils/pnpdump/pnpdump.c +++ b/reactos/apps/utils/pnpdump/pnpdump.c @@ -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);