From: Brendan Shanks bshanks@codeweavers.com
--- dlls/ntdll/unix/cdrom.c | 2 +- dlls/ntdll/unix/debug.c | 6 +++--- dlls/ntdll/unix/env.c | 14 +++++++------- dlls/ntdll/unix/file.c | 2 +- dlls/ntdll/unix/loader.c | 4 ++-- dlls/ntdll/unix/process.c | 2 +- dlls/ntdll/unix/registry.c | 6 +++--- dlls/ntdll/unix/serial.c | 2 +- dlls/ntdll/unix/sync.c | 2 +- dlls/ntdll/unix/system.c | 26 +++++++++++++------------- dlls/ntdll/unix/tape.c | 2 +- dlls/ntdll/unix/thread.c | 6 +++--- 12 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/dlls/ntdll/unix/cdrom.c b/dlls/ntdll/unix/cdrom.c index 615e7d10eba..45b61d54d05 100644 --- a/dlls/ntdll/unix/cdrom.c +++ b/dlls/ntdll/unix/cdrom.c @@ -203,7 +203,7 @@ static const char *iocodex(DWORD code) for(i=0; i<ARRAY_SIZE(iocodextable); i++) if (code==iocodextable[i].code) return iocodextable[i].codex; - sprintf(buffer, "IOCTL_CODE_%x", (int)code); + snprintf(buffer, sizeof(buffer), "IOCTL_CODE_%x", (int)code); return buffer; }
diff --git a/dlls/ntdll/unix/debug.c b/dlls/ntdll/unix/debug.c index bc0e3c1c694..11bb7a2df22 100644 --- a/dlls/ntdll/unix/debug.c +++ b/dlls/ntdll/unix/debug.c @@ -318,10 +318,10 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_ if (TRACE_ON(timestamp)) { UINT ticks = NtGetTickCount(); - pos += sprintf( pos, "%3u.%03u:", ticks / 1000, ticks % 1000 ); + pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%3u.%03u:", ticks / 1000, ticks % 1000 ); } - if (TRACE_ON(pid)) pos += sprintf( pos, "%04x:", (UINT)GetCurrentProcessId() ); - pos += sprintf( pos, "%04x:", (UINT)GetCurrentThreadId() ); + if (TRACE_ON(pid)) pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%04x:", (UINT)GetCurrentProcessId() ); + pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%04x:", (UINT)GetCurrentThreadId() ); } if (function && cls < ARRAY_SIZE( classes )) pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%s:%s:%s ", diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index ec908a5389f..5a58911c759 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -95,7 +95,7 @@ static char *get_nls_file_path( UINT type, UINT id ) { case NLS_SECTION_SORTKEYS: name = "sortdefault"; break; case NLS_SECTION_CASEMAP: name = "l_intl"; break; - case NLS_SECTION_CODEPAGE: name = tmp; sprintf( tmp, "c_%03u", id ); break; + case NLS_SECTION_CODEPAGE: name = tmp; snprintf( tmp, sizeof(tmp), "c_%03u", id ); break; case NLS_SECTION_NORMALIZE: switch (id) { @@ -182,10 +182,10 @@ static NTSTATUS get_nls_section_name( UINT type, UINT id, WCHAR name[32] ) strcpy( buffer, "\NLS\NlsSectionLANG_INTL" ); break; case NLS_SECTION_CODEPAGE: - sprintf( buffer, "\NLS\NlsSectionCP%03u", id); + snprintf( buffer, sizeof(buffer), "\NLS\NlsSectionCP%03u", id); break; case NLS_SECTION_NORMALIZE: - sprintf( buffer, "\NLS\NlsSectionNORM%08x", id); + snprintf( buffer, sizeof(buffer), "\NLS\NlsSectionNORM%08x", id); break; default: return STATUS_INVALID_PARAMETER_1; @@ -303,7 +303,7 @@ static void init_unix_codepage(void) char buffer[16]; void *data;
- sprintf( buffer, "c_%03u.nls", charset_names[pos].cp ); + snprintf( buffer, sizeof(buffer), "c_%03u.nls", charset_names[pos].cp ); if ((data = read_nls_file( buffer ))) init_codepage_table( data, &unix_cp ); } return; @@ -1077,10 +1077,10 @@ static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size ) add_path_var( env, pos, size, "WINECONFIGDIR", config_dir ); for (i = 0; dll_paths[i]; i++) { - sprintf( str, "WINEDLLDIR%u", i ); + snprintf( str, sizeof(str), "WINEDLLDIR%u", i ); add_path_var( env, pos, size, str, dll_paths[i] ); } - sprintf( str, "WINEDLLDIR%u", i ); + snprintf( str, sizeof(str), "WINEDLLDIR%u", i ); append_envW( env, pos, size, str, NULL ); add_system_dll_path_var( env, pos, size ); append_envA( env, pos, size, "WINELOADER", wineloader ); @@ -1088,7 +1088,7 @@ static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size ) append_envA( env, pos, size, "WINEDLLOVERRIDES", overrides ); if (unix_cp.CodePage != CP_UTF8) { - sprintf( str, "%u", unix_cp.CodePage ); + snprintf( str, sizeof(str), "%u", unix_cp.CodePage ); append_envA( env, pos, size, "WINEUNIXCP", str ); } else append_envW( env, pos, size, "WINEUNIXCP", NULL ); diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index 72fcba6e998..98e50082904 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -1613,7 +1613,7 @@ static int fd_set_dos_attrib( int fd, UINT attr, BOOL force_set ) * this format with more features, but retains compatibility with the * earlier format. */ char data[11]; - int len = sprintf( data, "0x%x", attr ); + int len = snprintf( data, sizeof(data), "0x%x", attr ); return xattr_fset( fd, SAMBA_XATTR_DOS_ATTRIB, data, len ); } else return xattr_fremove( fd, SAMBA_XATTR_DOS_ATTRIB ); diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 0db25f88527..8ffd5ca41e6 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -757,8 +757,8 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i
signal( SIGPIPE, SIG_DFL );
- sprintf( socket_env, "WINESERVERSOCKET=%u", socketfd ); - sprintf( preloader_reserve, "WINEPRELOADRESERVE=%x%08x-%x%08x", + snprintf( socket_env, sizeof(socket_env), "WINESERVERSOCKET=%u", socketfd ); + snprintf( preloader_reserve, sizeof(preloader_reserve), "WINEPRELOADRESERVE=%x%08x-%x%08x", (UINT)(res_start >> 32), (UINT)res_start, (UINT)(res_end >> 32), (UINT)res_end );
putenv( preloader_reserve ); diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c index 4c7e545695c..db0d92a1b36 100644 --- a/dlls/ntdll/unix/process.c +++ b/dlls/ntdll/unix/process.c @@ -1042,7 +1042,7 @@ void fill_vm_counters( VM_COUNTERS_EX *pvmi, int unix_pid ) if (unix_pid == -1) strcpy( path, "/proc/self/status" ); else - sprintf( path, "/proc/%u/status", unix_pid); + snprintf( path, sizeof(path), "/proc/%u/status", unix_pid); f = fopen( path, "r" ); if (!f) return;
diff --git a/dlls/ntdll/unix/registry.c b/dlls/ntdll/unix/registry.c index fe629b5e3b4..e19414bfa86 100644 --- a/dlls/ntdll/unix/registry.c +++ b/dlls/ntdll/unix/registry.c @@ -55,12 +55,12 @@ NTSTATUS open_hkcu_key( const char *path, HANDLE *key ) if (status) return status;
sid = ((TOKEN_USER *)sid_data)->User.Sid; - len = sprintf( buffer, "\Registry\User\S-%u-%u", sid->Revision, + len = snprintf( buffer, sizeof(buffer), "\Registry\User\S-%u-%u", sid->Revision, (int)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++) - len += sprintf( buffer + len, "-%u", (int)sid->SubAuthority[i] ); - len += sprintf( buffer + len, "\%s", path ); + len += snprintf( buffer + len, sizeof(buffer) - len, "-%u", (int)sid->SubAuthority[i] ); + len += snprintf( buffer + len, sizeof(buffer) - len, "\%s", path );
ascii_to_unicode( bufferW, buffer, len + 1 ); init_unicode_string( &name, bufferW ); diff --git a/dlls/ntdll/unix/serial.c b/dlls/ntdll/unix/serial.c index 734f88aa449..93619f2407b 100644 --- a/dlls/ntdll/unix/serial.c +++ b/dlls/ntdll/unix/serial.c @@ -113,7 +113,7 @@ static const char* iocode2str(UINT ioc) X(IOCTL_SERIAL_WAIT_ON_MASK); X(IOCTL_SERIAL_XOFF_COUNTER); #undef X - default: { static char tmp[32]; sprintf(tmp, "IOCTL_SERIAL_%d\n", ioc); return tmp; } + default: { static char tmp[32]; snprintf(tmp, sizeof(tmp), "IOCTL_SERIAL_%d\n", ioc); return tmp; } } }
diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c index d1e4e5ee111..b21fcc0b046 100644 --- a/dlls/ntdll/unix/sync.c +++ b/dlls/ntdll/unix/sync.c @@ -2207,7 +2207,7 @@ done: static ULONG integral_atom_name( WCHAR *buffer, ULONG len, RTL_ATOM atom ) { char tmp[16]; - int ret = sprintf( tmp, "#%u", atom ); + int ret = snprintf( tmp, sizeof(tmp), "#%u", atom );
len /= sizeof(WCHAR); if (len) diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 4fbe45b2dd9..07598c8c95e 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -938,7 +938,7 @@ static NTSTATUS create_logical_proc_info(void) continue; }
- sprintf(name, core_info, i, "physical_package_id"); + snprintf(name, sizeof(name), core_info, i, "physical_package_id"); f = fopen(name, "r"); if (f) { @@ -964,13 +964,13 @@ static NTSTATUS create_logical_proc_info(void) */
/* Mask of logical threads sharing same physical core in kernel core numbering. */ - sprintf(name, core_info, i, "thread_siblings"); + snprintf(name, sizeof(name), core_info, i, "thread_siblings"); if(!sysfs_parse_bitmap(name, &thread_mask)) thread_mask = 1<<i;
/* Needed later for NumaNode and Group. */ all_cpus_mask |= thread_mask;
- sprintf(name, core_info, i, "thread_siblings_list"); + snprintf(name, sizeof(name), core_info, i, "thread_siblings_list"); f = fopen(name, "r"); if (f) { @@ -990,31 +990,31 @@ static NTSTATUS create_logical_proc_info(void) CACHE_DESCRIPTOR cache; ULONG_PTR mask = 0;
- sprintf(name, cache_info, i, j, "shared_cpu_map"); + snprintf(name, sizeof(name), cache_info, i, j, "shared_cpu_map"); if(!sysfs_parse_bitmap(name, &mask)) continue;
- sprintf(name, cache_info, i, j, "level"); + snprintf(name, sizeof(name), cache_info, i, j, "level"); f = fopen(name, "r"); if(!f) continue; fscanf(f, "%u", &r); fclose(f); cache.Level = r;
- sprintf(name, cache_info, i, j, "ways_of_associativity"); + snprintf(name, sizeof(name), cache_info, i, j, "ways_of_associativity"); f = fopen(name, "r"); if(!f) continue; fscanf(f, "%u", &r); fclose(f); cache.Associativity = r;
- sprintf(name, cache_info, i, j, "coherency_line_size"); + snprintf(name, sizeof(name), cache_info, i, j, "coherency_line_size"); f = fopen(name, "r"); if(!f) continue; fscanf(f, "%u", &r); fclose(f); cache.LineSize = r;
- sprintf(name, cache_info, i, j, "size"); + snprintf(name, sizeof(name), cache_info, i, j, "size"); f = fopen(name, "r"); if(!f) continue; fscanf(f, "%u%c", &r, &op); @@ -1023,7 +1023,7 @@ static NTSTATUS create_logical_proc_info(void) WARN("unknown cache size %u%c\n", r, op); cache.Size = (op=='K' ? r*1024 : r);
- sprintf(name, cache_info, i, j, "type"); + snprintf(name, sizeof(name), cache_info, i, j, "type"); f = fopen(name, "r"); if(!f) continue; fscanf(f, "%s", name); @@ -1066,7 +1066,7 @@ static NTSTATUS create_logical_proc_info(void) { ULONG_PTR mask = 0;
- sprintf(name, numa_info, i); + snprintf(name, sizeof(name), numa_info, i); if (!sysfs_parse_bitmap( name, &mask )) continue;
if (!logical_proc_info_add_numa_node( mask, i )) @@ -2218,7 +2218,7 @@ static void find_reg_tz_info(RTL_DYNAMIC_TIME_ZONE_INFORMATION *tzi, const char* char buffer[128]; KEY_BASIC_INFORMATION *info = (KEY_BASIC_INFORMATION *)buffer;
- sprintf( buffer, "%u", year ); + snprintf( buffer, sizeof(buffer), "%u", year ); ascii_to_unicode( yearW, buffer, strlen(buffer) + 1 ); init_unicode_string( &nameW, Time_ZonesW ); InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL ); @@ -3780,7 +3780,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input, FILE* f;
for(i = 0; i < out_cpus; i++) { - sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i); + snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i); f = fopen(filename, "r"); if (f && (fscanf(f, "%u", &val) == 1)) { cpu_power[i].MaxMhz = val / 1000; @@ -3799,7 +3799,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input, if(f) fclose(f); }
- sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i); + snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i); f = fopen(filename, "r"); if(f && (fscanf(f, "%u", &val) == 1)) { cpu_power[i].MhzLimit = val / 1000; diff --git a/dlls/ntdll/unix/tape.c b/dlls/ntdll/unix/tape.c index 3e0226836ff..a8eb04cf67f 100644 --- a/dlls/ntdll/unix/tape.c +++ b/dlls/ntdll/unix/tape.c @@ -84,7 +84,7 @@ static const char *io2str( unsigned int io ) X(IOCTL_TAPE_SET_POSITION); X(IOCTL_TAPE_WRITE_MARKS); #undef X - default: { static char tmp[32]; sprintf(tmp, "IOCTL_TAPE_%d\n", io); return tmp; } + default: { static char tmp[32]; snprintf(tmp, sizeof(tmp), "IOCTL_TAPE_%d\n", io); return tmp; } } }
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index 0c433fef4c2..2a9bc41e788 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -1799,9 +1799,9 @@ BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LA int i;
if (unix_tid == -1) - sprintf( buf, "/proc/%u/stat", unix_pid ); + snprintf( buf, sizeof(buf), "/proc/%u/stat", unix_pid ); else - sprintf( buf, "/proc/%u/task/%u/stat", unix_pid, unix_tid ); + snprintf( buf, sizeof(buf), "/proc/%u/task/%u/stat", unix_pid, unix_tid ); if (!(f = fopen( buf, "r" ))) { WARN("Failed to open %s: %s\n", buf, strerror(errno)); @@ -1904,7 +1904,7 @@ static void set_native_thread_name( HANDLE handle, const UNICODE_STRING *name ) }
len = ntdll_wcstoumbs( name->Buffer, name->Length / sizeof(WCHAR), nameA, sizeof(nameA), FALSE ); - sprintf(path, "/proc/%u/task/%u/comm", unix_pid, unix_tid); + snprintf(path, sizeof(path), "/proc/%u/task/%u/comm", unix_pid, unix_tid); if ((fd = open( path, O_WRONLY )) != -1) { write( fd, nameA, len );