[dlls/shlwapi/string.c] Strncpy elimination.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 14:23:54 CST 2005
Hunk 3 is safe as szCopy is set to \0 some line above.
Changelog:
Change strncpy and StrCpyNXA to lstrcpynA.
Index: dlls/shlwapi/string.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/string.c,v
retrieving revision 1.54
diff -u -r1.54 string.c
--- dlls/shlwapi/string.c 24 Mar 2005 21:01:37 -0000 1.54
+++ dlls/shlwapi/string.c 26 Mar 2005 09:41:23 -0000
@@ -1577,7 +1577,7 @@
ulKB = (ulKB - ulNextDigit) / 10;
} while (ulKB > 0);
- strncpy(lpszDest, szOut + 1, cchMax);
+ lstrcpynA(lpszDest, szOut + 1, cchMax);
return lpszDest;
}
@@ -1605,7 +1605,7 @@
ulKB = (ulKB - ulNextDigit) / 10;
} while (ulKB > 0);
- strncpyW(lpszDest, szOut + 1, cchMax);
+ lstrcpynW(lpszDest, szOut + 1, cchMax);
return lpszDest;
}
@@ -2027,8 +2027,9 @@
if (iDigits) /* Always write seconds if we have significant digits */
SHLWAPI_WriteTimeClass(szCopy, dwMS, szSec, iDigits);
- strncpyW(lpszStr, szCopy, cchMax);
- iRet = strlenW(lpszStr);
+ iRet = min(strlen(szCopy),cchMax-1);
+ memcpy(lpszStr, szCopy, iRet * sizeof(WCHAR));
+ lpszStr[iRet] = '\0';
}
return iRet;
}
@@ -2301,7 +2302,7 @@
sprintfW(wszBuff, bfFormats[i].lpwszFormat, dBytes);
wszAdd[1] = bfFormats[i].wPrefix;
strcatW(wszBuff, wszAdd);
- strncpyW(lpszDest, wszBuff, cchMax);
+ lstrcpynW(lpszDest, wszBuff, cchMax);
return lpszDest;
}
@@ -2638,10 +2639,7 @@
TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszSrc), lpszDst, iLen);
- /* Our original version used lstrncpy/lstrlen, incorrectly filling up all
- * of lpszDst with extra NULs. This version is correct, and faster too.
- */
- lpszRet = StrCpyNXA(lpszDst, lpszSrc, iLen);
+ lpszRet = lstrcpynA(lpszDst, lpszSrc, iLen);
return lpszRet - lpszDst + 1;
}
@@ -2656,7 +2654,7 @@
TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszSrc), lpszDst, iLen);
- lpszRet = StrCpyNXW(lpszDst, lpszSrc, iLen);
+ lpszRet = lstrcpynW(lpszDst, lpszSrc, iLen);
return lpszRet - lpszDst + 1;
}
More information about the wine-patches
mailing list