Mark SkStringPrintf as SK_PRINTF_LIKE

Change-Id: I3d2ee8dca1d2e962794ce8c3c391779bff357f0c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/288762
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
This commit is contained in:
Adlai Holler 2020-05-12 10:41:04 -04:00 committed by Skia Commit-Bot
parent cb1c2624e7
commit 684838f1f5
23 changed files with 79 additions and 61 deletions

View File

@ -15,7 +15,7 @@ public:
explicit MemsetBench(int n)
: fN(n)
, fBuffer(n)
, fName(SkStringPrintf("memset%d_%d%s", sizeof(T)*8, n, kInline ? "_inline" : "")) {}
, fName(SkStringPrintf("memset%zu_%d%s", sizeof(T)*8, n, kInline ? "_inline" : "")) {}
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
const char* onGetName() override { return fName.c_str(); }

View File

@ -52,6 +52,7 @@
#include "experimental/svg/model/SkSVGDOM.h"
#endif // SK_XML
#include <cinttypes>
#include <stdlib.h>
#include <thread>
@ -179,7 +180,7 @@ static DEFINE_bool(purgeBetweenBenches, false,
static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
static SkString humanize(double ms) {
if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
if (FLAGS_verbose) return SkStringPrintf("%" PRIu64, (uint64_t)(ms*1e6));
return HumanizeMs(ms);
}
#define HUMANIZE(ms) humanize(ms).c_str()

View File

@ -269,7 +269,7 @@ private:
};
/// Creates a new string and writes into it using a printf()-style format.
SkString SkStringPrintf(const char* format, ...);
SkString SkStringPrintf(const char* format, ...) SK_PRINTF_LIKE(1, 2);
/// This makes it easier to write a caller as a VAR_ARGS function where the format string is
/// optional.
static inline SkString SkStringPrintf() { return SkString(); }

View File

@ -46,7 +46,7 @@ static DEFINE_int(threads, 0, "Number of worker threads (0 -> cores count).");
namespace {
std::unique_ptr<SkFILEWStream> MakeFrameStream(size_t idx, const char* ext) {
const auto frame_file = SkStringPrintf("0%06d.%s", idx, ext);
const auto frame_file = SkStringPrintf("0%06zu.%s", idx, ext);
auto stream = std::make_unique<SkFILEWStream>(SkOSPath::Join(FLAGS_writePath[0],
frame_file.c_str()).c_str());
if (!stream->isValid()) {

View File

@ -98,7 +98,7 @@ void SkTextBlobTrace::Capture::dump(SkWStream* dst) const {
SkTLazy<SkFILEWStream> fileStream;
if (!dst) {
uint32_t id = SkChecksum::Mix(reinterpret_cast<uintptr_t>(this));
SkString f = SkStringPrintf("diff-canvas-%08x-%04d.trace", id, fBlobCount);
SkString f = SkStringPrintf("diff-canvas-%08x-%04zu.trace", id, fBlobCount);
dst = fileStream.init(f.c_str());
if (!fileStream->isValid()) {
SkDebugf("Error opening '%s'.\n", f.c_str());

View File

@ -17,6 +17,8 @@
#include "src/core/SkVM.h"
#include "src/shaders/SkColorFilterShader.h"
#include <cinttypes>
namespace {
// Uniforms set by the Blitter itself,
@ -80,14 +82,15 @@ namespace {
SK_END_REQUIRE_DENSE;
static SkString debug_name(const Key& key) {
return SkStringPrintf("Shader-%llx_Clip-%llx_CS-%llx_CT-%d_AT-%d_Blend-%d_Cov-%d",
key.shader,
key.clip,
key.colorSpace,
key.colorType,
key.alphaType,
key.blendMode,
key.coverage);
return SkStringPrintf(
"Shader-%" PRIx64 "_Clip-%" PRIx64 "_CS-%" PRIx64 "_CT-%d_AT-%d_Blend-%d_Cov-%d",
key.shader,
key.clip,
key.colorSpace,
key.colorType,
key.alphaType,
key.blendMode,
key.coverage);
}
static SkLRUCache<Key, skvm::Program>* try_acquire_program_cache() {

View File

@ -269,7 +269,7 @@ DEF_TEST(AnimatedImage, r) {
}
if (!testDraw(animatedImage, i)) {
ERRORF(r, "Did not update to %i properly", i);
ERRORF(r, "Did not update to %zu properly", i);
failed = true;
break;
}
@ -339,7 +339,7 @@ DEF_TEST(AnimatedImage, r) {
failed = true;
}
if (i != frameInfos.size() - 1) {
ERRORF(r, "%s animation stopped early: i: %i\tsize: %i",
ERRORF(r, "%s animation stopped early: i: %zu\tsize: %zu",
file, i, frameInfos.size());
failed = true;
}

View File

@ -201,27 +201,27 @@ DEF_TEST(Codec_frames, r) {
const int expected = rec.fFrameCount;
if (rec.fRequiredFrames.size() + 1 != static_cast<size_t>(expected)) {
ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expected: %i\tactual: %i",
ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expected: %i\tactual: %zu",
rec.fName, expected - 1, rec.fRequiredFrames.size());
continue;
}
if (expected > 1) {
if (rec.fDurations.size() != static_cast<size_t>(expected)) {
ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i\tactual: %i",
ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i\tactual: %zu",
rec.fName, expected, rec.fDurations.size());
continue;
}
if (rec.fAlphas.size() + 1 != static_cast<size_t>(expected)) {
ERRORF(r, "'%s' has wrong number entries in fAlphas; expected: %i\tactual: %i",
ERRORF(r, "'%s' has wrong number entries in fAlphas; expected: %i\tactual: %zu",
rec.fName, expected - 1, rec.fAlphas.size());
continue;
}
if (rec.fDisposalMethods.size() != static_cast<size_t>(expected)) {
ERRORF(r, "'%s' has wrong number entries in fDisposalMethods; "
"expected %i\tactual: %i",
"expected %i\tactual: %zu",
rec.fName, expected, rec.fDisposalMethods.size());
continue;
}

View File

@ -289,7 +289,7 @@ DEF_TEST(Codec_partialAnim, r) {
}
if (result != SkCodec::kSuccess) {
ERRORF(r, "Failed to decode frame %i from %s", i, path);
ERRORF(r, "Failed to decode frame %zu from %s", i, path);
return;
}
@ -301,7 +301,7 @@ DEF_TEST(Codec_partialAnim, r) {
std::unique_ptr<SkCodec> partialCodec(SkCodec::MakeFromStream(
std::unique_ptr<SkStream>(haltingStream)));
if (!partialCodec) {
ERRORF(r, "Failed to create a partial codec from %s with %i bytes out of %i",
ERRORF(r, "Failed to create a partial codec from %s with %zu bytes out of %zu",
path, frameByteCounts[0], file->size());
return;
}
@ -325,7 +325,7 @@ DEF_TEST(Codec_partialAnim, r) {
SkCodec::Result result = partialCodec->startIncrementalDecode(info,
frame.getPixels(), frame.rowBytes(), &opts);
if (result != SkCodec::kSuccess) {
ERRORF(r, "Failed to start incremental decode for %s on frame %i",
ERRORF(r, "Failed to start incremental decode for %s on frame %zu",
path, i);
return;
}
@ -341,11 +341,11 @@ DEF_TEST(Codec_partialAnim, r) {
REPORTER_ASSERT(r, frameInfo.size() == i + 1);
REPORTER_ASSERT(r, frameInfo[i].fFullyReceived);
if (!compare_bitmaps(r, frames[i], frame)) {
ERRORF(r, "\tfailure was on frame %i", i);
SkString name = SkStringPrintf("expected_%i", i);
ERRORF(r, "\tfailure was on frame %zu", i);
SkString name = SkStringPrintf("expected_%zu", i);
write_bm(name.c_str(), frames[i]);
name = SkStringPrintf("actual_%i", i);
name = SkStringPrintf("actual_%zu", i);
write_bm(name.c_str(), frame);
}
}
@ -534,15 +534,15 @@ DEF_TEST(Codec_incomplete, r) {
std::make_unique<SkMemoryStream>(file->data(), len), &result));
if (codec) {
if (result != SkCodec::kSuccess) {
ERRORF(r, "Created an SkCodec for %s with %lu bytes, but "
"reported an error %i", name, len, result);
ERRORF(r, "Created an SkCodec for %s with %zu bytes, but "
"reported an error %i", name, len, (int)result);
}
break;
}
if (SkCodec::kIncompleteInput != result) {
ERRORF(r, "Reported error %i for %s with %lu bytes",
result, name, len);
ERRORF(r, "Reported error %i for %s with %zu bytes",
(int)result, name, len);
break;
}
}

View File

@ -1517,7 +1517,7 @@ DEF_TEST(Codec_InvalidAnimated, r) {
auto result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes(), &opts);
if (result != SkCodec::kSuccess) {
ERRORF(r, "Failed to start decoding frame %i (out of %i) with error %i\n", i,
ERRORF(r, "Failed to start decoding frame %i (out of %zu) with error %i\n", i,
frameInfos.size(), result);
continue;
}

View File

@ -591,7 +591,7 @@ static void run_test(GrContext* context, const char* testName, skiatest::Reporte
return;
}
if (sizeof(uint32_t) * kImageWidth != gold.rowBytes()) {
ERRORF(reporter, "unexpected row bytes in gold image.", testName);
ERRORF(reporter, "[%s] unexpected row bytes in gold image", testName);
return;
}

View File

@ -24,11 +24,11 @@ static void assert_quad_eq(skiatest::Reporter* r, const GrQuad& expected, const
ASSERTF(expected.quadType() == actual.quadType(), "Expected type %d, got %d",
(int) expected.quadType(), (int) actual.quadType());
for (int i = 0; i < 4; ++i) {
ASSERTF(expected.x(i) == actual.x(i), "Expected x(%d) = %f, got %d",
ASSERTF(expected.x(i) == actual.x(i), "Expected x(%d) = %f, got %f",
i, expected.x(i), actual.x(i));
ASSERTF(expected.y(i) == actual.y(i), "Expected y(%d) = %f, got %d",
ASSERTF(expected.y(i) == actual.y(i), "Expected y(%d) = %f, got %f",
i, expected.y(i), actual.y(i));
ASSERTF(expected.w(i) == actual.w(i), "Expected w(%d) = %f, got %d",
ASSERTF(expected.w(i) == actual.w(i), "Expected w(%d) = %f, got %f",
i, expected.w(i), actual.w(i));
}
}

View File

@ -16,6 +16,8 @@
#include "src/core/SkMathPriv.h"
#include "tests/Test.h"
#include <cinttypes>
static void test_clz(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 32 == SkCLZ(0));
REPORTER_ASSERT(reporter, 31 == SkCLZ(1));
@ -480,7 +482,8 @@ DEF_TEST(Math, reporter) {
check = SK_MinS32;
}
if (result != (int32_t)check) {
ERRORF(reporter, "\nFixed Divide: %8x / %8x -> %8x %8x\n", numer, denom, result, check);
ERRORF(reporter, "\nFixed Divide: %8x / %8x -> %8x %8" PRIx64 "\n", numer, denom,
result, check);
}
REPORTER_ASSERT(reporter, result == (int32_t)check);
}

View File

@ -169,8 +169,8 @@ DEF_TEST(Serialize_and_deserialize_multi_skp, reporter) {
// Confirm written data is at least as large as the magic word
std::unique_ptr<SkStreamAsset> writtenStream = stream.detachAsStream();
REPORTER_ASSERT(reporter, writtenStream->getLength() > 24,
"Written data length too short (%d)", writtenStream->getLength());
// SkDebugf("Multi Frame file size = %d\n", writtenStream->getLength());
"Written data length too short (%zu)", writtenStream->getLength());
// SkDebugf("Multi Frame file size = %zu\n", writtenStream->getLength());
// Set up deserialization
SkSharingDeserialContext deserialContext;
@ -196,9 +196,9 @@ DEF_TEST(Serialize_and_deserialize_multi_skp, reporter) {
for (const auto& frame : frames) {
SkRect bounds = frame.fPicture->cullRect();
REPORTER_ASSERT(reporter, bounds.width() == WIDTH,
"Page width: expected (%d) got (%d)", WIDTH, bounds.width());
"Page width: expected (%d) got (%d)", WIDTH, (int)bounds.width());
REPORTER_ASSERT(reporter, bounds.height() == HEIGHT,
"Page height: expected (%d) got (%d)", HEIGHT, bounds.height());
"Page height: expected (%d) got (%d)", HEIGHT, (int)bounds.height());
// confirm contents of picture match what we drew.
// There are several ways of doing this, an ideal comparison would not break in the same
// way at the same time as the code under test (no serialization), and would involve only

View File

@ -59,7 +59,7 @@ static void assert_eql(skiatest::Reporter* reporter,
size_t len) {
if (!eq(skString, str, len)) {
REPORT_FAILURE(reporter, "", SkStringPrintf(
"'%*s' != '%s'", len, str, skString.c_str()));
"'%*s' != '%s'", (int)len, str, skString.c_str()));
}
}

View File

@ -122,8 +122,8 @@ DEF_TEST(SkVM, r) {
} else if (!expected->equals(actual.get())) {
ERRORF(r, "SkVMTest expected\n%.*s\nbut got\n%.*s\n",
expected->size(), expected->data(),
actual->size(), actual->data());
(int)expected->size(), expected->data(),
(int)actual->size(), actual->data());
writeActualAsNewExpectation = true;
}
}

View File

@ -167,10 +167,10 @@ static void TestPackedUInt(skiatest::Reporter* reporter) {
for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) {
size_t n;
if (!rstream->readPackedUInt(&n)) {
ERRORF(reporter, "[%d] sizes:%x could not be read\n", i, sizes[i]);
ERRORF(reporter, "[%zu] sizes:%zx could not be read\n", i, sizes[i]);
}
if (sizes[i] != n) {
ERRORF(reporter, "[%d] sizes:%x != n:%x\n", i, sizes[i], n);
ERRORF(reporter, "[%zu] sizes:%zx != n:%zx\n", i, sizes[i], n);
}
}
}

View File

@ -168,7 +168,7 @@ DEF_TEST(String, reporter) {
REPORTER_ASSERT(reporter, a.size() == 2000);
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] != ' ') {
ERRORF(reporter, "SkStringPrintf fail: a[%d] = '%c'", i, a[i]);
ERRORF(reporter, "SkStringPrintf fail: a[%zu] = '%c'", i, a[i]);
break;
}
}
@ -177,7 +177,7 @@ DEF_TEST(String, reporter) {
REPORTER_ASSERT(reporter, a.size() == 2000);
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] != ' ') {
ERRORF(reporter, "SkString::printf fail: a[%d] = '%c'", i, a[i]);
ERRORF(reporter, "SkString::printf fail: a[%zu] = '%c'", i, a[i]);
break;
}
}
@ -185,7 +185,7 @@ DEF_TEST(String, reporter) {
REPORTER_ASSERT(reporter, a.size() == 4000);
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] != ' ') {
ERRORF(reporter, "SkString::appendf fail: a[%d] = '%c'", i, a[i]);
ERRORF(reporter, "SkString::appendf fail: a[%zu] = '%c'", i, a[i]);
break;
}
}

View File

@ -146,16 +146,24 @@ private:
} // namespace skiatest
#define REPORTER_ASSERT(r, cond, ...) \
do { \
if (!(cond)) { \
REPORT_FAILURE(r, #cond, SkStringPrintf(__VA_ARGS__)); \
} \
static inline SkString reporter_string() { return {}; }
/// Prevent security warnings when using a non-literal string i.e. not a format string.
static inline SkString reporter_string(const char* s) { return SkString(s); }
template<typename... Args>
static inline SkString reporter_string(const char* fmt, Args... args) {
return SkStringPrintf(fmt, std::forward<Args>(args)...);
}
#define REPORTER_ASSERT(r, cond, ...) \
do { \
if (!(cond)) { \
REPORT_FAILURE(r, #cond, reporter_string(__VA_ARGS__)); \
} \
} while (0)
#define ERRORF(r, ...) \
do { \
REPORT_FAILURE(r, "", SkStringPrintf(__VA_ARGS__)); \
#define ERRORF(r, ...) \
do { \
REPORT_FAILURE(r, "", reporter_string(__VA_ARGS__)); \
} while (0)
#define INFOF(REPORTER, ...) \

View File

@ -362,7 +362,7 @@ DEF_TEST(Typeface_glyph_to_char, reporter) {
// If two codepoints map to the same glyph then this assert is not valid.
// However, the emoji test font should never have multiple characters map to the same glyph.
REPORTER_ASSERT(reporter, originalCodepoints[i] == newCodepoints[i],
"name:%s i:%d original:%d new:%d glyph:%d", familyName.c_str(), i,
"name:%s i:%zu original:%d new:%d glyph:%d", familyName.c_str(), i,
originalCodepoints[i], newCodepoints[i], glyphs[i]);
}
}

View File

@ -111,9 +111,12 @@ struct Result {
static const Result ok = {Result::Ok, {}},
skip = {Result::Skip, {}};
static Result fail(const char* why) {
return { Result::Fail, SkString(why) };
}
template <typename... Args>
static Result fail(const char* why, Args... args) {
return { Result::Fail, SkStringPrintf(why, args...) };
static Result fail(const char* whyFmt, Args... args) {
return { Result::Fail, SkStringPrintf(whyFmt, args...) };
}

View File

@ -494,7 +494,7 @@ void SkQP::makeReport() {
if (result.fErrors.empty()) {
unitOut.writeText(" PASSED\n* * *\n");
} else {
write(&unitOut, SkStringPrintf(" FAILED (%u errors)\n", result.fErrors.size()));
write(&unitOut, SkStringPrintf(" FAILED (%zu errors)\n", result.fErrors.size()));
for (const std::string& err : result.fErrors) {
write(&unitOut, err);
unitOut.newline();

View File

@ -36,10 +36,10 @@ static void draw_stats_box(SkCanvas* canvas, const skottie::Animation::Builder::
paint.setColor(SK_ColorBLACK);
const auto json_size = SkStringPrintf("Json size: %lu bytes",
const auto json_size = SkStringPrintf("Json size: %zu bytes",
stats.fJsonSize);
canvas->drawString(json_size, kR.x() + 10, kR.y() + kTextSize * 1, font, paint);
const auto animator_count = SkStringPrintf("Animator count: %lu",
const auto animator_count = SkStringPrintf("Animator count: %zu",
stats.fAnimatorCount);
canvas->drawString(animator_count, kR.x() + 10, kR.y() + kTextSize * 2, font, paint);
const auto json_parse_time = SkStringPrintf("Json parse time: %.3f ms",