First, there's a buffer overflow. The buffer used is 256 bytes long - if the results of String::formatted are greater than 256 bytes, it simply writes into "random memory". This 256 character limitation isn't documented, and as you know, buffer overflows are very dangerous...
So far, I haven't hit this limitation - I found it while debugging the next problem - but since I use String::formatted to make fairly long error messages that include full file paths it is a matter of certainty that if enough people use my program, someone will get an error with a file with a very long path and I'll have something completely unpredictable happen.
My second issue is that String::formatted seemed to work fine on the Mac to print strings, but I got non UTF-8 ("garbage") characters generated on the PC.
After some debugging, I narrowed it down to the fact that Juce's String::formatted only seems to accept wide characters on the PC, and only narrow characters on the Mac!
The following code works fine, but requires different actual calls on Mac and on PC...
- Code: Select all
String MAIL_SUBJECT("Support Request: %s");
String title = "Some title here";
const char* narrow = s.toUTF8().getAddress();
const wchar_t* wide = s.toWideCharPointer();
String res =
This doesn't seem right. Is there a better way to do this, or am I missing something obvious?
(* - admittedly, we haven't prepared a translation yet, but it's all set up to do so...)