thestk / rtaudio

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.
Other
1.49k stars 317 forks source link

Subtle problem with WideCharToMultiByte #385

Closed wamckee closed 1 year ago

wamckee commented 1 year ago

The use of a std::string as an output buffer when using WideCharToMultiByte leads to a subtle problem. The string buffer length is defined as "length-1". If length == 1, then the expression &s[0] leads to an out of bound assert when debugging since the length of the string buffer is zero. Furthermore, the value "length" is passed to WideCharToMultiByte indicating that you can write "length" bytes to the string buffer, however, the string buffer is only "length-1" bytes long.