Fix some GCC warnings.

Drop unnecessary () in `const char* (*fText)`.  Sure, whatever.

Then a couple tweaks where we use strncpy():

    In one case in SkICC.cpp, GCC warns us we're passing sizeof(dst) as
    the copy count, which can be error prone because you may miss a
    terminating nul.  I believe the existing strncpy() behavior is what
    we want here, so I've stifled this and left a note.  We don't really
    want a terminating nul... we want a zero fill of the remaining dst.

    On the other side of that if-statment in that same function, GCC
    warns that we've passed exactly sizeof(src) as the copy count when
    writing the calculated description prefix, which again might be
    buggy due to a missed terminating nul.  Seemed like memcpy() was the
    way to go here for that prefix. Ultimately we check to make sure we
    wrote every single destination byte.

    Over in SkPDFMetadata.cpp, strncpy() is concerned once again that
    we're copying strlen(src) and thus omitting the terminating nul.  As
    usual we don't want that terminating nul, so switch to memcpy() to
    make that explicit.

I'm starting to think strncpy() is too helpful to reason about sanely.

Change-Id: I1bcd5f4e406ca388c1c236c5f3ee531bf1737705
Reviewed-by: Brian Osman <>
Reviewed-by: Mike Reed <>
Commit-Queue: Mike Klein <>
diff --git a/bench/TypefaceBench.cpp b/bench/TypefaceBench.cpp
index 711bb6a..6d9579d 100644
--- a/bench/TypefaceBench.cpp
+++ b/bench/TypefaceBench.cpp
@@ -294,7 +294,7 @@
     std::vector<std::unique_ptr<Line>> fLines;
     std::vector<SkGlyphID> fGlyphIds;
     sk_sp<SkTypeface> fTypeface;
-    const char* (*fText);
+    const char** fText;
     int fLineCount;
     const char* fName;
diff --git a/src/core/SkICC.cpp b/src/core/SkICC.cpp
index 78e4a90..d6a29fc 100644
--- a/src/core/SkICC.cpp
+++ b/src/core/SkICC.cpp
@@ -266,16 +266,21 @@
 static void get_color_profile_tag(char dst[kICCDescriptionTagSize],
-                                 const skcms_TransferFunction& fn,
-                                 const skcms_Matrix3x3& toXYZD50) {
+                                  const skcms_TransferFunction& fn,
+                                  const skcms_Matrix3x3& toXYZD50) {
     if (const char* description = get_color_profile_description(fn, toXYZD50)) {
         SkASSERT(strlen(description) < kICCDescriptionTagSize);
-        strncpy(dst, description, kICCDescriptionTagSize);
+        // Without these extra (), GCC would warn us something like
+        //    ... sepecified bound 44 equals destination size ...
+        // which, yeah, is exactly what we're trying to do, copy the string
+        // and zero the rest of the destination if any.  Sheesh.
+        (strncpy(dst, description, kICCDescriptionTagSize));
         // "If the length of src is less than n, strncpy() writes additional
         // null bytes to dest to ensure that a total of n bytes are written."
     } else {
-        strncpy(dst, kDescriptionTagBodyPrefix, sizeof(kDescriptionTagBodyPrefix));
+        memcpy(dst, kDescriptionTagBodyPrefix, sizeof(kDescriptionTagBodyPrefix));
         SkMD5 md5;
         md5.write(&toXYZD50, sizeof(toXYZD50));
         static_assert(sizeof(fn) == sizeof(float) * 7, "packed");
diff --git a/src/pdf/SkPDFMetadata.cpp b/src/pdf/SkPDFMetadata.cpp
index 75ebd90..21c3ed9 100644
--- a/src/pdf/SkPDFMetadata.cpp
+++ b/src/pdf/SkPDFMetadata.cpp
@@ -268,10 +268,10 @@
     static const char kLt[] = "&lt;";
     for (size_t i = 0; i < input.size(); ++i) {
         if (input[i] == '&') {
-            strncpy(out, kAmp, strlen(kAmp));
+            memcpy(out, kAmp, strlen(kAmp));
             out += strlen(kAmp);
         } else if (input[i] == '<') {
-            strncpy(out, kLt, strlen(kLt));
+            memcpy(out, kLt, strlen(kLt));
             out += strlen(kLt);
         } else {
             *out++ = input[i];