Bugs involving returning strings from API functions
Uwe Bonnes
bon at elektron.ikp.physik.tu-darmstadt.de
Tue Sep 4 02:36:37 CDT 2001
>>>>> "Justin" == Justin Santa Barbara <justinsb at hotmail.com> writes:
Justin> Thanks for the quick reply Uwe. You're absolutely correct in
Justin> that what I stated in my email wasn't right. I'm pretty sure
...
Justin> The problem is that MultiByteToWideChar does count the null
Justin> terminator, if param 4 (the multibyte string length) is -1
Justin> indicating a null-terminated string.
I didn't consider MultiByteToWideChar.
Justin> Hence this code needs to be changed to return instead: if (len
Justin> <= count) return len - 1; else return len;
Justin> Then I had a look at GetSystemDirectoryA:
Justin> UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count ) { if
Justin> (path) lstrcpynA( path, DIR_System.short_name, count ); return
Justin> strlen( DIR_System.short_name ); }
You're right too.
Justin> You're right that strlen doesn't count the terminating null, but
Justin> the problem now is that the terminating null does need to be
Justin> counted if the buffer is too small (it should return the size of
Justin> the buffer required to hold the path). Sorry I didn't explain
Justin> that correctly. So I think we need: len = strlen() if (len <
Justin> count) return len; else return len+1;
Justin> ...
Justin> As I see it, the advantage of a helper function is that for
Justin> about the same amount of work of fixing GetSystemDirectory and
Justin> GetCurrentDirectory, all the functions should work the same way
Justin> meaning any bugs would quickly be found. It might also be
Justin> possible to optimize the case where buflen=0, while this isn't
Justin> practical per-function. Should I offer a patch only for
Justin> wine/files/* ?
I think that everybody feared to write a general helper function and break a
lot ofr special cases. But if done right and tested well, its a good thing.
Write it first for wine/files/*, if it proved usefull, it will find more
uses.
>> >>>>> "Justin" == Justin Santa Barbara <justinsb at hotmail.com> writes:
>>
Justin> There are a group of functions in the kernel that appear to be
Another hint: It is well known habit to cite first, editing away unneeded
parts and then to put one own text. If the whole message gets attached
unattended, it will blew up the text length.
Bye
--
Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
More information about the wine-devel
mailing list