http://bugs.winehq.org/show_bug.cgi?id=19839
--- Comment #11 from LIGHTNING UK! lightning_uk@imgburn.com 2009-08-26 04:51:10 --- Oops, seems that if size is 0, windows actually returns the number of characters that *would* be copied into the buffer *if* there was sufficient allocation.
So this should work?
len = strlenW (infoPtr->parts[0].text);
if(size == 0) { return len; } else if(size > len) { strcpyW (buf, infoPtr->parts[0].text); return len; } else { memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR)); buf[size - 1] = 0; // This has to be 'size - 1' rather than just 'size' or you'll get an access overrun? return size - 1; }