Fix strncpyWtoA to actually act as advertised (and not overflow the

input buffer).
Small cleanups of it at the same time.
This commit is contained in:
Vincent Béron 2003-09-22 19:45:29 +00:00 committed by Alexandre Julliard
parent ad1a1064d0
commit a8fb3d786e
1 changed files with 3 additions and 5 deletions

View File

@ -81,13 +81,12 @@ char *get_typename(resource_t* r)
char *strncpyWtoA(char *cs, short *ws, int maxlen) char *strncpyWtoA(char *cs, short *ws, int maxlen)
{ {
char *cptr = cs; char *cptr = cs;
short *wsMax = ws + maxlen; short *wsMax = ws + maxlen - 1;
while(ws < wsMax) while(*ws && ws < wsMax)
{ {
if(*ws < -128 || *ws > 127) if(*ws < -128 || *ws > 127)
printf("***Warning: Unicode string contains non-printable chars***"); fprintf(stderr, "***Warning: Unicode string contains non-printable chars***\n");
*cptr++ = (char)*ws++; *cptr++ = (char)*ws++;
maxlen--;
} }
*cptr = '\0'; *cptr = '\0';
return cs; return cs;
@ -1047,4 +1046,3 @@ void dump_resources(resource_t *top)
top = top->next; top = top->next;
} }
} }