From 6e3bcb5a54f5b854ab679c2822eec3eff4fbf741 Mon Sep 17 00:00:00 2001 From: Peter Berg Larsen Date: Mon, 18 Apr 2005 10:30:55 +0000 Subject: [PATCH] Replace strncpy with memcpy or lstrcpyn. --- dlls/comctl32/tooltips.c | 2 +- dlls/commdlg/filedlg.c | 2 +- dlls/devenum/parsedisplayname.c | 8 +++++--- dlls/dmband/band.c | 6 +++--- dlls/dmcompos/chordmap.c | 6 +++--- dlls/dmime/audiopath.c | 6 +++--- dlls/dmime/graph.c | 6 +++--- dlls/dmime/segment.c | 6 +++--- dlls/dmloader/loaderstream.c | 2 +- dlls/dmscript/script.c | 6 +++--- dlls/dmstyle/style.c | 6 +++--- dlls/gdi/font.c | 2 +- dlls/gdi/freetype.c | 10 +++++----- dlls/itss/chm_lib.c | 2 +- dlls/msi/cond.y | 2 +- dlls/msvcrt/locale.c | 14 +++++++------- dlls/msvideo/mciwnd.c | 4 ++-- dlls/msvideo/msvideo16.c | 8 +++++--- dlls/oledlg/insobjdlg.c | 2 +- dlls/quartz/filtermapper.c | 2 +- dlls/shell32/debughlp.c | 4 ++-- dlls/shell32/shelllink.c | 2 +- dlls/shell32/shellpath.c | 10 +++++----- dlls/shell32/shlexec.c | 4 ++-- dlls/shell32/systray.c | 3 +-- dlls/user/edit.c | 14 ++++++++------ dlls/winedos/int21.c | 2 +- dlls/wininet/dialogs.c | 2 +- dlls/wininet/internet.c | 9 ++++++++- dlls/wininet/utility.c | 1 + dlls/winmm/wineoss/audio.c | 2 +- programs/winecfg/drivedetect.c | 2 +- tools/sfnt2fnt.c | 7 ++++--- 33 files changed, 89 insertions(+), 75 deletions(-) diff --git a/dlls/comctl32/tooltips.c b/dlls/comctl32/tooltips.c index c59a7d2a74f..80073d47935 100644 --- a/dlls/comctl32/tooltips.c +++ b/dlls/comctl32/tooltips.c @@ -387,7 +387,7 @@ static void TOOLTIPS_GetDispInfoW(HWND hwnd, TOOLTIPS_INFO *infoPtr, TTTOOL_INFO else if (ttnmdi.lpszText != LPSTR_TEXTCALLBACKW) { INT max_len = (ttnmdi.lpszText == &ttnmdi.szText[0]) ? sizeof(ttnmdi.szText)/sizeof(ttnmdi.szText[0]) : INFOTIPSIZE-1; - strncpyW(infoPtr->szTipText, ttnmdi.lpszText, max_len); + lstrcpynW(infoPtr->szTipText, ttnmdi.lpszText, max_len); if (ttnmdi.uFlags & TTF_DI_SETITEM) { INT len = max(strlenW(ttnmdi.lpszText), max_len); toolPtr->hinst = 0; diff --git a/dlls/commdlg/filedlg.c b/dlls/commdlg/filedlg.c index a2c13a9fc7d..524d27262c7 100644 --- a/dlls/commdlg/filedlg.c +++ b/dlls/commdlg/filedlg.c @@ -2065,7 +2065,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) if(fodInfos->unicode) { LPOPENFILENAMEW ofn = fodInfos->ofnInfos; - strncpyW(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle); + lstrcpynW(ofn->lpstrFileTitle, lpstrFileTitle, ofn->nMaxFileTitle); } else { diff --git a/dlls/devenum/parsedisplayname.c b/dlls/devenum/parsedisplayname.c index f1b8505f10f..47782102ecd 100644 --- a/dlls/devenum/parsedisplayname.c +++ b/dlls/devenum/parsedisplayname.c @@ -94,6 +94,7 @@ static HRESULT WINAPI DEVENUM_IParseDisplayName_ParseDisplayName( MediaCatMoniker * pMoniker = NULL; CLSID clsidDevice; HRESULT res = S_OK; + int classlen; TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut); @@ -107,12 +108,13 @@ static HRESULT WINAPI DEVENUM_IParseDisplayName_ParseDisplayName( /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID) * + 1 (for NULL character) */ - pszClass = CoTaskMemAlloc((int)(pszBetween - pszDisplayName) * sizeof(WCHAR)); + classlen = (int)(pszBetween - pszDisplayName - 1); + pszClass = CoTaskMemAlloc((classlen + 1) * sizeof(WCHAR)); if (!pszClass) return E_OUTOFMEMORY; - strncpyW(pszClass, pszDisplayName, (int)(pszBetween - pszDisplayName) - 1); - pszClass[(int)(pszBetween - pszDisplayName) - 1] = 0; + memcpy(pszClass, pszDisplayName, classlen * sizeof(WCHAR)); + pszClass[classlen] = 0; TRACE("Device CLSID: %s\n", debugstr_w(pszClass)); diff --git a/dlls/dmband/band.c b/dlls/dmband/band.c index 122a70dae03..e14a4133382 100644 --- a/dlls/dmband/band.c +++ b/dlls/dmband/band.c @@ -163,11 +163,11 @@ HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMU if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/dmcompos/chordmap.c b/dlls/dmcompos/chordmap.c index 0e390e3c8be..be754e91576 100644 --- a/dlls/dmcompos/chordmap.c +++ b/dlls/dmcompos/chordmap.c @@ -147,11 +147,11 @@ HRESULT WINAPI IDirectMusicChordMapImpl_IDirectMusicObject_SetDescriptor (LPDIRE if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/dmime/audiopath.c b/dlls/dmime/audiopath.c index 6256ed63128..43fae8e8e55 100644 --- a/dlls/dmime/audiopath.c +++ b/dlls/dmime/audiopath.c @@ -262,11 +262,11 @@ HRESULT WINAPI IDirectMusicAudioPathImpl_IDirectMusicObject_SetDescriptor (LPDIR if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/dmime/graph.c b/dlls/dmime/graph.c index ea45f7a3529..2049c312003 100644 --- a/dlls/dmime/graph.c +++ b/dlls/dmime/graph.c @@ -228,11 +228,11 @@ HRESULT WINAPI IDirectMusicGraphImpl_IDirectMusicObject_SetDescriptor (LPDIRECTM if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/dmime/segment.c b/dlls/dmime/segment.c index 118238ffd76..b80410411b2 100644 --- a/dlls/dmime/segment.c +++ b/dlls/dmime/segment.c @@ -548,11 +548,11 @@ HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRE if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index 3ecc7eab5a6..062bb2619be 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -67,7 +67,7 @@ HRESULT WINAPI IDirectMusicLoaderFileStream_Attach (LPSTREAM iface, LPCWSTR wzFi } /* create IDirectMusicGetLoader */ This->pLoader = (LPDIRECTMUSICLOADER8)pLoader; - strncpyW (This->wzFileName, wzFile, MAX_PATH); + lstrcpynW (This->wzFileName, wzFile, MAX_PATH); TRACE(": succeeded\n"); return S_OK; } diff --git a/dlls/dmscript/script.c b/dlls/dmscript/script.c index 79c7b316eb3..58a3502cd0d 100644 --- a/dlls/dmscript/script.c +++ b/dlls/dmscript/script.c @@ -226,11 +226,11 @@ HRESULT WINAPI IDirectMusicScriptImpl_IDirectMusicObject_SetDescriptor (LPDIRECT if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/dmstyle/style.c b/dlls/dmstyle/style.c index cfba90a0bd2..da4cbd9f0cd 100644 --- a/dlls/dmstyle/style.c +++ b/dlls/dmstyle/style.c @@ -230,11 +230,11 @@ HRESULT WINAPI IDirectMusicStyle8Impl_IDirectMusicObject_SetDescriptor (LPDIRECT if (pDesc->dwValidData & DMUS_OBJ_CLASS) memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass)); 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) - strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); + lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY); 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) memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion)); if (pDesc->dwValidData & DMUS_OBJ_DATE) diff --git a/dlls/gdi/font.c b/dlls/gdi/font.c index d4e5dfac56c..f1a175f1268 100644 --- a/dlls/gdi/font.c +++ b/dlls/gdi/font.c @@ -2319,7 +2319,7 @@ GetCharacterPlacementW( /* 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) - strncpyW( lpResults->lpOutString, lpString, nSet ); + memcpy( lpResults->lpOutString, lpString, nSet * sizeof(WCHAR)); if(lpResults->lpOrder) { diff --git a/dlls/gdi/freetype.c b/dlls/gdi/freetype.c index 02509e54872..1d0f2ea3354 100644 --- a/dlls/gdi/freetype.c +++ b/dlls/gdi/freetype.c @@ -2044,13 +2044,13 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf, if(potm) { pntm->ntmTm.ntmSizeEM = potm->otmEMSquare; - strncpyW(pelf->elfLogFont.lfFaceName, + lstrcpynW(pelf->elfLogFont.lfFaceName, (WCHAR*)((char*)potm + (ptrdiff_t)potm->otmpFamilyName), LF_FACESIZE); - strncpyW(pelf->elfFullName, + lstrcpynW(pelf->elfFullName, (WCHAR*)((char*)potm + (ptrdiff_t)potm->otmpFaceName), LF_FULLFACESIZE); - strncpyW(pelf->elfStyle, + lstrcpynW(pelf->elfStyle, (WCHAR*)((char*)potm + (ptrdiff_t)potm->otmpStyleName), LF_FACESIZE); @@ -2058,8 +2058,8 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf, } else { pntm->ntmTm.ntmSizeEM = pntm->ntmTm.tmHeight - pntm->ntmTm.tmInternalLeading; - strncpyW(pelf->elfLogFont.lfFaceName, face->family->FamilyName, LF_FACESIZE); - strncpyW(pelf->elfFullName, face->family->FamilyName, LF_FACESIZE); + lstrcpynW(pelf->elfLogFont.lfFaceName, face->family->FamilyName, LF_FACESIZE); + lstrcpynW(pelf->elfFullName, face->family->FamilyName, LF_FACESIZE); pelf->elfStyle[0] = '\0'; } diff --git a/dlls/itss/chm_lib.c b/dlls/itss/chm_lib.c index 206924ab1c7..3eef05d6d88 100644 --- a/dlls/itss/chm_lib.c +++ b/dlls/itss/chm_lib.c @@ -1538,7 +1538,7 @@ int chm_enumerate_dir(struct chmFile *h, curPage = h->index_head; /* initialize pathname state */ - strncpyW(prefixRectified, prefix, CHM_MAX_PATHLEN); + lstrcpynW(prefixRectified, prefix, CHM_MAX_PATHLEN); prefixLen = strlenW(prefixRectified); if (prefixLen != 0) { diff --git a/dlls/msi/cond.y b/dlls/msi/cond.y index f6c731474de..4a7f46d86ed 100644 --- a/dlls/msi/cond.y +++ b/dlls/msi/cond.y @@ -701,7 +701,7 @@ static LPWSTR COND_GetString( struct cond_str *str ) ret = HeapAlloc( GetProcessHeap(), 0, (str->len+1) * sizeof (WCHAR) ); if( ret ) { - strncpyW( ret, str->data, str->len ); + memcpy( ret, str->data, str->len * sizeof(WCHAR)); ret[str->len]=0; } TRACE("Got identifier %s\n",debugstr_w(ret)); diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 33b39ce3ccf..3ae68ecd5b8 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -372,7 +372,7 @@ char* MSVCRT_setlocale(int category, const char* locale) if (next && next != locale) { haveLang = 1; - strncpy(lc.search_language,locale,next-locale); + memcpy(lc.search_language,locale,next-locale); locale += next-locale+1; } @@ -383,23 +383,23 @@ char* MSVCRT_setlocale(int category, const char* locale) if (next == locale) { locale++; - strncpy(lc.search_codepage, locale, MAX_ELEM_LEN); + lstrcpynA(lc.search_codepage, locale, MAX_ELEM_LEN); } else { if (haveLang) { haveCountry = 1; - strncpy(lc.search_country,locale,next-locale); + memcpy(lc.search_country,locale,next-locale); locale += next-locale+1; } else { haveLang = 1; - strncpy(lc.search_language,locale,next-locale); + memcpy(lc.search_language,locale,next-locale); locale += next-locale+1; } - strncpy(lc.search_codepage, locale, MAX_ELEM_LEN); + lstrcpynA(lc.search_codepage, locale, MAX_ELEM_LEN); } } else @@ -407,12 +407,12 @@ char* MSVCRT_setlocale(int category, const char* locale) if (haveLang) { haveCountry = 1; - strncpy(lc.search_country, locale, MAX_ELEM_LEN); + lstrcpynA(lc.search_country, locale, MAX_ELEM_LEN); } else { haveLang = 1; - strncpy(lc.search_language, locale, MAX_ELEM_LEN); + lstrcpynA(lc.search_language, locale, MAX_ELEM_LEN); } } diff --git a/dlls/msvideo/mciwnd.c b/dlls/msvideo/mciwnd.c index eb8d376a4f1..cf52beb19dc 100644 --- a/dlls/msvideo/mciwnd.c +++ b/dlls/msvideo/mciwnd.c @@ -1010,7 +1010,7 @@ end_of_mci_open: return mwi->lasterror; case MCIWNDM_RETURNSTRINGW: - strncpyW((LPWSTR)lParam, mwi->return_string, wParam); + lstrcpynW((LPWSTR)lParam, mwi->return_string, wParam); TRACE("MCIWNDM_RETURNTRINGW %s\n", debugstr_wn((LPWSTR)lParam, wParam)); return mwi->lasterror; @@ -1095,7 +1095,7 @@ end_of_mci_open: case MCIWNDM_GETFILENAMEW: TRACE("MCIWNDM_GETFILENAMEW: %s\n", debugstr_w(mwi->lpName)); if (mwi->lpName) - strncpyW((LPWSTR)lParam, mwi->lpName, wParam); + lstrcpynW((LPWSTR)lParam, mwi->lpName, wParam); return 0; case MCIWNDM_GETTIMEFORMATA: diff --git a/dlls/msvideo/msvideo16.c b/dlls/msvideo/msvideo16.c index fa3b11adcf2..67fe006224a 100644 --- a/dlls/msvideo/msvideo16.c +++ b/dlls/msvideo/msvideo16.c @@ -834,7 +834,7 @@ DWORD WINAPI VideoCapDriverDescAndVer16(WORD nr, LPSTR buf1, WORD buf1len, else { TRACE("GetFileVersionInfoA failed for %s.\n", fn); - strncpy(buf2, fn, buf2len); /* msvideo.dll appears to copy fn*/ + lstrcpynA(buf2, fn, buf2len); /* msvideo.dll appears to copy fn*/ } /* FIXME: language problem? */ if (VerQueryValueA( infobuf, @@ -843,13 +843,15 @@ DWORD WINAPI VideoCapDriverDescAndVer16(WORD nr, LPSTR buf1, WORD buf1len, &subblocklen )) { + UINT copylen = min(subblocklen,buf1len-1); + memcpy(buf1, subblock, copylen); + buf1[copylen] = '\0'; TRACE("VQA returned %s\n", (LPCSTR)subblock); - strncpy(buf1, subblock, buf1len); } else { TRACE("VQA did not return on query \\StringFileInfo\\040904E4\\FileDescription?\n"); - strncpy(buf1, fn, buf1len); /* msvideo.dll appears to copy fn*/ + lstrcpynA(buf1, fn, buf1len); /* msvideo.dll appears to copy fn*/ } HeapFree(GetProcessHeap(), 0, infobuf); return 0; diff --git a/dlls/oledlg/insobjdlg.c b/dlls/oledlg/insobjdlg.c index 2210fea4215..88259264ea1 100644 --- a/dlls/oledlg/insobjdlg.c +++ b/dlls/oledlg/insobjdlg.c @@ -479,7 +479,7 @@ static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo) WCHAR wcsFile[MAX_PATH]; SendMessageA(pdlgInfo->hwndFileTB, WM_GETTEXT, (WPARAM)MAX_PATH, (LPARAM)fname); - strncpy(pdlgInfo->lpOleUIInsertObject->lpszFile, fname, pdlgInfo->lpOleUIInsertObject->cchFile); + lstrcpynA(pdlgInfo->lpOleUIInsertObject->lpszFile, fname, pdlgInfo->lpOleUIInsertObject->cchFile); RtlMultiByteToUnicodeN(wcsFile, MAX_PATH, NULL, fname, MAX_PATH); if (ERROR_SUCCESS == (hres = GetClassFile(wcsFile, &pdlgInfo->lpOleUIInsertObject->clsid))) diff --git a/dlls/quartz/filtermapper.c b/dlls/quartz/filtermapper.c index 07b914a9b60..3d938e819f0 100644 --- a/dlls/quartz/filtermapper.c +++ b/dlls/quartz/filtermapper.c @@ -732,7 +732,7 @@ static HRESULT WINAPI FilterMapper2_RegisterFilter( if (SUCCEEDED(hr)) { - strncpyW(pCurrent, szClsidTemp, CHARS_IN_GUID); + memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR)); pCurrent += CHARS_IN_GUID - 1; pCurrent[0] = '\\'; diff --git a/dlls/shell32/debughlp.c b/dlls/shell32/debughlp.c index 6857cdcbb6d..2282f6c9418 100644 --- a/dlls/shell32/debughlp.c +++ b/dlls/shell32/debughlp.c @@ -159,13 +159,13 @@ DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize) if (_dbg_ILIsDesktop(pidl)) { /* desktop */ - if (szOut) strncpy(szOut, "Desktop", uOutSize); + if (szOut) lstrcpynA(szOut, "Desktop", uOutSize); dwReturn = strlen ("Desktop"); } else if (( szSrc = _dbg_ILGetTextPointer(pidl) )) { /* filesystem */ - if (szOut) strncpy(szOut, szSrc, uOutSize); + if (szOut) lstrcpynA(szOut, szSrc, uOutSize); dwReturn = strlen(szSrc); } else if (( riid = _dbg_ILGetGUIDPointer(pidl) )) diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c index 12e2054b7d5..aa84d92a0f6 100644 --- a/dlls/shell32/shelllink.c +++ b/dlls/shell32/shelllink.c @@ -909,7 +909,7 @@ static HRESULT Stream_WriteAdvertiseInfo( IStream* stm, LPCWSTR string, DWORD ma memset( &buffer, 0, sizeof buffer ); buffer.dbh.cbSize = sizeof buffer; buffer.dbh.dwSignature = magic; - strncpyW( buffer.szwDarwinID, string, MAX_PATH ); + lstrcpynW( buffer.szwDarwinID, string, MAX_PATH ); WideCharToMultiByte(CP_ACP, 0, string, -1, buffer.szDarwinID, MAX_PATH, NULL, NULL ); return IStream_Write( stm, &buffer, buffer.dbh.cbSize, &count ); diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index ac7725e6261..ff989675c6e 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -1210,7 +1210,7 @@ static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix, WCHAR szTemp[MAX_PATH]; _SHExpandEnvironmentStrings(path, szTemp); - strncpyW(path, szTemp, MAX_PATH); + lstrcpynW(path, szTemp, MAX_PATH); } ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR)); @@ -1493,12 +1493,12 @@ static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName, else { /* Missing or invalid value, set a default */ - strncpyW(szValue, szDefault, MAX_PATH); - szValue[MAX_PATH - 1] = '\0'; + lstrcpynW(szValue, szDefault, MAX_PATH); TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName), - debugstr_w(szValue)); + debugstr_w(szValue)); lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ, - (LPBYTE)szValue, (strlenW(szValue) + 1) * sizeof(WCHAR)); + (LPBYTE)szValue, + (strlenW(szValue) + 1) * sizeof(WCHAR)); if (lRet) hr = HRESULT_FROM_WIN32(lRet); else diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c index f04828a65ce..cf3b4db9aaf 100644 --- a/dlls/shell32/shlexec.c +++ b/dlls/shell32/shlexec.c @@ -1218,7 +1218,7 @@ BOOL WINAPI ShellExecuteExW32 (LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfun LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/; for(s=beg; (space=strchrW(s, ' ')); s=space+1) { int idx = space-sei_tmp.lpFile; - strncpyW(buffer, sei_tmp.lpFile, idx); + memcpy(buffer, sei_tmp.lpFile, idx * sizeof(WCHAR)); buffer[idx] = '\0'; /*FIXME This finds directory paths if the targeted file name contains spaces. */ @@ -1296,7 +1296,7 @@ BOOL WINAPI ShellExecuteExW32 (LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfun TRACE("Got URL: %s\n", debugstr_w(lpFile)); /* Looking for ...protocol\shell\lpOperation\command */ - strncpyW(lpstrProtocol, lpFile, iSize); + memcpy(lpstrProtocol, lpFile, iSize*sizeof(WCHAR)); lpstrProtocol[iSize] = '\0'; strcatW(lpstrProtocol, wShell); strcatW(lpstrProtocol, sei_tmp.lpVerb? sei_tmp.lpVerb: wszOpen); diff --git a/dlls/shell32/systray.c b/dlls/shell32/systray.c index 1568289a4ad..714ef7727b1 100644 --- a/dlls/shell32/systray.c +++ b/dlls/shell32/systray.c @@ -256,8 +256,7 @@ void SYSTRAY_ItemSetTip(SystrayItem *ptrayItem, CHAR* szTip, int modify) { TTTOOLINFOA ti; - strncpy(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip)); - ptrayItem->notifyIcon.szTip[sizeof(ptrayItem->notifyIcon.szTip)-1]=0; + lstrcpynA(ptrayItem->notifyIcon.szTip, szTip, sizeof(ptrayItem->notifyIcon.szTip)); ti.cbSize = sizeof(TTTOOLINFOA); ti.uFlags = 0; diff --git a/dlls/user/edit.c b/dlls/user/edit.c index 3e71ea3d023..22f4bb39628 100644 --- a/dlls/user/edit.c +++ b/dlls/user/edit.c @@ -3052,7 +3052,7 @@ static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replac bufl = e - s; buf = HeapAlloc(GetProcessHeap(), 0, (bufl + 1) * sizeof(WCHAR)); if (!buf) return; - strncpyW(buf, es->text + s, bufl); + memcpy(buf, es->text + s, bufl * sizeof(WCHAR)); buf[bufl] = 0; /* ensure 0 termination */ /* now delete */ strcpyW(es->text + s, es->text + e); @@ -3113,7 +3113,7 @@ static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replac if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) { /* undo-buffer is extended to the right */ EDIT_MakeUndoFit(es, utl + e - s); - strncpyW(es->undo_text + utl, buf, e - s + 1); + memcpy(es->undo_text + utl, buf, (e - s)*sizeof(WCHAR)); (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */ } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) { /* undo-buffer is extended to the left */ @@ -3126,7 +3126,7 @@ static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replac } else { /* new undo-buffer */ EDIT_MakeUndoFit(es, e - s); - strncpyW(es->undo_text, buf, e - s + 1); + memcpy(es->undo_text, buf, (e - s)*sizeof(WCHAR)); es->undo_text[e - s] = 0; /* ensure 0 termination */ es->undo_position = s; } @@ -3932,13 +3932,15 @@ static void EDIT_WM_Copy(EDITSTATE *es) INT e = max(es->selection_start, es->selection_end); HGLOBAL hdst; LPWSTR dst; + DWORD len; if (e == s) return; - hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR)); + len = e - s; + hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (len + 1) * sizeof(WCHAR)); dst = GlobalLock(hdst); - strncpyW(dst, es->text + s, e - s); - dst[e - s] = 0; /* ensure 0 termination */ + memcpy(dst, es->text + s, len * sizeof(WCHAR)); + dst[len] = 0; /* ensure 0 termination */ TRACE("%s\n", debugstr_w(dst)); GlobalUnlock(hdst); OpenClipboard(es->hwndSelf); diff --git a/dlls/winedos/int21.c b/dlls/winedos/int21.c index c22af6b56f5..8b53ece107e 100644 --- a/dlls/winedos/int21.c +++ b/dlls/winedos/int21.c @@ -3434,7 +3434,7 @@ static int INT21_GetDiskSerialNumber( CONTEXT86 *context ) *(WORD *)dataptr = 0; memcpy(dataptr + 2, &serial, sizeof(DWORD)); WideCharToMultiByte(CP_OEMCP, 0, label, 11, dataptr + 6, 11, NULL, NULL); - strncpy(dataptr + 17, "FAT16 ", 8); + memcpy(dataptr + 17, "FAT16 ", 8); return 1; } diff --git a/dlls/wininet/dialogs.c b/dlls/wininet/dialogs.c index 5f9df126621..7fc6207e2b2 100644 --- a/dlls/wininet/dialogs.c +++ b/dlls/wininet/dialogs.c @@ -76,7 +76,7 @@ static BOOL WININET_GetProxyServer( HINTERNET hRequest, LPWSTR szBuf, DWORD sz ) if (NULL == hIC) return FALSE; - strncpyW(szBuf, hIC->lpszProxy, sz); + lstrcpynW(szBuf, hIC->lpszProxy, sz); /* FIXME: perhaps it would be better to use InternetCrackUrl here */ p = strchrW(szBuf, ':'); diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 950cb0e96ce..32d584f6db7 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -1195,6 +1195,13 @@ static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp) * * Helper function for InternetCrackUrlW * + * PARAMS + * lppszComponent [O] Holds the returned string + * dwComponentLen [I] Holds the size of lppszComponent + * [O] Holds the length of the string in lppszComponent without '\0' + * lpszStart [I] Holds the string to copy from + * len [I] Holds the length of lpszStart without '\0' + * * RETURNS * TRUE on success * FALSE on failure @@ -1217,7 +1224,7 @@ static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen else { DWORD ncpylen = min((*dwComponentLen)-1, len); - strncpyW(*lppszComponent, lpszStart, ncpylen); + memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR)); (*lppszComponent)[ncpylen] = '\0'; *dwComponentLen = ncpylen; } diff --git a/dlls/wininet/utility.c b/dlls/wininet/utility.c index d76bed3c272..ea7cdf49c45 100644 --- a/dlls/wininet/utility.c +++ b/dlls/wininet/utility.c @@ -53,6 +53,7 @@ time_t ConvertTimeString(LPCWSTR asctime) if(!asctime || !timelen) return 0; + /* The atoiWs below relie on that tmpChar is \0 padded? */ strncpyW(tmpChar, asctime, TIME_STRING_LEN); /* Assert that the string is the expected length */ diff --git a/dlls/winmm/wineoss/audio.c b/dlls/winmm/wineoss/audio.c index e63cbb8c12d..5ffaa77a674 100644 --- a/dlls/winmm/wineoss/audio.c +++ b/dlls/winmm/wineoss/audio.c @@ -701,7 +701,7 @@ static BOOL OSS_WaveOutInit(OSS_DEVICE* ossdev) if ((mixer = open(ossdev->mixer_name, O_RDONLY|O_NDELAY)) >= 0) { mixer_info info; if (ioctl(mixer, SOUND_MIXER_INFO, &info) >= 0) { - strncpy(ossdev->ds_desc.szDesc, info.name, sizeof(info.name)); + lstrcpynA(ossdev->ds_desc.szDesc, info.name, sizeof(info.name)); strcpy(ossdev->ds_desc.szDrvname, "wineoss.drv"); MultiByteToWideChar(CP_ACP, 0, info.name, sizeof(info.name), ossdev->out_caps.szPname, diff --git a/programs/winecfg/drivedetect.c b/programs/winecfg/drivedetect.c index b3dabb4eac2..0058c07592b 100644 --- a/programs/winecfg/drivedetect.c +++ b/programs/winecfg/drivedetect.c @@ -310,7 +310,7 @@ int autodetect_drives() return FALSE; } - strncpy(label, "Drive X", 8); + strcpy(label, "Drive X"); label[6] = letter; WINE_TRACE("adding drive %c for %s, type %s with label %s\n", letter, ent->mnt_dir, ent->mnt_type,label); diff --git a/tools/sfnt2fnt.c b/tools/sfnt2fnt.c index eaa656a82b7..d3d912405d5 100644 --- a/tools/sfnt2fnt.c +++ b/tools/sfnt2fnt.c @@ -207,12 +207,13 @@ static void fill_fontinfo(FT_Face face, int enc, FILE *fp, int dpi, unsigned cha num_names = FT_Get_Sfnt_Name_Count(face); for(i = 0; i