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>
diff --git a/tests/AnimatedImageTest.cpp b/tests/AnimatedImageTest.cpp
index 98f4860..98ecfd4 100644
--- a/tests/AnimatedImageTest.cpp
+++ b/tests/AnimatedImageTest.cpp
@@ -269,7 +269,7 @@
}
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 @@
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;
}
diff --git a/tests/CodecAnimTest.cpp b/tests/CodecAnimTest.cpp
index 3555441..c052ed2 100644
--- a/tests/CodecAnimTest.cpp
+++ b/tests/CodecAnimTest.cpp
@@ -201,27 +201,27 @@
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;
}
diff --git a/tests/CodecPartialTest.cpp b/tests/CodecPartialTest.cpp
index 43ea226..fba55d1 100644
--- a/tests/CodecPartialTest.cpp
+++ b/tests/CodecPartialTest.cpp
@@ -289,7 +289,7 @@
}
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 @@
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 @@
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 @@
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 @@
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;
}
}
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 638ccc9..c3c815f 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1517,7 +1517,7 @@
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;
}
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 3ee4c35..7209fb3 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -591,7 +591,7 @@
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;
}
diff --git a/tests/GrQuadBufferTest.cpp b/tests/GrQuadBufferTest.cpp
index c6ba08f..e36651c 100644
--- a/tests/GrQuadBufferTest.cpp
+++ b/tests/GrQuadBufferTest.cpp
@@ -24,11 +24,11 @@
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));
}
}
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index d3164ed..7684c34 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -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 @@
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);
}
diff --git a/tests/MultiPictureDocumentTest.cpp b/tests/MultiPictureDocumentTest.cpp
index 5d422ed..06a69bc 100644
--- a/tests/MultiPictureDocumentTest.cpp
+++ b/tests/MultiPictureDocumentTest.cpp
@@ -169,8 +169,8 @@
// 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 @@
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
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index f6169b3..6949f8b 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -59,7 +59,7 @@
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()));
}
}
diff --git a/tests/SkVMTest.cpp b/tests/SkVMTest.cpp
index afff26c..970f994 100644
--- a/tests/SkVMTest.cpp
+++ b/tests/SkVMTest.cpp
@@ -122,8 +122,8 @@
} 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;
}
}
diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp
index ab8e09f..49d2005 100644
--- a/tests/StreamTest.cpp
+++ b/tests/StreamTest.cpp
@@ -167,10 +167,10 @@
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);
}
}
}
diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp
index a8dfc0e..e20732a 100644
--- a/tests/StringTest.cpp
+++ b/tests/StringTest.cpp
@@ -168,7 +168,7 @@
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 @@
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 @@
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;
}
}
diff --git a/tests/Test.h b/tests/Test.h
index c52a724..c5ba79f 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -146,16 +146,24 @@
} // 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, ...) \
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp
index b21284a..b3ee3b6 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -362,7 +362,7 @@
// 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]);
}
}