]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4890: Fix ly:format for the string that contain zero
authorMasamichi Hosoda <trueroad@trueroad.jp>
Fri, 10 Jun 2016 13:12:33 +0000 (22:12 +0900)
committerMasamichi Hosoda <trueroad@trueroad.jp>
Wed, 15 Jun 2016 15:06:57 +0000 (00:06 +0900)
strcpy and strncpy cannot be used in std::string concatenation
because std::string may contain '\0' in its contents.

In order to avoid problems with string that contains '\0',
this commit replaces the strncpy to std::string::copy.

lily/general-scheme.cc

index d5fe89024cd2fa7c0cce49968a74f665d8465795..02cf2fa76bf3c660a473b70da7ae543b574297af 100644 (file)
@@ -595,7 +595,9 @@ LY_DEFINE (ly_format, "ly:format",
   char *ptr = result;
   for (vsize i = 0; i < results.size (); i++)
     {
-      strncpy (ptr, results[i].c_str (), results[i].size ());
+      // strcpy and strncpy cannot be used here
+      // because std::string may contain '\0' in its contents.
+      results[i].copy (ptr, results[i].size ());
       ptr += results[i].size ();
     }
   *ptr = '\0';