mattn/go-ole — pull request #42 by mgspross (2014-12-09 23:11:20+00:00)
Title: Fixes SysAllocStringLen to handle empty strings without causing panic.

This fixes issue #41.

The problem was that the code converts the passed-in string to UTF16, which means converting it to a slice of int16's. The code then needs to get the address of the first character in this slice, in order to pass the pointer to the real `SysAllocStringLen` function in Windows.

Since the slice will be empty for an empty string, the code to get the pointer (`&utf16[0]`) panics because the slice is empty.

This was fixed by appending an extra null character to the string before it is converted to UTF16, so that the resulting slice will always contain at least character. 1 character is then substracted from the length of the string to allocate, so the extra character is not included in the copy of the string that Windows allocates.