Skip to content

Commit

Permalink
fix: %zu vs %llu and str() vs str().c_str()
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Apr 10, 2024
1 parent 6e6644a commit a04d66f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions singleheader/amalgamation_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int main(int , char *[]) {
// convert to UTF-16LE
size_t utf16words =
simdutf::convert_utf8_to_utf16le(source, 4, utf16_output.get());
printf("wrote %llu UTF-16LE words.", utf16words);
printf("wrote %zu UTF-16LE words.", utf16words);
// It wrote utf16words * sizeof(char16_t) bytes.
bool validutf16 = simdutf::validate_utf16le(utf16_output.get(), utf16words);
if (validutf16) {
Expand All @@ -36,7 +36,7 @@ int main(int , char *[]) {
// convert to UTF-8
size_t utf8words = simdutf::convert_utf16le_to_utf8(
utf16_output.get(), utf16words, utf8_output.get());
printf("wrote %llu UTF-8 words.", utf8words);
printf("wrote %zu UTF-8 words.", utf8words);
std::string final_string(utf8_output.get(), utf8words);
puts(final_string.c_str());
if (final_string != source) {
Expand Down
12 changes: 6 additions & 6 deletions tests/base64_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ TEST(roundtrip_base64) {
printf("=====input size %zu\n", len);
for (size_t i = 0; i < len; i++) {
if (back[i] != source[i]) {
printf("Mismatch at position %llu trial %llu\n", i, trial);
printf("Mismatch at position %zu trial %zu\n", i, trial);
}
printf("%zu: %02x %02x\n", i, uint8_t(back[i]), uint8_t(source[i]));
}
Expand Down Expand Up @@ -417,7 +417,7 @@ TEST(roundtrip_base64_16) {
printf("=====input size %zu\n", len);
for (size_t i = 0; i < len; i++) {
if (back[i] != source[i]) {
printf("Mismatch at position %llu trial %llu\n", i, trial);
printf("Mismatch at position %zu trial %zu\n", i, trial);
}
printf("%zu: %02x %02x\n", i, uint8_t(back[i]), uint8_t(source[i]));
}
Expand Down Expand Up @@ -457,7 +457,7 @@ TEST(roundtrip_base64url) {
printf("=====input size %zu\n", len);
for (size_t i = 0; i < len; i++) {
if (back[i] != source[i]) {
printf("Mismatch at position %llu trial %llu\n", i, trial);
printf("Mismatch at position %zu trial %zu\n", i, trial);
}
printf("%zu: %02x %02x\n", i, uint8_t(back[i]), uint8_t(source[i]));
}
Expand Down Expand Up @@ -501,7 +501,7 @@ TEST(roundtrip_base64url_16) {
printf("=====input size %zu\n", len);
for (size_t i = 0; i < len; i++) {
if (back[i] != source[i]) {
printf("Mismatch at position %llu trial %llu\n", i, trial);
printf("Mismatch at position %zu trial %zu\n", i, trial);
}
printf("%zu: %02x %02x\n", i, uint8_t(back[i]), uint8_t(source[i]));
}
Expand Down Expand Up @@ -755,7 +755,7 @@ TEST(roundtrip_base64_16_with_spaces) {
printf("=====input size %zu\n", len);
for (size_t i = 0; i < len; i++) {
if (back[i] != source[i]) {
printf("Mismatch at position %llu trial %llu\n", i, trial);
printf("Mismatch at position %zu trial %zu\n", i, trial);
}
printf("%zu: %02x %02x\n", i, uint8_t(back[i]), uint8_t(source[i]));
}
Expand Down Expand Up @@ -1023,7 +1023,7 @@ TEST(readme_test) {
simdutf::result r = simdutf::base64_to_binary(base64.data() + pos, count,
back.data() + outpos);
if (r.error == simdutf::error_code::INVALID_BASE64_CHARACTER) {
printf("Invalid base64 character at position %llu\n", pos + r.count);
printf("Invalid base64 character at position %zu\n", pos + r.count);
return;
}
// If we arrived at the end of the base64 input, we must check that the
Expand Down
18 changes: 9 additions & 9 deletions tests/basic_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,23 +633,23 @@ TEST(basic_fuzz) {
input.size() / sizeof(char32_t), reinterpret_cast<char16_t *>(output.data()));
if(is_ok_utf8.second ? (utf8_to_utf16.second == 0 || utf8_to_utf32.second == 0) : (utf8_to_utf16.second > 0 || utf8_to_utf32.second > 0)) {
printf("%s\n", (is_ok_utf8.second ? "UTF-8 is ok" : "UTF-8 is not ok"));
printf(" size = %llu\n", input.size());
printf(" implementation.convert_utf8_to_utf16.second return %llu\n", utf8_to_utf16.second);
printf(" implementation.convert_utf8_to_utf32.second return %lli\n", utf8_to_utf32.second);
printf(" size = %zu\n", input.size());
printf(" implementation.convert_utf8_to_utf16.second return %zu\n", utf8_to_utf16.second);
printf(" implementation.convert_utf8_to_utf32.second return %zu\n", utf8_to_utf32.second);
}
ASSERT_TRUE(is_ok_utf8.second ? (utf8_to_utf16.second > 0 && utf8_to_utf32.second > 0) : (utf8_to_utf16.second == 0 && utf8_to_utf32.second == 0));
if(is_ok_utf16.second ? (utf16_to_utf8.second == 0 || utf16_to_utf32.second == 0) : (utf16_to_utf8.second > 0 || utf16_to_utf32.second > 0)) {
printf("%s\n", (is_ok_utf16.second ? "UTF-16 is ok" : "UTF-16 is not ok"));
printf(" size = %llu\n", input.size() / sizeof(char16_t));
printf(" implementation.convert_utf16_to_utf8.second return %llu\n", utf16_to_utf8.second);
printf(" implementation.convert_utf16_to_utf32.second return %llu\n",utf16_to_utf32.second);
printf(" size = %zu\n", input.size() / sizeof(char16_t));
printf(" implementation.convert_utf16_to_utf8.second return %zu\n", utf16_to_utf8.second);
printf(" implementation.convert_utf16_to_utf32.second return %zu\n",utf16_to_utf32.second);
}
ASSERT_TRUE(is_ok_utf16.second ? (utf16_to_utf8.second > 0 && utf16_to_utf32.second > 0) : (utf16_to_utf8.second == 0 && utf16_to_utf32.second == 0));
if(is_ok_utf32.second ? (utf32_to_utf8.second == 0 || utf32_to_utf16.second == 0) : (utf32_to_utf8.second > 0 || utf32_to_utf16.second > 0)) {
printf("%s\n", (is_ok_utf32.second ? "UTF-32 is ok" : "UTF-32 is not ok"));
printf(" size = %llu\n", input.size() / sizeof(char32_t));
printf(" implementation.convert_utf32_to_utf8.second return %llu\n", utf32_to_utf8.second);
printf(" implementation.convert_utf32_to_utf16.second return %llu\n", utf32_to_utf16.second);
printf(" size = %zu\n", input.size() / sizeof(char32_t));
printf(" implementation.convert_utf32_to_utf8.second return %zu\n", utf32_to_utf8.second);
printf(" implementation.convert_utf32_to_utf16.second return %zu\n", utf32_to_utf16.second);
}
ASSERT_TRUE(is_ok_utf32.second ? (utf32_to_utf8.second > 0 && utf32_to_utf16.second > 0) : (utf32_to_utf8.second == 0 && utf32_to_utf16.second == 0));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void test_impl_##name(const simdutf::implementation& implementation, uint32_t se
lhs_str << lhs; \
std::stringstream rhs_str; \
rhs_str << rhs; \
printf("lhs: %s = %s\n", #a, lhs_str.str()); \
printf("rhs: %s = %s\n", #b, rhs_str.str()); \
printf("lhs: %s = %s\n", #a, lhs_str.str().c_str()); \
printf("rhs: %s = %s\n", #b, rhs_str.str().c_str()); \
printf("%s \n",#a); \
printf("file %s:%d, function %s \n", __FILE__, __LINE__, __func__); \
exit(1); \
Expand Down
10 changes: 5 additions & 5 deletions tests/random_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void print_input(const std::string& s, const simdutf::implementation *con
printf("%02x ", (unsigned char)c);
}
printf("\n");
printf("string length: %llu\n", s.size());
printf("string length: %zu\n", s.size());
printf("implementation->name() = %s", e->name().c_str());
}

Expand Down Expand Up @@ -604,11 +604,11 @@ int main(int argc, char*argv[]) {
return EXIT_FAILURE;
}
}
printf("Number of strings: %llu\n", N);
printf("Number of strings: %zu\n", N);
if (fuzz_running(N)) {
printf("valid UTF8 = %llu\n", valid_utf8);
printf("valid UTF16-BE = %llu\n", valid_utf16be);
printf("valid UTF16-LE = %llu\n", valid_utf16be);
printf("valid UTF8 = %zu\n", valid_utf8);
printf("valid UTF16-BE = %zu\n", valid_utf16be);
printf("valid UTF16-LE = %zu\n", valid_utf16be);
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
Expand Down
14 changes: 7 additions & 7 deletions tests/readme_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main_demo() {
// convert to UTF-16LE
size_t utf16words =
simdutf::convert_utf8_to_utf16le(source, 4, utf16_output.get());
printf("wrote %llu UTF-16LE code units.", utf16words);
printf("wrote %zu UTF-16LE code units.", utf16words);
// It wrote utf16words * sizeof(char16_t) bytes.
bool validutf16 = simdutf::validate_utf16le(utf16_output.get(), utf16words);
if (validutf16) {
Expand All @@ -45,7 +45,7 @@ int main_demo() {
// convert to UTF-8
size_t utf8words = simdutf::convert_utf16le_to_utf8(
utf16_output.get(), utf16words, utf8_output.get());
printf("wrote %llu UTF-8 code units.", utf8words);
printf("wrote %zu UTF-8 code units.", utf8words);
std::string final_string(utf8_output.get(), utf8words);
puts(final_string.c_str());
if (final_string != source) {
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST(error_location_badascii) {
std::string bad_ascii = "\x20\x20\x20\x20\x20\xff\x20\x20\x20";
simdutf::result res = implementation.validate_ascii_with_errors(bad_ascii.data(), bad_ascii.size());
if (res.error != simdutf::error_code::SUCCESS) {
printf("error at index %llu\n", res.count);
printf("error at index %zu\n", res.count);
}
ASSERT_EQUAL(res.error, simdutf::error_code::TOO_LARGE);
ASSERT_EQUAL(res.count, 5);
Expand All @@ -123,13 +123,13 @@ TEST(error_location_badutf8) {
std::string bad_utf8 = "\xc3\xa9\xc3\xa9\x20\xff\xc3\xa9";
simdutf::result res = implementation.validate_utf8_with_errors(bad_utf8.data(), bad_utf8.size());
if(res.error != simdutf::error_code::SUCCESS) {
printf("error at index %llu\n", res.count);
printf("error at index %zu\n", res.count);
}
ASSERT_EQUAL(res.error, simdutf::error_code::HEADER_BITS);
ASSERT_EQUAL(res.count, 5);
res = implementation.validate_utf8_with_errors(bad_utf8.data(), res.count);
if(res.error == simdutf::error_code::SUCCESS) {
printf("we have transcoded %llu valud bytes", res.count);
printf("we have transcoded %zu valud bytes", res.count);
}
ASSERT_EQUAL(res.error, simdutf::error_code::SUCCESS);
ASSERT_EQUAL(res.count, 5);
Expand All @@ -145,13 +145,13 @@ TEST(error_location_badutf8_transcoding) {
simdutf::result res = simdutf::convert_utf8_to_utf16_with_errors(bad_utf8.data(), bad_utf8.size(), utf16.get());

if(res.error != simdutf::error_code::SUCCESS) {
printf("error at index %llu\n", res.count);
printf("error at index %zu\n", res.count);
}
ASSERT_EQUAL(res.error, simdutf::error_code::HEADER_BITS);
ASSERT_EQUAL(res.count, 5);
res = simdutf::convert_utf8_to_utf16_with_errors(bad_utf8.data(), res.count, utf16.get());
if(res.error == simdutf::error_code::SUCCESS) {
printf("we have transcoded %llu characters", res.count);
printf("we have transcoded %zu characters", res.count);
}
ASSERT_EQUAL(res.error, simdutf::error_code::SUCCESS);
ASSERT_EQUAL(res.count, 3);
Expand Down

0 comments on commit a04d66f

Please sign in to comment.