From 211634be6f90db700eb8e5725046b27aa153ee92 Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Fri, 10 Jun 2016 22:12:33 +0900 Subject: [PATCH] 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. --- lily/general-scheme.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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'; -- 2.39.2