Skip to content

Commit 4971aad

Browse files
committed
Merge pull request #8691 from FirebirdSQL/work/gh-8690
Fix for bug #8690 : On Windows 7 isql exits silently right after the start.
1 parent ec2befe commit 4971aad

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- compatibility.manifest -->
2+
<!-- see https://learn.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1 -->
3+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
5+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
6+
<application>
7+
<!-- Windows 10 and Windows 11 -->
8+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
9+
<!-- Windows 8.1 -->
10+
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
11+
<!-- Windows 8 -->
12+
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
13+
<!-- Windows 7 -->
14+
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
15+
<!-- Windows Vista -->
16+
<!-- supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/ -->
17+
</application>
18+
</compatibility>
19+
</assembly>

builds/win32/msvc15/FirebirdCommon.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@
4444
<ResourceCompile>
4545
<PreprocessorDefinitions>RC_ARH_$(Platform);RC_TARGET_$(TargetName);RC_TARGET_NAME=$(TargetName);RC_TARGET_FILENAME=$(TargetFileName);%(PreprocessorDefinitions)</PreprocessorDefinitions>
4646
</ResourceCompile>
47+
<Manifest>
48+
<AdditionalManifestFiles>..\defs\compatibility.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
49+
</Manifest>
4750
</ItemDefinitionGroup>
4851
</Project>

src/isql/isql.epp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ enum literal_string_type
103103

104104
#if defined(WIN_NT)
105105
#include <windows.h>
106+
#include <VersionHelpers.h>
106107
#endif
107108
#include "ibase.h"
108109
#include "../isql/isql.h"
@@ -339,14 +340,21 @@ static int win32ReadConsole(FILE* file, CharBuffer& mbBuffer)
339340
SetConsoleMode(handle, oldMode);
340341
});
341342

342-
const size_t MAX_LINE_LENGTH = MAX_USHORT;
343-
WCHAR* wideBuf = wideBuffer->getBuffer(MAX_LINE_LENGTH, false);
343+
// Before Windows 10, ReadConsole() can't work with relatively large input
344+
// buffers and set ERROR_NOT_ENOUGH_MEMORY error. Thus, use initial buffer size
345+
// twice less than for Windows 10 and handle error by reducing the buffer size.
346+
347+
static size_t maxLineLength = IsWindows10OrGreater() ? MAX_USHORT : MAX_SSHORT;
348+
WCHAR* wideBuf = wideBuffer->getBuffer(maxLineLength, false);
344349

345350
DWORD charsRead;
346-
if (!ReadConsoleW(handle, wideBuf, MAX_LINE_LENGTH, &charsRead, NULL))
351+
while (!ReadConsoleW(handle, wideBuf, maxLineLength, &charsRead, NULL))
347352
{
348-
fb_assert(false);
349-
return -1;
353+
const DWORD error = GetLastError();
354+
if (error == ERROR_NOT_ENOUGH_MEMORY && maxLineLength > 256)
355+
maxLineLength -= 256;
356+
else
357+
Firebird::system_error::raise("ReadConsoleW", error);
350358
}
351359

352360
if (!charsRead)

0 commit comments

Comments
 (0)