Commit 6aefbc09 authored by Peter Berg Larsen's avatar Peter Berg Larsen Committed by Alexandre Julliard

Strncpy elimination.

parent 972a9495
...@@ -111,7 +111,7 @@ HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject (LPDIR ...@@ -111,7 +111,7 @@ HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject (LPDIR
if (dwCount == dwIndex) { if (dwCount == dwIndex) {
HRESULT result = S_OK; HRESULT result = S_OK;
if (pwszAlias) { if (pwszAlias) {
strncpyW (pwszAlias, pContainedObject->wszAlias, DMUS_MAX_FILENAME); lstrcpynW (pwszAlias, pContainedObject->wszAlias, DMUS_MAX_FILENAME);
if (strlenW (pContainedObject->wszAlias) > DMUS_MAX_FILENAME) if (strlenW (pContainedObject->wszAlias) > DMUS_MAX_FILENAME)
result = DMUS_S_STRING_TRUNCATED; result = DMUS_S_STRING_TRUNCATED;
} }
...@@ -199,15 +199,15 @@ HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicObject_SetDescriptor (LPDIR ...@@ -199,15 +199,15 @@ HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicObject_SetDescriptor (LPDIR
dwNewFlags |= DMUS_OBJ_OBJECT; dwNewFlags |= DMUS_OBJ_OBJECT;
} }
if (pDesc->dwValidData & DMUS_OBJ_NAME) { if (pDesc->dwValidData & DMUS_OBJ_NAME) {
strncpyW (This->Desc.wszName, pDesc->wszName, DMUS_MAX_NAME); lstrcpynW (This->Desc.wszName, pDesc->wszName, DMUS_MAX_NAME);
dwNewFlags |= DMUS_OBJ_NAME; dwNewFlags |= DMUS_OBJ_NAME;
} }
if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) { if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) {
strncpyW (This->Desc.wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); lstrcpynW (This->Desc.wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
dwNewFlags |= DMUS_OBJ_CATEGORY; dwNewFlags |= DMUS_OBJ_CATEGORY;
} }
if (pDesc->dwValidData & (DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH)) { if (pDesc->dwValidData & (DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH)) {
strncpyW (This->Desc.wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME); lstrcpynW (This->Desc.wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
dwNewFlags |= (pDesc->dwValidData & (DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH)); dwNewFlags |= (pDesc->dwValidData & (DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH));
} }
if (pDesc->dwValidData & DMUS_OBJ_VERSION) { if (pDesc->dwValidData & DMUS_OBJ_VERSION) {
......
...@@ -131,6 +131,7 @@ HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument ...@@ -131,6 +131,7 @@ HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
unsigned int r = 0; unsigned int r = 0;
DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry; DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
struct list *listEntry; struct list *listEntry;
DWORD dwLen;
TRACE("(%p, %ld, %p, %p, %ld)\n", This, dwIndex, pdwPatch, pwszName, dwNameLen); TRACE("(%p, %ld, %p, %p, %ld)\n", This, dwIndex, pdwPatch, pwszName, dwNameLen);
LIST_FOR_EACH (listEntry, &This->Instruments) { LIST_FOR_EACH (listEntry, &This->Instruments) {
...@@ -138,8 +139,11 @@ HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument ...@@ -138,8 +139,11 @@ HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
if (r == dwIndex) { if (r == dwIndex) {
ICOM_NAME_MULTI (IDirectMusicInstrumentImpl, InstrumentVtbl, tmpEntry->pInstrument, pInstrument); ICOM_NAME_MULTI (IDirectMusicInstrumentImpl, InstrumentVtbl, tmpEntry->pInstrument, pInstrument);
IDirectMusicInstrument_GetPatch (tmpEntry->pInstrument, pdwPatch); IDirectMusicInstrument_GetPatch (tmpEntry->pInstrument, pdwPatch);
dwNameLen = strlenW (pInstrument->wszName); if (pwszName) {
strncpyW (pwszName, pInstrument->wszName, dwNameLen); dwLen = min(strlenW(pInstrument->wszName),dwNameLen-1);
memcpy (pwszName, pInstrument->wszName, dwLen * sizeof(WCHAR));
pwszName[dwLen] = '\0';
}
return S_OK; return S_OK;
} }
r++; r++;
...@@ -190,11 +194,11 @@ HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor (LPDI ...@@ -190,11 +194,11 @@ HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor (LPDI
if (pDesc->dwValidData & DMUS_OBJ_CLASS) if (pDesc->dwValidData & DMUS_OBJ_CLASS)
memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
if (pDesc->dwValidData & DMUS_OBJ_NAME) if (pDesc->dwValidData & DMUS_OBJ_NAME)
strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME); lstrcpynW(This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); lstrcpynW(This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
if (pDesc->dwValidData & DMUS_OBJ_FILENAME) if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME); lstrcpynW(This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
if (pDesc->dwValidData & DMUS_OBJ_VERSION) if (pDesc->dwValidData & DMUS_OBJ_VERSION)
memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
if (pDesc->dwValidData & DMUS_OBJ_DATE) if (pDesc->dwValidData & DMUS_OBJ_DATE)
......
...@@ -293,9 +293,11 @@ static TDB *TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, LPCSTR cmdline, BYT ...@@ -293,9 +293,11 @@ static TDB *TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, LPCSTR cmdline, BYT
if (hModule) if (hModule)
{ {
char name[10]; char name[sizeof(pTask->module_name)+1];
size_t len;
GetModuleName16( hModule, name, sizeof(name) ); GetModuleName16( hModule, name, sizeof(name) );
strncpy( pTask->module_name, name, sizeof(pTask->module_name) ); len = strlen(name) + 1;
memcpy(pTask->module_name, name, min(len,sizeof(pTask->module_name)));
pTask->compat_flags = GetProfileIntA( "Compatibility", name, 0 ); pTask->compat_flags = GetProfileIntA( "Compatibility", name, 0 );
} }
......
...@@ -1399,21 +1399,19 @@ static BOOL unpad_data(CONST BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWOR ...@@ -1399,21 +1399,19 @@ static BOOL unpad_data(CONST BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWOR
BOOL WINAPI RSAENH_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer, BOOL WINAPI RSAENH_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer,
DWORD dwFlags, PVTableProvStruc pVTable) DWORD dwFlags, PVTableProvStruc pVTable)
{ {
DWORD dwLen; CHAR szKeyContainerName[MAX_PATH];
CHAR szKeyContainerName[MAX_PATH] = "";
CHAR szRegKey[MAX_PATH]; CHAR szRegKey[MAX_PATH];
TRACE("(phProv=%p, pszContainer=%s, dwFlags=%08lx, pVTable=%p)\n", phProv, TRACE("(phProv=%p, pszContainer=%s, dwFlags=%08lx, pVTable=%p)\n", phProv,
debugstr_a(pszContainer), dwFlags, pVTable); debugstr_a(pszContainer), dwFlags, pVTable);
if (pszContainer ? strlen(pszContainer) : 0) if (pszContainer && *pszContainer)
{ {
strncpy(szKeyContainerName, pszContainer, MAX_PATH); lstrcpynA(szKeyContainerName, pszContainer, MAX_PATH);
szKeyContainerName[MAX_PATH-1] = '\0';
} }
else else
{ {
dwLen = MAX_PATH; DWORD dwLen = sizeof(szKeyContainerName);
if (!GetUserNameA(szKeyContainerName, &dwLen)) return FALSE; if (!GetUserNameA(szKeyContainerName, &dwLen)) return FALSE;
} }
......
...@@ -2774,7 +2774,7 @@ int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPat ...@@ -2774,7 +2774,7 @@ int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPat
* dx [I] Desired width * dx [I] Desired width
* *
* RETURNS * RETURNS
* TRUE If the path was modified. * TRUE If the path was modified/went well.
* FALSE Otherwise. * FALSE Otherwise.
*/ */
BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx) BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
...@@ -2810,7 +2810,7 @@ BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx) ...@@ -2810,7 +2810,7 @@ BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx); TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
if (!lpszPath) if (!lpszPath)
return bRet; return FALSE;
if (!hDC) if (!hDC)
hdc = hDC = GetDC(0); hdc = hDC = GetDC(0);
...@@ -2887,7 +2887,7 @@ BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx) ...@@ -2887,7 +2887,7 @@ BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
if (dwLen > MAX_PATH - 3) if (dwLen > MAX_PATH - 3)
dwLen = MAX_PATH - 3; dwLen = MAX_PATH - 3;
strncpyW(buff, sFile, dwLen); lstrcpynW(buff, sFile, dwLen);
do { do {
dwLen--; dwLen--;
......
...@@ -720,7 +720,7 @@ HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative, ...@@ -720,7 +720,7 @@ HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative,
* Return the pszBase scheme with pszRelative. Basically * Return the pszBase scheme with pszRelative. Basically
* keeps the scheme and replaces the domain and following. * keeps the scheme and replaces the domain and following.
*/ */
strncpyW(preliminary, base.pszProtocol, base.cchProtocol + 1); memcpy(preliminary, base.pszProtocol, (base.cchProtocol + 1)*sizeof(WCHAR));
work = preliminary + base.cchProtocol + 1; work = preliminary + base.cchProtocol + 1;
strcpyW(work, relative.pszSuffix); strcpyW(work, relative.pszSuffix);
if (!(dwFlags & URL_PLUGGABLE_PROTOCOL) && if (!(dwFlags & URL_PLUGGABLE_PROTOCOL) &&
...@@ -733,7 +733,7 @@ HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative, ...@@ -733,7 +733,7 @@ HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative,
* after the location is pszRelative. (Replace document * after the location is pszRelative. (Replace document
* from root on.) * from root on.)
*/ */
strncpyW(preliminary, base.pszProtocol, base.cchProtocol+1+sizeloc); memcpy(preliminary, base.pszProtocol, (base.cchProtocol+1+sizeloc)*sizeof(WCHAR));
work = preliminary + base.cchProtocol + 1 + sizeloc; work = preliminary + base.cchProtocol + 1 + sizeloc;
if (dwFlags & URL_PLUGGABLE_PROTOCOL) if (dwFlags & URL_PLUGGABLE_PROTOCOL)
*(work++) = L'/'; *(work++) = L'/';
...@@ -744,7 +744,8 @@ HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative, ...@@ -744,7 +744,8 @@ HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative,
* Return the pszBase without its document (if any) and * Return the pszBase without its document (if any) and
* append pszRelative after its scheme. * append pszRelative after its scheme.
*/ */
strncpyW(preliminary, base.pszProtocol, base.cchProtocol+1+base.cchSuffix); memcpy(preliminary, base.pszProtocol,
(base.cchProtocol+1+base.cchSuffix)*sizeof(WCHAR));
work = preliminary + base.cchProtocol+1+base.cchSuffix - 1; work = preliminary + base.cchProtocol+1+base.cchSuffix - 1;
if (*work++ != L'/') if (*work++ != L'/')
*(work++) = L'/'; *(work++) = L'/';
...@@ -1951,7 +1952,9 @@ static LONG URL_ParseUrl(LPCWSTR pszUrl, WINE_PARSE_URL *pl) ...@@ -1951,7 +1952,9 @@ static LONG URL_ParseUrl(LPCWSTR pszUrl, WINE_PARSE_URL *pl)
* PARAMS * PARAMS
* pszIn [I] Url to parse * pszIn [I] Url to parse
* pszOut [O] Destination for part of pszIn requested * pszOut [O] Destination for part of pszIn requested
* pcchOut [I/O] Length of pszOut/destination for length of pszOut * pcchOut [I] Size of pszOut
* [O] length of pszOut string EXLUDING '\0' if S_OK, otherwise
* needed size of pszOut INCLUDING '\0'.
* dwPart [I] URL_PART_ enum from "shlwapi.h" * dwPart [I] URL_PART_ enum from "shlwapi.h"
* dwFlags [I] URL_ flags from "shlwapi.h" * dwFlags [I] URL_ flags from "shlwapi.h"
* *
...@@ -2003,7 +2006,6 @@ HRESULT WINAPI UrlGetPartW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut, ...@@ -2003,7 +2006,6 @@ HRESULT WINAPI UrlGetPartW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut,
HRESULT ret; HRESULT ret;
DWORD size, schsize; DWORD size, schsize;
LPCWSTR addr, schaddr; LPCWSTR addr, schaddr;
LPWSTR work;
TRACE("(%s %p %p(%ld) %08lx %08lx)\n", TRACE("(%s %p %p(%ld) %08lx %08lx)\n",
debugstr_w(pszIn), pszOut, pcchOut, *pcchOut, dwPart, dwFlags); debugstr_w(pszIn), pszOut, pcchOut, *pcchOut, dwPart, dwFlags);
...@@ -2055,24 +2057,21 @@ HRESULT WINAPI UrlGetPartW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut, ...@@ -2055,24 +2057,21 @@ HRESULT WINAPI UrlGetPartW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut,
} }
if (dwFlags == URL_PARTFLAG_KEEPSCHEME) { if (dwFlags == URL_PARTFLAG_KEEPSCHEME) {
if (*pcchOut < size + schsize + 2) { if (*pcchOut < schsize + size + 2) {
*pcchOut = size + schsize + 2; *pcchOut = schsize + size + 2;
return E_POINTER; return E_POINTER;
} }
strncpyW(pszOut, schaddr, schsize); memcpy(pszOut, schaddr, schsize*sizeof(WCHAR));
work = pszOut + schsize; pszOut[schsize] = ':';
*work = L':'; memcpy(pszOut+schsize+1, addr, size*sizeof(WCHAR));
strncpyW(work+1, addr, size); pszOut[schsize+1+size] = 0;
*pcchOut = size + schsize + 1; *pcchOut = schsize + 1 + size;
work += (size + 1);
*work = L'\0';
} }
else { else {
if (*pcchOut < size + 1) {*pcchOut = size+1; return E_POINTER;} if (*pcchOut < size + 1) {*pcchOut = size+1; return E_POINTER;}
strncpyW(pszOut, addr, size); memcpy(pszOut, addr, size*sizeof(WCHAR));
pszOut[size] = 0;
*pcchOut = size; *pcchOut = size;
work = pszOut + size;
*work = L'\0';
} }
TRACE("len=%ld %s\n", *pcchOut, debugstr_w(pszOut)); TRACE("len=%ld %s\n", *pcchOut, debugstr_w(pszOut));
} }
......
...@@ -563,10 +563,11 @@ DWORD DOSDEV_FindCharDevice(char*name) ...@@ -563,10 +563,11 @@ DWORD DOSDEV_FindCharDevice(char*name)
int cnt; int cnt;
/* get first 8 characters */ /* get first 8 characters */
strncpy(dname,name,8);
/* if less than 8 characters, pad with spaces */ /* if less than 8 characters, pad with spaces */
for (cnt=0; cnt<8; cnt++) for (cnt=0; name[cnt] && cnt<8; cnt++)
if (!dname[cnt]) dname[cnt]=' '; dname[cnt]=name[cnt];
while(cnt<8) dname[cnt++] = ' ';
/* search for char devices with the right name */ /* search for char devices with the right name */
while (cur && while (cur &&
......
...@@ -670,22 +670,25 @@ static BOOL URLCache_LocalFileNameToPathA( ...@@ -670,22 +670,25 @@ static BOOL URLCache_LocalFileNameToPathA(
LPLONG lpBufferSize) LPLONG lpBufferSize)
{ {
LONG nRequired; LONG nRequired;
int path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL); int path_len, file_name_len, dir_len;
int file_name_len = strlen(szLocalFileName);
int dir_len = DIR_LENGTH;
if (Directory >= pHeader->DirectoryCount) if (Directory >= pHeader->DirectoryCount)
{ {
*lpBufferSize = 0; *lpBufferSize = 0;
return FALSE; return FALSE;
} }
nRequired = (path_len + dir_len + file_name_len + 1) * sizeof(WCHAR); path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL);
file_name_len = strlen(szLocalFileName);
dir_len = DIR_LENGTH;
nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(WCHAR);
if (nRequired < *lpBufferSize) if (nRequired < *lpBufferSize)
{ {
WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, -1, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, -1, NULL, NULL);
strncpy(szPath, pHeader->directory_data[Directory].filename, DIR_LENGTH); memcpy(szPath+path_len, pHeader->directory_data[Directory].filename, dir_len);
szPath[dir_len + path_len] = '\\'; szPath[path_len + dir_len] = '\\';
strcpy(szPath + dir_len + path_len + 1, szLocalFileName); memcpy(szPath + path_len + dir_len + 1, szLocalFileName, file_name_len);
*lpBufferSize = nRequired; *lpBufferSize = nRequired;
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment