diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt --- a/libc/src/stdio/CMakeLists.txt +++ b/libc/src/stdio/CMakeLists.txt @@ -258,8 +258,6 @@ HDRS fprintf.h DEPENDS - libc.include.stdio - libc.src.stdio.printf_core.printf_main - libc.src.stdio.printf_core.file_writer - libc.src.stdio.printf_core.writer + libc.src.__support.arg_list + libc.src.stdio.printf_core.vfprintf_internal ) diff --git a/libc/src/stdio/fprintf.cpp b/libc/src/stdio/fprintf.cpp --- a/libc/src/stdio/fprintf.cpp +++ b/libc/src/stdio/fprintf.cpp @@ -8,14 +8,11 @@ #include "src/stdio/fprintf.h" +#include "src/__support/File/file.h" #include "src/__support/arg_list.h" -#include "src/stdio/ferror.h" -#include "src/stdio/printf_core/file_writer.h" -#include "src/stdio/printf_core/printf_main.h" -#include "src/stdio/printf_core/writer.h" +#include "src/stdio/printf_core/vfprintf_internal.h" #include -#include namespace __llvm_libc { @@ -28,12 +25,7 @@ // and pointer semantics, as well as handling // destruction automatically. va_end(vlist); - printf_core::Writer writer(reinterpret_cast(stream), - printf_core::write_to_file); - - int ret_val = printf_core::printf_main(&writer, format, args); - if (__llvm_libc::ferror(stream)) - return -1; + int ret_val = printf_core::vfprintf_internal(stream, format, args); return ret_val; } diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt --- a/libc/src/stdio/printf_core/CMakeLists.txt +++ b/libc/src/stdio/printf_core/CMakeLists.txt @@ -79,3 +79,19 @@ .core_structs libc.src.__support.arg_list ) + +add_object_library( + vfprintf_internal + SRCS + vfprintf_internal.cpp + HDRS + vfprintf_internal.h + DEPENDS + libc.include.stdio + libc.src.__support.File.file + libc.src.__support.File.platform_file + libc.src.__support.arg_list + libc.src.stdio.printf_core.printf_main + libc.src.stdio.printf_core.file_writer + libc.src.stdio.printf_core.writer +) diff --git a/libc/src/stdio/printf_core/char_converter.h b/libc/src/stdio/printf_core/char_converter.h --- a/libc/src/stdio/printf_core/char_converter.h +++ b/libc/src/stdio/printf_core/char_converter.h @@ -15,21 +15,22 @@ namespace __llvm_libc { namespace printf_core { -void inline convert_char(Writer *writer, const FormatSection &to_conv) { +int inline convert_char(Writer *writer, const FormatSection &to_conv) { char c = to_conv.conv_val_raw; if (to_conv.min_width > 1) { if ((to_conv.flags & FormatFlags::LEFT_JUSTIFIED) == FormatFlags::LEFT_JUSTIFIED) { - writer->write(&c, 1); - writer->write_chars(' ', to_conv.min_width - 1); + RET_IF_RESULT_NEGATIVE(writer->write(&c, 1)); + RET_IF_RESULT_NEGATIVE(writer->write_chars(' ', to_conv.min_width - 1)); } else { - writer->write_chars(' ', to_conv.min_width - 1); - writer->write(&c, 1); + RET_IF_RESULT_NEGATIVE(writer->write_chars(' ', to_conv.min_width - 1)); + RET_IF_RESULT_NEGATIVE(writer->write(&c, 1)); } } else { - writer->write(&c, 1); + RET_IF_RESULT_NEGATIVE(writer->write(&c, 1)); } + return 0; } } // namespace printf_core diff --git a/libc/src/stdio/printf_core/converter.h b/libc/src/stdio/printf_core/converter.h --- a/libc/src/stdio/printf_core/converter.h +++ b/libc/src/stdio/printf_core/converter.h @@ -20,7 +20,7 @@ // convert will call a conversion function to convert the FormatSection into // its string representation, and then that will write the result to the // writer. -void convert(Writer *writer, const FormatSection &to_conv); +int convert(Writer *writer, const FormatSection &to_conv); } // namespace printf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/printf_core/converter.cpp b/libc/src/stdio/printf_core/converter.cpp --- a/libc/src/stdio/printf_core/converter.cpp +++ b/libc/src/stdio/printf_core/converter.cpp @@ -24,61 +24,48 @@ namespace __llvm_libc { namespace printf_core { -void convert(Writer *writer, const FormatSection &to_conv) { - if (!to_conv.has_conv) { - writer->write(to_conv.raw_string, to_conv.raw_len); - return; - } +int convert(Writer *writer, const FormatSection &to_conv) { + if (!to_conv.has_conv) + return writer->write(to_conv.raw_string, to_conv.raw_len); + switch (to_conv.conv_name) { case '%': - writer->write("%", 1); - return; + return writer->write("%", 1); case 'c': - convert_char(writer, to_conv); - return; + return convert_char(writer, to_conv); case 's': - convert_string(writer, to_conv); - return; + return convert_string(writer, to_conv); case 'd': case 'i': case 'u': - convert_int(writer, to_conv); - return; + return convert_int(writer, to_conv); case 'o': - // convert_oct(writer, to_conv); - return; + // return convert_oct(writer, to_conv); case 'x': case 'X': - // convert_hex(writer, to_conv); - return; + // return convert_hex(writer, to_conv); // TODO(michaelrj): add a flag to disable float point values here case 'f': case 'F': - // convert_float_decimal(writer, to_conv); - return; + // return convert_float_decimal(writer, to_conv); case 'e': case 'E': - // convert_float_dec_exp(writer, to_conv); - return; + // return convert_float_dec_exp(writer, to_conv); case 'a': case 'A': - // convert_float_hex_exp(writer, to_conv); - return; + // return convert_float_hex_exp(writer, to_conv); case 'g': case 'G': - // convert_float_mixed(writer, to_conv); - return; + // return convert_float_mixed(writer, to_conv); // TODO(michaelrj): add a flag to disable writing an int here case 'n': - // convert_write_int(writer, to_conv); - return; + // return convert_write_int(writer, to_conv); case 'p': - // convert_pointer(writer, to_conv); - return; + // return convert_pointer(writer, to_conv); default: - writer->write(to_conv.raw_string, to_conv.raw_len); - return; + return writer->write(to_conv.raw_string, to_conv.raw_len); } + return -1; } } // namespace printf_core diff --git a/libc/src/stdio/printf_core/core_structs.h b/libc/src/stdio/printf_core/core_structs.h --- a/libc/src/stdio/printf_core/core_structs.h +++ b/libc/src/stdio/printf_core/core_structs.h @@ -79,6 +79,13 @@ } }; +#define RET_IF_RESULT_NEGATIVE(func) \ + { \ + int result = (func); \ + if (result < 0) \ + return result; \ + } + } // namespace printf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/printf_core/file_writer.h b/libc/src/stdio/printf_core/file_writer.h --- a/libc/src/stdio/printf_core/file_writer.h +++ b/libc/src/stdio/printf_core/file_writer.h @@ -10,15 +10,31 @@ #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_FILE_WRITER_H #include "src/__support/File/file.h" + #include +#include namespace __llvm_libc { namespace printf_core { +class FileWriter { + __llvm_libc::File *file; + +public: + FileWriter(::FILE *init_file) { + file = reinterpret_cast<__llvm_libc::File *>(init_file); + file->lock(); + } + + ~FileWriter() { file->unlock(); } + + int write(const char *__restrict to_write, size_t len); +}; + // write_to_file treats raw_pointer as a File and calls its write // function. -void write_to_file(void *raw_pointer, const char *__restrict to_write, - size_t len); +int write_to_file(void *raw_pointer, const char *__restrict to_write, + size_t len); } // namespace printf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/printf_core/file_writer.cpp b/libc/src/stdio/printf_core/file_writer.cpp --- a/libc/src/stdio/printf_core/file_writer.cpp +++ b/libc/src/stdio/printf_core/file_writer.cpp @@ -13,10 +13,19 @@ namespace __llvm_libc { namespace printf_core { -void write_to_file(void *raw_pointer, const char *__restrict to_write, - size_t len) { - __llvm_libc::File *file = reinterpret_cast<__llvm_libc::File *>(raw_pointer); - file->write(to_write, len); +int FileWriter::write(const char *__restrict to_write, size_t len) { + int written = file->write_unlocked(to_write, len); + if (written != len) + written = -1; + if (file->error_unlocked()) + written = -2; + return written; +} + +int write_to_file(void *raw_pointer, const char *__restrict to_write, + size_t len) { + FileWriter *file_writer = reinterpret_cast(raw_pointer); + return file_writer->write(to_write, len); } } // namespace printf_core diff --git a/libc/src/stdio/printf_core/int_converter.h b/libc/src/stdio/printf_core/int_converter.h --- a/libc/src/stdio/printf_core/int_converter.h +++ b/libc/src/stdio/printf_core/int_converter.h @@ -19,7 +19,7 @@ namespace __llvm_libc { namespace printf_core { -void inline convert_int(Writer *writer, const FormatSection &to_conv) { +int inline convert_int(Writer *writer, const FormatSection &to_conv) { static constexpr size_t BITS_IN_BYTE = 8; static constexpr size_t BITS_IN_NUM = sizeof(uintmax_t) * BITS_IN_BYTE; @@ -148,24 +148,25 @@ if ((flags & FormatFlags::LEFT_JUSTIFIED) == FormatFlags::LEFT_JUSTIFIED) { // If left justified it goes sign zeroes digits spaces if (sign_char != 0) - writer->write(&sign_char, 1); + RET_IF_RESULT_NEGATIVE(writer->write(&sign_char, 1)); if (zeroes > 0) - writer->write_chars('0', zeroes); + RET_IF_RESULT_NEGATIVE(writer->write_chars('0', zeroes)); if (digits_written > 0) - writer->write(buffer + buff_cur, digits_written); + RET_IF_RESULT_NEGATIVE(writer->write(buffer + buff_cur, digits_written)); if (spaces > 0) - writer->write_chars(' ', spaces); + RET_IF_RESULT_NEGATIVE(writer->write_chars(' ', spaces)); } else { // Else it goes spaces sign zeroes digits if (spaces > 0) - writer->write_chars(' ', spaces); + RET_IF_RESULT_NEGATIVE(writer->write_chars(' ', spaces)); if (sign_char != 0) - writer->write(&sign_char, 1); + RET_IF_RESULT_NEGATIVE(writer->write(&sign_char, 1)); if (zeroes > 0) - writer->write_chars('0', zeroes); + RET_IF_RESULT_NEGATIVE(writer->write_chars('0', zeroes)); if (digits_written > 0) - writer->write(buffer + buff_cur, digits_written); + RET_IF_RESULT_NEGATIVE(writer->write(buffer + buff_cur, digits_written)); } + return 0; } } // namespace printf_core diff --git a/libc/src/stdio/printf_core/printf_main.cpp b/libc/src/stdio/printf_core/printf_main.cpp --- a/libc/src/stdio/printf_core/printf_main.cpp +++ b/libc/src/stdio/printf_core/printf_main.cpp @@ -22,13 +22,16 @@ int printf_main(Writer *writer, const char *__restrict str, internal::ArgList &args) { Parser parser(str, args); - + int result = 0; for (FormatSection cur_section = parser.get_next_section(); cur_section.raw_len > 0; cur_section = parser.get_next_section()) { if (cur_section.has_conv) - convert(writer, cur_section); + result = convert(writer, cur_section); else - writer->write(cur_section.raw_string, cur_section.raw_len); + result = writer->write(cur_section.raw_string, cur_section.raw_len); + + if (result < 0) + return result; } return writer->get_chars_written(); diff --git a/libc/src/stdio/printf_core/string_converter.h b/libc/src/stdio/printf_core/string_converter.h --- a/libc/src/stdio/printf_core/string_converter.h +++ b/libc/src/stdio/printf_core/string_converter.h @@ -17,7 +17,7 @@ namespace __llvm_libc { namespace printf_core { -void inline convert_string(Writer *writer, const FormatSection &to_conv) { +int inline convert_string(Writer *writer, const FormatSection &to_conv) { int string_len = 0; for (char *cur_str = reinterpret_cast(to_conv.conv_val_ptr); @@ -31,18 +31,22 @@ if (to_conv.min_width > string_len) { if ((to_conv.flags & FormatFlags::LEFT_JUSTIFIED) == FormatFlags::LEFT_JUSTIFIED) { - writer->write(reinterpret_cast(to_conv.conv_val_ptr), - string_len); - writer->write_chars(' ', to_conv.min_width - string_len); + RET_IF_RESULT_NEGATIVE(writer->write( + reinterpret_cast(to_conv.conv_val_ptr), string_len)); + RET_IF_RESULT_NEGATIVE( + writer->write_chars(' ', to_conv.min_width - string_len)); + } else { - writer->write_chars(' ', to_conv.min_width - string_len); - writer->write(reinterpret_cast(to_conv.conv_val_ptr), - string_len); + RET_IF_RESULT_NEGATIVE( + writer->write_chars(' ', to_conv.min_width - string_len)); + RET_IF_RESULT_NEGATIVE(writer->write( + reinterpret_cast(to_conv.conv_val_ptr), string_len)); } } else { - writer->write(reinterpret_cast(to_conv.conv_val_ptr), - string_len); + RET_IF_RESULT_NEGATIVE(writer->write( + reinterpret_cast(to_conv.conv_val_ptr), string_len)); } + return 0; } } // namespace printf_core diff --git a/libc/src/stdio/printf_core/string_writer.h b/libc/src/stdio/printf_core/string_writer.h --- a/libc/src/stdio/printf_core/string_writer.h +++ b/libc/src/stdio/printf_core/string_writer.h @@ -36,8 +36,8 @@ // write_to_string treats raw_pointer as a StringWriter and calls its write // function. -void write_to_string(void *raw_pointer, const char *__restrict to_write, - size_t len); +int write_to_string(void *raw_pointer, const char *__restrict to_write, + size_t len); } // namespace printf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/printf_core/string_writer.cpp b/libc/src/stdio/printf_core/string_writer.cpp --- a/libc/src/stdio/printf_core/string_writer.cpp +++ b/libc/src/stdio/printf_core/string_writer.cpp @@ -24,10 +24,11 @@ } } -void write_to_string(void *raw_pointer, const char *__restrict to_write, - size_t len) { +int write_to_string(void *raw_pointer, const char *__restrict to_write, + size_t len) { StringWriter *string_writer = reinterpret_cast(raw_pointer); string_writer->write(to_write, len); + return 0; } } // namespace printf_core diff --git a/libc/src/stdio/printf_core/vfprintf_internal.h b/libc/src/stdio/printf_core/vfprintf_internal.h new file mode 100644 --- /dev/null +++ b/libc/src/stdio/printf_core/vfprintf_internal.h @@ -0,0 +1,24 @@ +//===-- Internal implementation header of vfprintf --------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_VFPRINTF_INTERNAL_H +#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_VFPRINTF_INTERNAL_H + +#include "src/__support/arg_list.h" + +#include + +namespace __llvm_libc { +namespace printf_core { + +int vfprintf_internal(::FILE *__restrict stream, const char *__restrict format, + internal::ArgList &args); +} // namespace printf_core +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_VFPRINTF_INTERNAL_H diff --git a/libc/src/stdio/printf_core/vfprintf_internal.cpp b/libc/src/stdio/printf_core/vfprintf_internal.cpp new file mode 100644 --- /dev/null +++ b/libc/src/stdio/printf_core/vfprintf_internal.cpp @@ -0,0 +1,30 @@ +//===-- Internal implementation of vfprintf ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/stdio/printf_core/vfprintf_internal.h" + +#include "src/__support/arg_list.h" +#include "src/stdio/printf_core/file_writer.h" +#include "src/stdio/printf_core/printf_main.h" +#include "src/stdio/printf_core/writer.h" + +#include + +namespace __llvm_libc { +namespace printf_core { + +int vfprintf_internal(::FILE *__restrict stream, const char *__restrict format, + internal::ArgList &args) { + FileWriter file_writer(stream); + printf_core::Writer writer(reinterpret_cast(&file_writer), + printf_core::write_to_file); + return printf_core::printf_main(&writer, format, args); +} + +} // namespace printf_core +} // namespace __llvm_libc diff --git a/libc/src/stdio/printf_core/writer.h b/libc/src/stdio/printf_core/writer.h --- a/libc/src/stdio/printf_core/writer.h +++ b/libc/src/stdio/printf_core/writer.h @@ -14,7 +14,7 @@ namespace __llvm_libc { namespace printf_core { -using WriteFunc = void (*)(void *, const char *__restrict, size_t); +using WriteFunc = int (*)(void *, const char *__restrict, size_t); class Writer final { // output is a pointer to the string or file that the writer is meant to write @@ -23,26 +23,27 @@ // raw_write is a function that, when called on output with a char* and // length, will copy the number of bytes equal to the length from the char* - // onto the end of output. + // onto the end of output. It should return a positive number or zero on + // success, or a negative number on failure. WriteFunc raw_write; - unsigned long long chars_written = 0; + int chars_written = 0; public: Writer(void *init_output, WriteFunc init_raw_write) : output(init_output), raw_write(init_raw_write) {} // write will copy length bytes from new_string into output using - // raw_write, unless that would cause more bytes than max_length to be - // written. It always increments chars_written by length. - void write(const char *new_string, size_t length); + // raw_write. It increments chars_written by length always. It returns the + // result of raw_write. + int write(const char *new_string, size_t length); - // write_chars will copy length copies of new_char into output using raw_write - // unless that would cause more bytes than max_length to be written. It always - // increments chars_written by length. - void write_chars(char new_char, size_t length); + // write_chars will copy length copies of new_char into output using the write + // function and a statically sized buffer. This is primarily used for padding. + // If write returns a negative value, this will return early with that value. + int write_chars(char new_char, size_t length); - unsigned long long get_chars_written() { return chars_written; } + int get_chars_written() { return chars_written; } }; } // namespace printf_core diff --git a/libc/src/stdio/printf_core/writer.cpp b/libc/src/stdio/printf_core/writer.cpp --- a/libc/src/stdio/printf_core/writer.cpp +++ b/libc/src/stdio/printf_core/writer.cpp @@ -13,24 +13,23 @@ namespace __llvm_libc { namespace printf_core { -void Writer::write(const char *new_string, size_t length) { - - raw_write(output, new_string, length); - - // chars_written tracks the number of chars that would have been written - // regardless of what the raw_write call does. +int Writer::write(const char *new_string, size_t length) { chars_written += length; + return raw_write(output, new_string, length); } -void Writer::write_chars(char new_char, size_t length) { +int Writer::write_chars(char new_char, size_t length) { constexpr size_t BUFF_SIZE = 8; char buff[BUFF_SIZE]; + int result; inline_memset(buff, new_char, BUFF_SIZE); while (length > BUFF_SIZE) { - write(buff, BUFF_SIZE); + result = write(buff, BUFF_SIZE); + if (result < 0) + return result; length -= BUFF_SIZE; } - write(buff, length); + return write(buff, length); } } // namespace printf_core diff --git a/libc/test/src/stdio/fprintf_test.cpp b/libc/test/src/stdio/fprintf_test.cpp --- a/libc/test/src/stdio/fprintf_test.cpp +++ b/libc/test/src/stdio/fprintf_test.cpp @@ -62,7 +62,7 @@ written = __llvm_libc::fprintf(file, "Writing to a read only file should fail."); - EXPECT_EQ(written, -1); + EXPECT_LT(written, 0); ASSERT_EQ(__llvm_libc::fclose(file), 0); } diff --git a/libc/test/src/stdio/printf_core/converter_test.cpp b/libc/test/src/stdio/printf_core/converter_test.cpp --- a/libc/test/src/stdio/printf_core/converter_test.cpp +++ b/libc/test/src/stdio/printf_core/converter_test.cpp @@ -37,7 +37,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "abc"); - ASSERT_EQ(writer.get_chars_written(), 3ull); + ASSERT_EQ(writer.get_chars_written(), 3); } TEST_F(LlvmLibcPrintfConverterTest, PercentConversion) { @@ -51,7 +51,7 @@ str[1] = '\0'; ASSERT_STREQ(str, "%"); - ASSERT_EQ(writer.get_chars_written(), 1ull); + ASSERT_EQ(writer.get_chars_written(), 1); } TEST_F(LlvmLibcPrintfConverterTest, CharConversionSimple) { @@ -69,7 +69,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "D"); - ASSERT_EQ(writer.get_chars_written(), 1ull); + ASSERT_EQ(writer.get_chars_written(), 1); } TEST_F(LlvmLibcPrintfConverterTest, CharConversionRightJustified) { @@ -84,7 +84,7 @@ str_writer.terminate(); ASSERT_STREQ(str, " E"); - ASSERT_EQ(writer.get_chars_written(), 4ull); + ASSERT_EQ(writer.get_chars_written(), 4); } TEST_F(LlvmLibcPrintfConverterTest, CharConversionLeftJustified) { @@ -101,7 +101,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "F "); - ASSERT_EQ(writer.get_chars_written(), 4ull); + ASSERT_EQ(writer.get_chars_written(), 4); } TEST_F(LlvmLibcPrintfConverterTest, StringConversionSimple) { @@ -117,7 +117,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "DEF"); - ASSERT_EQ(writer.get_chars_written(), 3ull); + ASSERT_EQ(writer.get_chars_written(), 3); } TEST_F(LlvmLibcPrintfConverterTest, StringConversionPrecisionHigh) { @@ -132,7 +132,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "456"); - ASSERT_EQ(writer.get_chars_written(), 3ull); + ASSERT_EQ(writer.get_chars_written(), 3); } TEST_F(LlvmLibcPrintfConverterTest, StringConversionPrecisionLow) { @@ -147,7 +147,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "xy"); - ASSERT_EQ(writer.get_chars_written(), 2ull); + ASSERT_EQ(writer.get_chars_written(), 2); } TEST_F(LlvmLibcPrintfConverterTest, StringConversionRightJustified) { @@ -162,7 +162,7 @@ str_writer.terminate(); ASSERT_STREQ(str, " 789"); - ASSERT_EQ(writer.get_chars_written(), 4ull); + ASSERT_EQ(writer.get_chars_written(), 4); } TEST_F(LlvmLibcPrintfConverterTest, StringConversionLeftJustified) { @@ -179,7 +179,7 @@ str_writer.terminate(); ASSERT_STREQ(str, "ghi "); - ASSERT_EQ(writer.get_chars_written(), 4ull); + ASSERT_EQ(writer.get_chars_written(), 4); } TEST_F(LlvmLibcPrintfConverterTest, IntConversionSimple) { @@ -193,5 +193,5 @@ str_writer.terminate(); ASSERT_STREQ(str, "12345"); - ASSERT_EQ(writer.get_chars_written(), 5ull); + ASSERT_EQ(writer.get_chars_written(), 5); } diff --git a/libc/test/src/stdio/printf_core/string_writer_test.cpp b/libc/test/src/stdio/printf_core/string_writer_test.cpp --- a/libc/test/src/stdio/printf_core/string_writer_test.cpp +++ b/libc/test/src/stdio/printf_core/string_writer_test.cpp @@ -36,7 +36,7 @@ str_writer.terminate(); ASSERT_STREQ("abc", str); - ASSERT_EQ(writer.get_chars_written(), 3ull); + ASSERT_EQ(writer.get_chars_written(), 3); } TEST(LlvmLibcPrintfStringWriterTest, WriteMultipleTimes) { @@ -52,7 +52,7 @@ str_writer.terminate(); ASSERT_STREQ("abcDEF123", str); - ASSERT_EQ(writer.get_chars_written(), 9ull); + ASSERT_EQ(writer.get_chars_written(), 9); } TEST(LlvmLibcPrintfStringWriterTest, WriteChars) { @@ -67,7 +67,7 @@ str_writer.terminate(); ASSERT_STREQ("aaa", str); - ASSERT_EQ(writer.get_chars_written(), 3ull); + ASSERT_EQ(writer.get_chars_written(), 3); } TEST(LlvmLibcPrintfStringWriterTest, WriteCharsMultipleTimes) { @@ -83,7 +83,7 @@ str_writer.terminate(); ASSERT_STREQ("aaaDDD111", str); - ASSERT_EQ(writer.get_chars_written(), 9ull); + ASSERT_EQ(writer.get_chars_written(), 9); } TEST(LlvmLibcPrintfStringWriterTest, WriteManyChars) { @@ -107,7 +107,7 @@ "ZZZZZZZZZZ" "ZZZZZZZZZ", str); - ASSERT_EQ(writer.get_chars_written(), 99ull); + ASSERT_EQ(writer.get_chars_written(), 99); } TEST(LlvmLibcPrintfStringWriterTest, MixedWrites) { @@ -124,7 +124,7 @@ str_writer.terminate(); ASSERT_STREQ("aaaDEF111456", str); - ASSERT_EQ(writer.get_chars_written(), 12ull); + ASSERT_EQ(writer.get_chars_written(), 12); } TEST(LlvmLibcPrintfStringWriterTest, WriteWithMaxLength) { @@ -138,7 +138,7 @@ str_writer.terminate(); ASSERT_STREQ("abcDEF1234", str); - ASSERT_EQ(writer.get_chars_written(), 12ull); + ASSERT_EQ(writer.get_chars_written(), 12); } TEST(LlvmLibcPrintfStringWriterTest, WriteCharsWithMaxLength) { @@ -153,7 +153,7 @@ str_writer.terminate(); ASSERT_STREQ("1111111111", str); - ASSERT_EQ(writer.get_chars_written(), 15ull); + ASSERT_EQ(writer.get_chars_written(), 15); } TEST(LlvmLibcPrintfStringWriterTest, MixedWriteWithMaxLength) { @@ -170,7 +170,7 @@ str_writer.terminate(); ASSERT_STREQ("aaaDEF1114", str); - ASSERT_EQ(writer.get_chars_written(), 12ull); + ASSERT_EQ(writer.get_chars_written(), 12); } TEST(LlvmLibcPrintfStringWriterTest, StringWithMaxLengthOne) { @@ -189,7 +189,7 @@ str_writer.terminate(); ASSERT_STREQ("", str); - ASSERT_EQ(writer.get_chars_written(), 12ull); + ASSERT_EQ(writer.get_chars_written(), 12); } TEST(LlvmLibcPrintfStringWriterTest, NullStringWithZeroMaxLength) { @@ -202,5 +202,5 @@ writer.write_chars('1', 3); writer.write("456", 3); - ASSERT_EQ(writer.get_chars_written(), 12ull); + ASSERT_EQ(writer.get_chars_written(), 12); }