Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: src/pdf/SkPDFMetadata.cpp

Issue 1908423002: Revert of SkStringPrintf and SkString::printf now are no longer limted by a static buffer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkString.cpp ('k') | tests/StringTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFMetadata.cpp
diff --git a/src/pdf/SkPDFMetadata.cpp b/src/pdf/SkPDFMetadata.cpp
index d3abd78312caecdcfff651cc6d7698b28abc6149..2765d4d189b99b0ae0042b0ff531f12797762370 100644
--- a/src/pdf/SkPDFMetadata.cpp
+++ b/src/pdf/SkPDFMetadata.cpp
@@ -93,6 +93,54 @@
array->appendString(
SkString(reinterpret_cast<const char*>(&instance), sizeof(UUID)));
return array.release();
+}
+
+// Improvement on SkStringPrintf to allow for arbitrarily long output.
+// TODO: replace SkStringPrintf.
+static SkString sk_string_printf(const char* format, ...) {
+#ifdef SK_BUILD_FOR_WIN
+ va_list args;
+ va_start(args, format);
+ char buffer[1024];
+ int length = _vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, format, args);
+ va_end(args);
+ if (length >= 0 && length < (int)sizeof(buffer)) {
+ return SkString(buffer, length);
+ }
+ va_start(args, format);
+ length = _vscprintf(format, args);
+ va_end(args);
+
+ SkString string((size_t)length);
+ va_start(args, format);
+ SkDEBUGCODE(int check = ) _vsnprintf_s(string.writable_str(), length + 1,
+ _TRUNCATE, format, args);
+ va_end(args);
+ SkASSERT(check == length);
+ SkASSERT(string[length] == '\0');
+ return string;
+#else // C99/C++11 standard vsnprintf
+ // TODO: When all compilers support this, remove windows-specific code.
+ va_list args;
+ va_start(args, format);
+ char buffer[1024];
+ int length = vsnprintf(buffer, sizeof(buffer), format, args);
+ va_end(args);
+ if (length < 0) {
+ return SkString();
+ }
+ if (length < (int)sizeof(buffer)) {
+ return SkString(buffer, length);
+ }
+ SkString string((size_t)length);
+ va_start(args, format);
+ SkDEBUGCODE(int check = )
+ vsnprintf(string.writable_str(), length + 1, format, args);
+ va_end(args);
+ SkASSERT(check == length);
+ SkASSERT(string[length] == '\0');
+ return string;
+#endif
}
static const SkString get(const SkTArray<SkDocument::Attribute>& info,
@@ -255,14 +303,14 @@
fCreation->toISO8601(&tmp);
SkASSERT(0 == count_xml_escape_size(tmp));
// YYYY-mm-ddTHH:MM:SS[+|-]ZZ:ZZ; no need to escape
- creationDate = SkStringPrintf("<xmp:CreateDate>%s</xmp:CreateDate>\n",
- tmp.c_str());
+ creationDate = sk_string_printf("<xmp:CreateDate>%s</xmp:CreateDate>\n",
+ tmp.c_str());
}
if (fModified) {
SkString tmp;
fModified->toISO8601(&tmp);
SkASSERT(0 == count_xml_escape_size(tmp));
- modificationDate = SkStringPrintf(
+ modificationDate = sk_string_printf(
"<xmp:ModifyDate>%s</xmp:ModifyDate>\n", tmp.c_str());
}
SkString title = escape_xml(
@@ -291,7 +339,7 @@
SkASSERT(0 == count_xml_escape_size(documentID));
SkString instanceID = uuid_to_string(instance);
SkASSERT(0 == count_xml_escape_size(instanceID));
- return new PDFXMLObject(SkStringPrintf(
+ return new PDFXMLObject(sk_string_printf(
templateString, modificationDate.c_str(), creationDate.c_str(),
creator.c_str(), title.c_str(),
subject.c_str(), author.c_str(), keywords1.c_str(),
« no previous file with comments | « src/core/SkString.cpp ('k') | tests/StringTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698