From: Masamichi Hosoda Date: Fri, 10 Jun 2016 13:12:33 +0000 (+0900) Subject: Issue 4890: Fix ly:format for the string that contain zero X-Git-Tag: release/2.19.44-1~11 X-Git-Url: https://git.donarmstrong.com/?p=lilypond.git;a=commitdiff_plain;h=211634be6f90db700eb8e5725046b27aa153ee92 Issue 4890: Fix ly:format for the string that contain zero 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. --- diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc index d5fe89024c..02cf2fa76b 100644 --- a/lily/general-scheme.cc +++ b/lily/general-scheme.cc @@ -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';