@@ -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"
@@ -349,14 +350,21 @@ static int win32ReadConsole(FILE* file, CharBuffer& mbBuffer)
349
350
SetConsoleMode(handle, oldMode);
350
351
});
351
352
352
- const size_t MAX_LINE_LENGTH = MAX_USHORT;
353
- WCHAR* wideBuf = wideBuffer->getBuffer(MAX_LINE_LENGTH, false);
353
+ // Before Windows 10, ReadConsole() can't work with relatively large input
354
+ // buffers and set ERROR_NOT_ENOUGH_MEMORY error. Thus, use initial buffer size
355
+ // twice less than for Windows 10 and handle error by reducing the buffer size.
356
+
357
+ static size_t maxLineLength = IsWindows10OrGreater() ? MAX_USHORT : MAX_SSHORT;
358
+ WCHAR* wideBuf = wideBuffer->getBuffer(maxLineLength, false);
354
359
355
360
DWORD charsRead;
356
- if (!ReadConsoleW(handle, wideBuf, MAX_LINE_LENGTH , &charsRead, NULL))
361
+ while (!ReadConsoleW(handle, wideBuf, maxLineLength , &charsRead, NULL))
357
362
{
358
- fb_assert(false);
359
- return -1;
363
+ const DWORD error = GetLastError();
364
+ if (error == ERROR_NOT_ENOUGH_MEMORY && maxLineLength > 256)
365
+ maxLineLength -= 256;
366
+ else
367
+ Firebird::system_error::raise("ReadConsoleW", error);
360
368
}
361
369
362
370
if (!charsRead)
@@ -764,20 +772,17 @@ static void atexit_fb_shutdown()
764
772
765
773
int CLIB_ROUTINE main(int argc, char* argv[])
766
774
{
767
- /**************************************
768
- *
769
- * m a i n
770
- *
771
- **************************************
772
- *
773
- * Functional description
774
- * This calls ISQL_main, and exists to
775
- * isolate main which does not exist under
776
- * MS Windows.
777
- *
778
- **************************************/
779
-
780
- return ISQL_main(argc, argv);
775
+ try
776
+ {
777
+ return ISQL_main(argc, argv);
778
+ }
779
+ catch (const Firebird::Exception& ex)
780
+ {
781
+ Firebird::StaticStatusVector st;
782
+ ex.stuffException(st);
783
+ isc_print_status(st.begin());
784
+ }
785
+ return 1;
781
786
}
782
787
783
788
0 commit comments