@@ -99,6 +99,7 @@ enum literal_string_type
99
99
100
100
#if defined(WIN_NT)
101
101
#include <windows.h>
102
+ #include <VersionHelpers.h>
102
103
#endif
103
104
#include "ibase.h"
104
105
#include "../isql/isql.h"
@@ -347,14 +348,21 @@ static int win32ReadConsole(FILE* file, CharBuffer& mbBuffer)
347
348
SetConsoleMode(handle, oldMode);
348
349
});
349
350
350
- const size_t MAX_LINE_LENGTH = MAX_USHORT;
351
- WCHAR* wideBuf = wideBuffer->getBuffer(MAX_LINE_LENGTH, false);
351
+ // Before Windows 10, ReadConsole() can't work with relatively large input
352
+ // buffers and set ERROR_NOT_ENOUGH_MEMORY error. Thus, use initial buffer size
353
+ // twice less than for Windows 10 and handle error by reducing the buffer size.
354
+
355
+ static size_t maxLineLength = IsWindows10OrGreater() ? MAX_USHORT : MAX_SSHORT;
356
+ WCHAR* wideBuf = wideBuffer->getBuffer(maxLineLength, false);
352
357
353
358
DWORD charsRead;
354
- if (!ReadConsoleW(handle, wideBuf, MAX_LINE_LENGTH , &charsRead, NULL))
359
+ while (!ReadConsoleW(handle, wideBuf, maxLineLength , &charsRead, NULL))
355
360
{
356
- fb_assert(false);
357
- return -1;
361
+ const DWORD error = GetLastError();
362
+ if (error == ERROR_NOT_ENOUGH_MEMORY && maxLineLength > 256)
363
+ maxLineLength -= 256;
364
+ else
365
+ Firebird::system_error::raise("ReadConsoleW", error);
358
366
}
359
367
360
368
if (!charsRead)
@@ -690,20 +698,17 @@ static void atexit_fb_shutdown()
690
698
691
699
int CLIB_ROUTINE main(int argc, char* argv[])
692
700
{
693
- /**************************************
694
- *
695
- * m a i n
696
- *
697
- **************************************
698
- *
699
- * Functional description
700
- * This calls ISQL_main, and exists to
701
- * isolate main which does not exist under
702
- * MS Windows.
703
- *
704
- **************************************/
705
-
706
- return ISQL_main(argc, argv);
701
+ try
702
+ {
703
+ return ISQL_main(argc, argv);
704
+ }
705
+ catch (const Firebird::Exception& ex)
706
+ {
707
+ Firebird::StaticStatusVector st;
708
+ ex.stuffException(st);
709
+ isc_print_status(st.begin());
710
+ }
711
+ return 1;
707
712
}
708
713
709
714
0 commit comments