Skip to content

Commit 13cfaa2

Browse files
authored
Guard against usage of _isatty when header was not included (#3880)
* Guard against usage of _isatty when header was not included * Rename FMT_WINDOWS_NO_WCHAR macro to FMT_USE_WRITE_CONSOLE
1 parent 0861db5 commit 13cfaa2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

include/fmt/format-inl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# include <locale>
1919
#endif
2020

21-
#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR)
21+
#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
2222
# include <io.h> // _isatty
2323
#endif
2424

@@ -1639,7 +1639,7 @@ class file_print_buffer : public buffer<char> {
16391639
}
16401640
};
16411641

1642-
#if !defined(_WIN32) || defined(FMT_WINDOWS_NO_WCHAR)
1642+
#if !defined(_WIN32) || defined(FMT_USE_WRITE_CONSOLE)
16431643
FMT_FUNC auto write_console(int, string_view) -> bool { return false; }
16441644
#else
16451645
using dword = conditional_t<sizeof(long) == 4, unsigned long, unsigned>;
@@ -1665,7 +1665,7 @@ FMT_FUNC void vprint_mojibake(std::FILE* f, string_view fmt, format_args args,
16651665
#endif
16661666

16671667
FMT_FUNC void print(std::FILE* f, string_view text) {
1668-
#ifdef _WIN32
1668+
#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
16691669
int fd = _fileno(f);
16701670
if (_isatty(fd)) {
16711671
std::fflush(f);

test/format-impl-test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ TEST(format_impl_test, write_dragon_even) {
344344
if (!FMT_MSC_VERSION) EXPECT_EQ(s, "33554450");
345345
}
346346

347-
#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR)
347+
#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
348348
# include <windows.h>
349349

350350
TEST(format_impl_test, write_console_signature) {

0 commit comments

Comments
 (0)