[Libreoffice-commits] .: Branch 'libreoffice-3-5' - shell/source
Michael Meeks
michael at kemper.freedesktop.org
Tue Jun 12 02:16:01 PDT 2012
shell/source/backends/wininetbe/wininetbackend.cxx | 66 ++++++++++++++-------
1 file changed, 44 insertions(+), 22 deletions(-)
New commits:
commit a1555ee046fcf1fe9e49e8b6820316a66046698a
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Jun 8 16:54:18 2012 +0200
fdo#47044: Adapt to different Windows versions' InternetQueryOption behavior
Change-Id: Ia4d1d8f903872e5eefae2d9687866243b9055a13
(cherry picked from commit 0dded0d18a5945ed5a38623068ba7aa93da39df0)
Conflicts:
shell/source/backends/wininetbe/wininetbackend.cxx
Signed-off-by: Michael Meeks <michael.meeks at suse.com>
diff --git a/shell/source/backends/wininetbe/wininetbackend.cxx b/shell/source/backends/wininetbe/wininetbackend.cxx
old mode 100644
new mode 100755
index 20d35c7..5686689
--- a/shell/source/backends/wininetbe/wininetbackend.cxx
+++ b/shell/source/backends/wininetbe/wininetbackend.cxx
@@ -123,32 +123,54 @@ WinInetBackend::WinInetBackend()
GetProcAddress( hWinInetDll.module, "InternetQueryOptionA" ) );
if (lpfnInternetQueryOption)
{
- LPINTERNET_PROXY_INFO lpi = NULL;
-
- // query for the neccessary space
- DWORD dwLength = 0;
- BOOL bRet = lpfnInternetQueryOption(
- NULL,
- INTERNET_OPTION_PROXY,
- (LPVOID)lpi,
- &dwLength );
-
- // allocate sufficient space on the heap
- // insufficient space on the heap results
- // in a stack overflow exception, we assume
- // this never happens, because of the relatively
- // small amount of memory we need
- // alloca is nice because it is fast and we don't
- // have to free the allocated memory, it will be
- // automatically done
- lpi = reinterpret_cast< LPINTERNET_PROXY_INFO >(
- alloca( dwLength ) );
-
- bRet = lpfnInternetQueryOption(
+ // Some Windows versions would fail the InternetQueryOption call
+ // with ERROR_OUTOFMEMORY when the initial dwLength were zero (and
+ // are apparently fine with the initial sizeof (INTERNET_PROXY_INFO)
+ // and need no reallocation), while other versions fail with
+ // ERROR_INSUFFICIENT_BUFFER upon that initial dwLength and need a
+ // reallocation:
+ INTERNET_PROXY_INFO pi;
+ LPINTERNET_PROXY_INFO lpi = π
+ DWORD dwLength = sizeof (INTERNET_PROXY_INFO);
+ BOOL ok = lpfnInternetQueryOption(
NULL,
INTERNET_OPTION_PROXY,
(LPVOID)lpi,
&dwLength );
+ if (!ok)
+ {
+ DWORD err = GetLastError();
+ if (err = ERROR_INSUFFICIENT_BUFFER)
+ {
+ // allocate sufficient space on the heap
+ // insufficient space on the heap results
+ // in a stack overflow exception, we assume
+ // this never happens, because of the relatively
+ // small amount of memory we need
+ // alloca is nice because it is fast and we don't
+ // have to free the allocated memory, it will be
+ // automatically done
+ lpi = reinterpret_cast< LPINTERNET_PROXY_INFO >(
+ alloca( dwLength ) );
+ ok = lpfnInternetQueryOption(
+ NULL,
+ INTERNET_OPTION_PROXY,
+ (LPVOID)lpi,
+ &dwLength );
+ if (!ok)
+ {
+ err = GetLastError();
+ }
+ }
+ if (!ok)
+ {
+ SAL_WARN(
+ "shell",
+ "InternetQueryOption INTERNET_OPTION_PROXY"
+ " GetLastError=" << err);
+ return;
+ }
+ }
// if a proxy is disabled, InternetQueryOption returns
// an empty proxy list, so we don't have to check if
More information about the Libreoffice-commits
mailing list