Commit a5f17fac authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

ntdll/unix: Replace sprintf with snprintf to avoid deprecation warnings on macOS.

parent 90920400
...@@ -203,7 +203,7 @@ static const char *iocodex(DWORD code) ...@@ -203,7 +203,7 @@ static const char *iocodex(DWORD code)
for(i=0; i<ARRAY_SIZE(iocodextable); i++) for(i=0; i<ARRAY_SIZE(iocodextable); i++)
if (code==iocodextable[i].code) if (code==iocodextable[i].code)
return iocodextable[i].codex; return iocodextable[i].codex;
sprintf(buffer, "IOCTL_CODE_%x", (int)code); snprintf(buffer, sizeof(buffer), "IOCTL_CODE_%x", (int)code);
return buffer; return buffer;
} }
......
...@@ -318,10 +318,10 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_ ...@@ -318,10 +318,10 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_
if (TRACE_ON(timestamp)) if (TRACE_ON(timestamp))
{ {
UINT ticks = NtGetTickCount(); 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() ); if (TRACE_ON(pid)) pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%04x:", (UINT)GetCurrentProcessId() );
pos += sprintf( pos, "%04x:", (UINT)GetCurrentThreadId() ); pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%04x:", (UINT)GetCurrentThreadId() );
} }
if (function && cls < ARRAY_SIZE( classes )) if (function && cls < ARRAY_SIZE( classes ))
pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%s:%s:%s ", pos += snprintf( pos, sizeof(info->output) - (pos - info->output), "%s:%s:%s ",
......
...@@ -95,7 +95,7 @@ static char *get_nls_file_path( UINT type, UINT id ) ...@@ -95,7 +95,7 @@ static char *get_nls_file_path( UINT type, UINT id )
{ {
case NLS_SECTION_SORTKEYS: name = "sortdefault"; break; case NLS_SECTION_SORTKEYS: name = "sortdefault"; break;
case NLS_SECTION_CASEMAP: name = "l_intl"; 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: case NLS_SECTION_NORMALIZE:
switch (id) switch (id)
{ {
...@@ -182,10 +182,10 @@ static NTSTATUS get_nls_section_name( UINT type, UINT id, WCHAR name[32] ) ...@@ -182,10 +182,10 @@ static NTSTATUS get_nls_section_name( UINT type, UINT id, WCHAR name[32] )
strcpy( buffer, "\\NLS\\NlsSectionLANG_INTL" ); strcpy( buffer, "\\NLS\\NlsSectionLANG_INTL" );
break; break;
case NLS_SECTION_CODEPAGE: case NLS_SECTION_CODEPAGE:
sprintf( buffer, "\\NLS\\NlsSectionCP%03u", id); snprintf( buffer, sizeof(buffer), "\\NLS\\NlsSectionCP%03u", id);
break; break;
case NLS_SECTION_NORMALIZE: case NLS_SECTION_NORMALIZE:
sprintf( buffer, "\\NLS\\NlsSectionNORM%08x", id); snprintf( buffer, sizeof(buffer), "\\NLS\\NlsSectionNORM%08x", id);
break; break;
default: default:
return STATUS_INVALID_PARAMETER_1; return STATUS_INVALID_PARAMETER_1;
...@@ -303,7 +303,7 @@ static void init_unix_codepage(void) ...@@ -303,7 +303,7 @@ static void init_unix_codepage(void)
char buffer[16]; char buffer[16];
void *data; 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 ); if ((data = read_nls_file( buffer ))) init_codepage_table( data, &unix_cp );
} }
return; return;
...@@ -1077,10 +1077,10 @@ static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size ) ...@@ -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 ); add_path_var( env, pos, size, "WINECONFIGDIR", config_dir );
for (i = 0; dll_paths[i]; i++) 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] ); 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 ); append_envW( env, pos, size, str, NULL );
add_system_dll_path_var( env, pos, size ); add_system_dll_path_var( env, pos, size );
append_envA( env, pos, size, "WINELOADER", wineloader ); append_envA( env, pos, size, "WINELOADER", wineloader );
...@@ -1088,7 +1088,7 @@ static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size ) ...@@ -1088,7 +1088,7 @@ static void add_dynamic_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size )
append_envA( env, pos, size, "WINEDLLOVERRIDES", overrides ); append_envA( env, pos, size, "WINEDLLOVERRIDES", overrides );
if (unix_cp.CodePage != CP_UTF8) 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 ); append_envA( env, pos, size, "WINEUNIXCP", str );
} }
else append_envW( env, pos, size, "WINEUNIXCP", NULL ); else append_envW( env, pos, size, "WINEUNIXCP", NULL );
......
...@@ -1613,7 +1613,7 @@ static int fd_set_dos_attrib( int fd, UINT attr, BOOL force_set ) ...@@ -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 * this format with more features, but retains compatibility with the
* earlier format. */ * earlier format. */
char data[11]; 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 ); return xattr_fset( fd, SAMBA_XATTR_DOS_ATTRIB, data, len );
} }
else return xattr_fremove( fd, SAMBA_XATTR_DOS_ATTRIB ); else return xattr_fremove( fd, SAMBA_XATTR_DOS_ATTRIB );
......
...@@ -757,8 +757,8 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i ...@@ -757,8 +757,8 @@ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_i
signal( SIGPIPE, SIG_DFL ); signal( SIGPIPE, SIG_DFL );
sprintf( socket_env, "WINESERVERSOCKET=%u", socketfd ); snprintf( socket_env, sizeof(socket_env), "WINESERVERSOCKET=%u", socketfd );
sprintf( preloader_reserve, "WINEPRELOADRESERVE=%x%08x-%x%08x", 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 ); (UINT)(res_start >> 32), (UINT)res_start, (UINT)(res_end >> 32), (UINT)res_end );
putenv( preloader_reserve ); putenv( preloader_reserve );
......
...@@ -1042,7 +1042,7 @@ void fill_vm_counters( VM_COUNTERS_EX *pvmi, int unix_pid ) ...@@ -1042,7 +1042,7 @@ void fill_vm_counters( VM_COUNTERS_EX *pvmi, int unix_pid )
if (unix_pid == -1) if (unix_pid == -1)
strcpy( path, "/proc/self/status" ); strcpy( path, "/proc/self/status" );
else else
sprintf( path, "/proc/%u/status", unix_pid); snprintf( path, sizeof(path), "/proc/%u/status", unix_pid);
f = fopen( path, "r" ); f = fopen( path, "r" );
if (!f) return; if (!f) return;
......
...@@ -55,12 +55,12 @@ NTSTATUS open_hkcu_key( const char *path, HANDLE *key ) ...@@ -55,12 +55,12 @@ NTSTATUS open_hkcu_key( const char *path, HANDLE *key )
if (status) return status; if (status) return status;
sid = ((TOKEN_USER *)sid_data)->User.Sid; 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] ), (int)MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5], sid->IdentifierAuthority.Value[4] ),
MAKEWORD( sid->IdentifierAuthority.Value[3], sid->IdentifierAuthority.Value[2] ))); MAKEWORD( sid->IdentifierAuthority.Value[3], sid->IdentifierAuthority.Value[2] )));
for (i = 0; i < sid->SubAuthorityCount; i++) for (i = 0; i < sid->SubAuthorityCount; i++)
len += sprintf( buffer + len, "-%u", (int)sid->SubAuthority[i] ); len += snprintf( buffer + len, sizeof(buffer) - len, "-%u", (int)sid->SubAuthority[i] );
len += sprintf( buffer + len, "\\%s", path ); len += snprintf( buffer + len, sizeof(buffer) - len, "\\%s", path );
ascii_to_unicode( bufferW, buffer, len + 1 ); ascii_to_unicode( bufferW, buffer, len + 1 );
init_unicode_string( &name, bufferW ); init_unicode_string( &name, bufferW );
......
...@@ -113,7 +113,7 @@ static const char* iocode2str(UINT ioc) ...@@ -113,7 +113,7 @@ static const char* iocode2str(UINT ioc)
X(IOCTL_SERIAL_WAIT_ON_MASK); X(IOCTL_SERIAL_WAIT_ON_MASK);
X(IOCTL_SERIAL_XOFF_COUNTER); X(IOCTL_SERIAL_XOFF_COUNTER);
#undef X #undef X
default: { static char tmp[32]; sprintf(tmp, "IOCTL_SERIAL_%d\n", ioc); return tmp; } default: return wine_dbg_sprintf("IOCTL_SERIAL_%d\n", ioc);
} }
} }
......
...@@ -2207,7 +2207,7 @@ done: ...@@ -2207,7 +2207,7 @@ done:
static ULONG integral_atom_name( WCHAR *buffer, ULONG len, RTL_ATOM atom ) static ULONG integral_atom_name( WCHAR *buffer, ULONG len, RTL_ATOM atom )
{ {
char tmp[16]; char tmp[16];
int ret = sprintf( tmp, "#%u", atom ); int ret = snprintf( tmp, sizeof(tmp), "#%u", atom );
len /= sizeof(WCHAR); len /= sizeof(WCHAR);
if (len) if (len)
......
...@@ -938,7 +938,7 @@ static NTSTATUS create_logical_proc_info(void) ...@@ -938,7 +938,7 @@ static NTSTATUS create_logical_proc_info(void)
continue; continue;
} }
sprintf(name, core_info, i, "physical_package_id"); snprintf(name, sizeof(name), core_info, i, "physical_package_id");
f = fopen(name, "r"); f = fopen(name, "r");
if (f) if (f)
{ {
...@@ -964,13 +964,13 @@ static NTSTATUS create_logical_proc_info(void) ...@@ -964,13 +964,13 @@ static NTSTATUS create_logical_proc_info(void)
*/ */
/* Mask of logical threads sharing same physical core in kernel core numbering. */ /* 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; if(!sysfs_parse_bitmap(name, &thread_mask)) thread_mask = 1<<i;
/* Needed later for NumaNode and Group. */ /* Needed later for NumaNode and Group. */
all_cpus_mask |= thread_mask; 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"); f = fopen(name, "r");
if (f) if (f)
{ {
...@@ -990,31 +990,31 @@ static NTSTATUS create_logical_proc_info(void) ...@@ -990,31 +990,31 @@ static NTSTATUS create_logical_proc_info(void)
CACHE_DESCRIPTOR cache; CACHE_DESCRIPTOR cache;
ULONG_PTR mask = 0; 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; 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"); f = fopen(name, "r");
if(!f) continue; if(!f) continue;
fscanf(f, "%u", &r); fscanf(f, "%u", &r);
fclose(f); fclose(f);
cache.Level = r; 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"); f = fopen(name, "r");
if(!f) continue; if(!f) continue;
fscanf(f, "%u", &r); fscanf(f, "%u", &r);
fclose(f); fclose(f);
cache.Associativity = r; 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"); f = fopen(name, "r");
if(!f) continue; if(!f) continue;
fscanf(f, "%u", &r); fscanf(f, "%u", &r);
fclose(f); fclose(f);
cache.LineSize = r; cache.LineSize = r;
sprintf(name, cache_info, i, j, "size"); snprintf(name, sizeof(name), cache_info, i, j, "size");
f = fopen(name, "r"); f = fopen(name, "r");
if(!f) continue; if(!f) continue;
fscanf(f, "%u%c", &r, &op); fscanf(f, "%u%c", &r, &op);
...@@ -1023,7 +1023,7 @@ static NTSTATUS create_logical_proc_info(void) ...@@ -1023,7 +1023,7 @@ static NTSTATUS create_logical_proc_info(void)
WARN("unknown cache size %u%c\n", r, op); WARN("unknown cache size %u%c\n", r, op);
cache.Size = (op=='K' ? r*1024 : r); 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"); f = fopen(name, "r");
if(!f) continue; if(!f) continue;
fscanf(f, "%s", name); fscanf(f, "%s", name);
...@@ -1066,7 +1066,7 @@ static NTSTATUS create_logical_proc_info(void) ...@@ -1066,7 +1066,7 @@ static NTSTATUS create_logical_proc_info(void)
{ {
ULONG_PTR mask = 0; ULONG_PTR mask = 0;
sprintf(name, numa_info, i); snprintf(name, sizeof(name), numa_info, i);
if (!sysfs_parse_bitmap( name, &mask )) continue; if (!sysfs_parse_bitmap( name, &mask )) continue;
if (!logical_proc_info_add_numa_node( mask, i )) 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* ...@@ -2218,7 +2218,7 @@ static void find_reg_tz_info(RTL_DYNAMIC_TIME_ZONE_INFORMATION *tzi, const char*
char buffer[128]; char buffer[128];
KEY_BASIC_INFORMATION *info = (KEY_BASIC_INFORMATION *)buffer; 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 ); ascii_to_unicode( yearW, buffer, strlen(buffer) + 1 );
init_unicode_string( &nameW, Time_ZonesW ); init_unicode_string( &nameW, Time_ZonesW );
InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL ); InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL );
...@@ -3780,7 +3780,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input, ...@@ -3780,7 +3780,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input,
FILE* f; FILE* f;
for(i = 0; i < out_cpus; i++) { 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"); f = fopen(filename, "r");
if (f && (fscanf(f, "%u", &val) == 1)) { if (f && (fscanf(f, "%u", &val) == 1)) {
cpu_power[i].MaxMhz = val / 1000; cpu_power[i].MaxMhz = val / 1000;
...@@ -3799,7 +3799,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input, ...@@ -3799,7 +3799,7 @@ NTSTATUS WINAPI NtPowerInformation( POWER_INFORMATION_LEVEL level, void *input,
if(f) fclose(f); 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"); f = fopen(filename, "r");
if(f && (fscanf(f, "%u", &val) == 1)) { if(f && (fscanf(f, "%u", &val) == 1)) {
cpu_power[i].MhzLimit = val / 1000; cpu_power[i].MhzLimit = val / 1000;
......
...@@ -84,7 +84,7 @@ static const char *io2str( unsigned int io ) ...@@ -84,7 +84,7 @@ static const char *io2str( unsigned int io )
X(IOCTL_TAPE_SET_POSITION); X(IOCTL_TAPE_SET_POSITION);
X(IOCTL_TAPE_WRITE_MARKS); X(IOCTL_TAPE_WRITE_MARKS);
#undef X #undef X
default: { static char tmp[32]; sprintf(tmp, "IOCTL_TAPE_%d\n", io); return tmp; } default: return wine_dbg_sprintf("IOCTL_TAPE_%d\n", io);
} }
} }
......
...@@ -1799,9 +1799,9 @@ BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LA ...@@ -1799,9 +1799,9 @@ BOOL get_thread_times(int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time, LA
int i; int i;
if (unix_tid == -1) if (unix_tid == -1)
sprintf( buf, "/proc/%u/stat", unix_pid ); snprintf( buf, sizeof(buf), "/proc/%u/stat", unix_pid );
else 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" ))) if (!(f = fopen( buf, "r" )))
{ {
WARN("Failed to open %s: %s\n", buf, strerror(errno)); 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 ) ...@@ -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 ); 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) if ((fd = open( path, O_WRONLY )) != -1)
{ {
write( fd, nameA, len ); write( fd, nameA, len );
......
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