diff --git a/dlls/ntdll/actctx.c b/dlls/ntdll/actctx.c index e0c280af5bc..f64cb31a1f0 100644 --- a/dlls/ntdll/actctx.c +++ b/dlls/ntdll/actctx.c @@ -1098,7 +1098,7 @@ static WCHAR *build_assembly_dir(struct assembly_identity* ai) wcscat( ret, undW ); wcscat( ret, key ); wcscat( ret, undW ); - NTDLL_swprintf( ret + wcslen(ret), version_formatW, + swprintf( ret + wcslen(ret), size - wcslen(ret), version_formatW, ai->version.major, ai->version.minor, ai->version.build, ai->version.revision ); wcscat( ret, undW ); wcscat( ret, lang ); @@ -1135,7 +1135,7 @@ static WCHAR *build_assembly_id( const struct assembly_identity *ai ) WCHAR version[64], *ret; SIZE_T size = 0; - NTDLL_swprintf( version, version_formatW, + swprintf( version, ARRAY_SIZE(version), version_formatW, ai->version.major, ai->version.minor, ai->version.build, ai->version.revision ); if (ai->name) size += wcslen(ai->name) * sizeof(WCHAR); if (ai->arch) size += wcslen(archW) + wcslen(ai->arch) + 2; @@ -1981,7 +1981,7 @@ static int get_assembly_version(struct assembly *assembly, WCHAR *ret) WCHAR buff[25]; if (!ret) ret = buff; - return NTDLL_swprintf(ret, fmtW, ver->major, ver->minor, ver->build, ver->revision); + return swprintf(ret, ARRAY_SIZE(buff), fmtW, ver->major, ver->minor, ver->build, ver->revision); } static void parse_window_class_elem( xmlbuf_t *xmlbuf, struct dll_redirect *dll, @@ -3091,7 +3091,7 @@ static NTSTATUS get_manifest_in_associated_manifest( struct actctx_loader* acl, if (!(status = get_module_filename( module, &name, sizeof(dotManifestW) + 10*sizeof(WCHAR) ))) { - if (resid != 1) NTDLL_swprintf( name.Buffer + wcslen(name.Buffer), fmtW, resid ); + if (resid != 1) swprintf( name.Buffer + wcslen(name.Buffer), 10, fmtW, resid ); wcscat( name.Buffer, dotManifestW ); if (!RtlDosPathNameToNtPathName_U( name.Buffer, &nameW, NULL, NULL )) status = STATUS_RESOURCE_DATA_NOT_FOUND; @@ -3105,7 +3105,7 @@ static NTSTATUS get_manifest_in_associated_manifest( struct actctx_loader* acl, (wcslen(filename) + 10) * sizeof(WCHAR) + sizeof(dotManifestW) ))) return STATUS_NO_MEMORY; wcscpy( buffer, filename ); - if (resid != 1) NTDLL_swprintf( buffer + wcslen(buffer), fmtW, resid ); + if (resid != 1) swprintf( buffer + wcslen(buffer), 10, fmtW, resid ); wcscat( buffer, dotManifestW ); RtlInitUnicodeString( &nameW, buffer ); } @@ -3131,17 +3131,14 @@ static WCHAR *lookup_manifest_file( HANDLE dir, struct assembly_identity *ai ) UNICODE_STRING lookup_us; IO_STATUS_BLOCK io; const WCHAR *lang = ai->language; - unsigned int data_pos = 0, data_len; + unsigned int data_pos = 0, data_len, len; char buffer[8192]; if (!lang || !wcsicmp( lang, neutralW )) lang = wildcardW; - if (!(lookup = RtlAllocateHeap( GetProcessHeap(), 0, - (wcslen(ai->arch) + wcslen(ai->name) - + wcslen(ai->public_key) + wcslen(lang) + 20) * sizeof(WCHAR) - + sizeof(lookup_fmtW) ))) - return NULL; - NTDLL_swprintf( lookup, lookup_fmtW, ai->arch, ai->name, ai->public_key, + len = wcslen(ai->arch) + wcslen(ai->name) + wcslen(ai->public_key) + wcslen(lang) + 20 + ARRAY_SIZE(lookup_fmtW); + if (!(lookup = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL; + swprintf( lookup, len, lookup_fmtW, ai->arch, ai->name, ai->public_key, ai->version.major, ai->version.minor, lang ); RtlInitUnicodeString( &lookup_us, lookup ); diff --git a/dlls/ntdll/atom.c b/dlls/ntdll/atom.c index de0565094c8..1daaa1627c3 100644 --- a/dlls/ntdll/atom.c +++ b/dlls/ntdll/atom.c @@ -106,7 +106,7 @@ static ULONG integral_atom_name(WCHAR* buffer, ULONG len, RTL_ATOM atom) WCHAR tmp[16]; int ret; - ret = NTDLL_swprintf( tmp, fmt, atom ); + ret = swprintf( tmp, ARRAY_SIZE(tmp), fmt, atom ); if (!len) return ret * sizeof(WCHAR); if (len <= ret) ret = len - 1; memcpy( buffer, tmp, ret * sizeof(WCHAR) ); diff --git a/dlls/ntdll/locale.c b/dlls/ntdll/locale.c index 651da46aa6e..26295f260e8 100644 --- a/dlls/ntdll/locale.c +++ b/dlls/ntdll/locale.c @@ -583,16 +583,16 @@ static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file ) break; case NLS_SECTION_CASEMAP: if (id) return STATUS_UNSUCCESSFUL; - NTDLL_swprintf( buffer, keyfmtW, langW ); - NTDLL_swprintf( value, langfmtW, LANGIDFROMLCID(system_lcid) ); + swprintf( buffer, ARRAY_SIZE(buffer), keyfmtW, langW ); + swprintf( value, ARRAY_SIZE(value), langfmtW, LANGIDFROMLCID(system_lcid) ); break; case NLS_SECTION_CODEPAGE: - NTDLL_swprintf( buffer, keyfmtW, cpW ); - NTDLL_swprintf( value, cpfmtW, id ); + swprintf( buffer, ARRAY_SIZE(buffer), keyfmtW, cpW ); + swprintf( value, ARRAY_SIZE(value), cpfmtW, id ); break; case NLS_SECTION_NORMALIZE: - NTDLL_swprintf( buffer, keyfmtW, normW ); - NTDLL_swprintf( value, normfmtW, id ); + swprintf( buffer, ARRAY_SIZE(buffer), keyfmtW, normW ); + swprintf( value, ARRAY_SIZE(value), normfmtW, id ); break; default: return STATUS_INVALID_PARAMETER_1; @@ -628,7 +628,7 @@ static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file ) name = intlW; break; case NLS_SECTION_CODEPAGE: - NTDLL_swprintf( buffer, cpdefaultW, id ); + swprintf( buffer, ARRAY_SIZE(buffer), cpdefaultW, id ); name = buffer; break; case NLS_SECTION_NORMALIZE: @@ -650,7 +650,8 @@ static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file ) valueW.MaximumLength = (wcslen(name) + wcslen(dir) + 5) * sizeof(WCHAR); if (!(valueW.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, valueW.MaximumLength ))) return STATUS_NO_MEMORY; - valueW.Length = NTDLL_swprintf( valueW.Buffer, pathfmtW, dir, name ) * sizeof(WCHAR); + valueW.Length = swprintf( valueW.Buffer, valueW.MaximumLength/sizeof(WCHAR), + pathfmtW, dir, name ) * sizeof(WCHAR); InitializeObjectAttributes( &attr, &valueW, 0, 0, NULL ); status = NtOpenFile( file, GENERIC_READ, &attr, &io, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT ); if (!status) TRACE( "found %s\n", debugstr_w( valueW.Buffer )); diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index c662db0c0f5..f3c06854014 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1455,7 +1455,7 @@ @ cdecl _memicmp(str str long) @ varargs _snprintf(ptr long str) NTDLL__snprintf @ varargs _snprintf_s(ptr long long str) -@ varargs _snwprintf(ptr long wstr) NTDLL__snwprintf +@ varargs _snwprintf(ptr long wstr) @ varargs _snwprintf_s(ptr long long wstr) @ varargs _swprintf(ptr wstr) NTDLL_swprintf @ cdecl _splitpath(str ptr ptr ptr ptr) @@ -1472,9 +1472,9 @@ @ cdecl _ultow(long ptr long) @ cdecl -norelay _vsnprintf(ptr long str ptr) @ cdecl _vsnprintf_s(ptr long str ptr) -@ cdecl _vsnwprintf(ptr long wstr ptr) NTDLL__vsnwprintf +@ cdecl _vsnwprintf(ptr long wstr ptr) @ cdecl _vsnwprintf_s(ptr long long wstr ptr) -@ cdecl _vswprintf(ptr wstr ptr) NTDLL__vswprintf +@ cdecl _vswprintf(ptr wstr ptr) @ cdecl _wcsicmp(wstr wstr) NTDLL__wcsicmp @ cdecl _wcslwr(wstr) NTDLL__wcslwr @ cdecl _wcsnicmp(wstr wstr long) NTDLL__wcsnicmp @@ -1548,7 +1548,7 @@ @ cdecl towupper(long) NTDLL_towupper @ stdcall vDbgPrintEx(long long str ptr) @ stdcall vDbgPrintExWithPrefix(str long long str ptr) -@ cdecl vsprintf(ptr str ptr) NTDLL_vsprintf +@ cdecl vsprintf(ptr str ptr) @ cdecl vsprintf_s(ptr long str ptr) @ cdecl vswprintf_s(ptr long wstr ptr) @ cdecl wcscat(wstr wstr) NTDLL_wcscat diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 7c64515bd00..170aac85491 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -181,7 +181,6 @@ LPWSTR __cdecl NTDLL_wcsstr( LPCWSTR str, LPCWSTR sub ); LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim ); LONG __cdecl NTDLL_wcstol( LPCWSTR s, LPWSTR *end, INT base ); ULONG __cdecl NTDLL_wcstoul( LPCWSTR s, LPWSTR *end, INT base ); -int WINAPIV NTDLL_swprintf( WCHAR *str, const WCHAR *format, ... ); #define memchr(p,c,n) NTDLL_memchr(p,c,n) #define strcat(d,s) NTDLL_strcat(d,s) diff --git a/dlls/ntdll/printf.c b/dlls/ntdll/printf.c index f753aef5552..16f64002d41 100644 --- a/dlls/ntdll/printf.c +++ b/dlls/ntdll/printf.c @@ -618,7 +618,7 @@ int CDECL _vsnprintf( char *str, size_t len, const char *format, __ms_va_list ar /*********************************************************************** * _vsnwprintf (NTDLL.@) */ -int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args ) +int CDECL _vsnwprintf( WCHAR *str, size_t len, const WCHAR *format, __ms_va_list args ) { pf_output out; int r; @@ -637,7 +637,7 @@ int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_v /********************************************************************* * _snprintf (NTDLL.@) */ -int WINAPIV NTDLL__snprintf( char *str, SIZE_T len, const char *format, ... ) +int WINAPIV NTDLL__snprintf( char *str, size_t len, const char *format, ... ) { int ret; __ms_va_list valist; @@ -652,13 +652,13 @@ int WINAPIV NTDLL__snprintf( char *str, SIZE_T len, const char *format, ... ) /*********************************************************************** * _snwprintf (NTDLL.@) */ -int WINAPIV NTDLL__snwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, ... ) +int WINAPIV _snwprintf( WCHAR *str, size_t len, const WCHAR *format, ... ) { int ret; __ms_va_list valist; __ms_va_start(valist, format); - ret = NTDLL__vsnwprintf( str, len, format, valist ); + ret = _vsnwprintf( str, len, format, valist ); __ms_va_end(valist); return ret; } @@ -748,7 +748,7 @@ int WINAPIV _snwprintf_s( WCHAR *str, size_t size, size_t len, const WCHAR *form /********************************************************************* * vsprintf (NTDLL.@) */ -int CDECL NTDLL_vsprintf( char *str, const char *format, __ms_va_list args ) +int CDECL vsprintf( char *str, const char *format, __ms_va_list args ) { return _vsnprintf( str, size_max, format, args ); } @@ -766,9 +766,9 @@ int CDECL vsprintf_s( char *str, size_t size, const char *format, __ms_va_list a /********************************************************************* * _vswprintf (NTDLL.@) */ -int CDECL NTDLL__vswprintf( WCHAR *str, const WCHAR *format, __ms_va_list args ) +int CDECL _vswprintf( WCHAR *str, const WCHAR *format, __ms_va_list args ) { - return NTDLL__vsnwprintf( str, size_max, format, args ); + return _vsnwprintf( str, size_max, format, args ); } @@ -820,7 +820,7 @@ int WINAPIV NTDLL_swprintf( WCHAR *str, const WCHAR *format, ... ) __ms_va_list valist; __ms_va_start(valist, format); - ret = NTDLL__vsnwprintf( str, size_max, format, valist ); + ret = _vsnwprintf( str, size_max, format, valist ); __ms_va_end(valist); return ret; } diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index e5b56381964..992721d133f 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -204,6 +204,7 @@ NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) static const WCHAR comW[] = {'.','c','o','m',0}; static const WCHAR pifW[] = {'.','p','i','f',0}; + DWORD len; WCHAR *p, *cmdline; UNICODE_STRING pathW, cmdW; @@ -226,12 +227,11 @@ NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) case STATUS_INVALID_IMAGE_WIN_16: case STATUS_INVALID_IMAGE_NE_FORMAT: case STATUS_INVALID_IMAGE_PROTECT: - cmdline = RtlAllocateHeap( GetProcessHeap(), 0, - (wcslen(system_dir) + wcslen(winevdm) + 16 + - wcslen(params->ImagePathName.Buffer) + - wcslen(params->CommandLine.Buffer)) * sizeof(WCHAR)); - if (!cmdline) return STATUS_NO_MEMORY; - NTDLL_swprintf( cmdline, argsW, (is_win64 || is_wow64) ? syswow64_dir : system_dir, + len = (wcslen(system_dir) + wcslen(winevdm) + 16 + wcslen(params->ImagePathName.Buffer) + + wcslen(params->CommandLine.Buffer)); + if (!(cmdline = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) + return STATUS_NO_MEMORY; + swprintf( cmdline, len, argsW, (is_win64 || is_wow64) ? syswow64_dir : system_dir, winevdm, params->ImagePathName.Buffer, params->CommandLine.Buffer ); RtlInitUnicodeString( &pathW, winevdm ); RtlInitUnicodeString( &cmdW, cmdline ); diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c index 14a44c3e2f9..c32c63a880d 100644 --- a/dlls/ntdll/rtl.c +++ b/dlls/ntdll/rtl.c @@ -1319,11 +1319,11 @@ NTSTATUS WINAPI RtlIpv4AddressToStringExW(const IN_ADDR *pin, USHORT port, LPWST TRACE("(%p:0x%x, %d, %p, %p:%d)\n", pin, pin->S_un.S_addr, port, buffer, psize, *psize); - needed = NTDLL_swprintf(tmp_ip, fmt_ip, + needed = swprintf(tmp_ip, ARRAY_SIZE(tmp_ip), fmt_ip, pin->S_un.S_un_b.s_b1, pin->S_un.S_un_b.s_b2, pin->S_un.S_un_b.s_b3, pin->S_un.S_un_b.s_b4); - if (port) needed += NTDLL_swprintf(tmp_ip + needed, fmt_port, ntohs(port)); + if (port) needed += swprintf(tmp_ip + needed, ARRAY_SIZE(tmp_ip) - needed, fmt_port, ntohs(port)); if (*psize > needed) { *psize = needed + 1; diff --git a/dlls/ntdll/rtlstr.c b/dlls/ntdll/rtlstr.c index 05cb34224c0..d8ff81b8050 100644 --- a/dlls/ntdll/rtlstr.c +++ b/dlls/ntdll/rtlstr.c @@ -1699,7 +1699,7 @@ NTSTATUS WINAPI RtlStringFromGUID(const GUID* guid, UNICODE_STRING *str) str->Length = str->MaximumLength = 0; return STATUS_NO_MEMORY; } - NTDLL_swprintf(str->Buffer, szFormat, guid->Data1, guid->Data2, guid->Data3, + swprintf(str->Buffer, str->MaximumLength/sizeof(WCHAR), szFormat, guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); diff --git a/dlls/ntdll/sec.c b/dlls/ntdll/sec.c index 2447a405861..5876e06c5b5 100644 --- a/dlls/ntdll/sec.c +++ b/dlls/ntdll/sec.c @@ -1820,13 +1820,14 @@ NTSTATUS WINAPI RtlConvertSidToUnicodeString( DWORD i, len; *p++ = 'S'; - p += NTDLL_swprintf( p, formatW, sid->Revision ); - p += NTDLL_swprintf( p, formatW, MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5], - sid->IdentifierAuthority.Value[4] ), - MAKEWORD( sid->IdentifierAuthority.Value[3], - sid->IdentifierAuthority.Value[2] ))); + p += swprintf( p, ARRAY_SIZE(buffer) - (p - buffer), formatW, sid->Revision ); + p += swprintf( p, ARRAY_SIZE(buffer) - (p - buffer), formatW, + MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5], + sid->IdentifierAuthority.Value[4] ), + MAKEWORD( sid->IdentifierAuthority.Value[3], + sid->IdentifierAuthority.Value[2] ))); for (i = 0; i < sid->SubAuthorityCount; i++) - p += NTDLL_swprintf( p, formatW, sid->SubAuthority[i] ); + p += swprintf( p, ARRAY_SIZE(buffer) - (p - buffer), formatW, sid->SubAuthority[i] ); len = (p + 1 - buffer) * sizeof(WCHAR);