On May 31, 2003 05:45 am, Shachar Shemesh wrote:
/* Treat the case where no special handling was requested in a
fastpath way */ + /* copy will do if the GCP_REORDER flag is not set */
if (lpResults->lpOutString)
for (i = 0; i < nSet && lpString[i] != 0; ++i)
lpResults->lpOutString[i] = lpString[i];
What about a strncpy here:
+ if (lpResults->lpOutString) + strncpyW(lpResults->lpOutString, lpString, nSet);
Dimitrie O. Paun wrote:
On May 31, 2003 05:45 am, Shachar Shemesh wrote:
/* Treat the case where no special handling was requested in a
fastpath way */ + /* copy will do if the GCP_REORDER flag is not set */
if (lpResults->lpOutString)
for (i = 0; i < nSet && lpString[i] != 0; ++i)
lpResults->lpOutString[i] = lpString[i];
What about a strncpy here:
if (lpResults->lpOutString)
strncpyW(lpResults->lpOutString, lpString, nSet);
Probably a good idea. These lines predate my involvment in Wine, so I did not touch them under the "it works" discipline. I copied them over from objects/font.c (GetCharacterPlacementW), and I'm sending out another cleanup patch that removes these lines. I'll fix the upstream copy, if you think it's woth it (I am touching that function anyways).
Shachar
if (lpResults->lpOutString)
for (i = 0; i < nSet && lpString[i] != 0; ++i)
lpResults->lpOutString[i] = lpString[i];
What about a strncpy here:
Be aware that strncyp() rarely DTRT, in particular: - it doesn't guarantee to zero terminate the target - it is required to zero fill the target buffer Neither of these is usually desirable.
Many systems have a strlcpy() function which does what you want much more often.
OTOH is the target buffer can be too short with valid data, they you need to (typically) dynamically allocate a buffer.
David
David Laight wrote:
Be aware that strncyp() rarely DTRT, in particular:
- it doesn't guarantee to zero terminate the target
- it is required to zero fill the target buffer
Neither of these is usually desirable.
Well aware of both. Thanks. I'm routinely giving lectures about them (http://shemesh.biz/lectures).
Since the buffer is not zero terminated to begin with, 1 is not a problem. Since the loop that strncpy replaces copied n bytes over from the old buffer to the new one, neither is 2. This does impose the theoretical problem that if the original string WAS zero terminated, and the NULL was not the last WCHAR in the buffer, we change the semantics. I doubt very much, however, that you will find a program that relies on this. I don't even know what Windows does under the same circumstances.
Many systems have a strlcpy() function which does what you want much more often.
Well aware of that too. strncpy is really the most fitting here. Trust me.
OTOH is the target buffer can be too short with valid data, they you need to (typically) dynamically allocate a buffer.
Not applicable to GetCharacterPlacement.
David
Thanks.
Shachar
Shachar Shemesh wrote:
David Laight wrote:
Be aware that strncyp() rarely DTRT, in particular:
- it doesn't guarantee to zero terminate the target
- it is required to zero fill the target buffer
Neither of these is usually desirable.
Well aware of both. Thanks. I'm routinely giving lectures about them (http://shemesh.biz/lectures).
Seems like it's not my day for URLs.
http://shemesh.biz/lecures.html
Shachar
On Mon, 2 Jun 2003, Shachar Shemesh wrote:
Seems like it's not my day for URLs.
^t^
No, it really isn't :P
http://shemesh.biz/lectures.html
Dimitrie O. Paun wrote:
On Mon, 2 Jun 2003, Shachar Shemesh wrote:
Seems like it's not my day for URLs.
^t^
No, it really isn't :P
I told you it's not my URLs day.
I'll go to sleep now, if you don't mind.
Sh.
Seems like it's not my day for URLs.
Do you mean: http://shemesh.biz/lectures.html ? :)
Thanks, Hetz
Shachar