Handling NULL in copyToUnicode / copyChars

By accident I ended up calling String::copyToUnicode(NULL,0); and my program crashed. I fixed it by changing CopyChars to static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw() { if (numChars > 0) { memcpy (dest, src, numChars * sizeof (juce_wchar)); dest [numChars] = 0; } }The function’s so short that sending the whole thing seems easier than a diff. Not sure if you’d prefer to change copyToUnicode instead but I figure there may be other places that call copyChars this way.

Good point, but not the right fix! copyChars needs to write a null terminator even if the length is zero, so this would certainly break something. Plus, making it check its parameters would be an unnecessary pessimisation for all the code that uses it safely - it’s only the copyToUnicode method that risks passing it a dodgy pointer, so that’s where the check needs to go. Thanks, I’ll sort it out!