Commit 9b4e3718 authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

server: Replace sprintf with snprintf to avoid deprecation warnings on macOS.

parent 4e04b2d5
......@@ -726,7 +726,7 @@ static char *get_path_from_fd( int fd, int sz )
#ifdef linux
char *ret = malloc( 32 + sz );
if (ret) sprintf( ret, "/proc/self/fd/%u", fd );
if (ret) snprintf( ret, 32 + sz, "/proc/self/fd/%u", fd );
return ret;
#elif defined(F_GETPATH)
char *ret = malloc( PATH_MAX + sz );
......
......@@ -320,7 +320,7 @@ static void create_session( unsigned int id )
release_object( dir_sessions );
}
sprintf( id_strA, "%u", id );
snprintf( id_strA, sizeof(id_strA), "%u", id );
id_strW = ascii_to_unicode_str( id_strA, &id_str );
dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL );
dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, OBJ_PERMANENT, HASH_SIZE, NULL );
......
......@@ -465,7 +465,7 @@ const char *get_timeout_str( timeout_t timeout )
{
secs = -timeout / TICKS_PER_SEC;
nsecs = -timeout % TICKS_PER_SEC;
sprintf( buffer, "+%ld.%07ld", secs, nsecs );
snprintf( buffer, sizeof(buffer), "+%ld.%07ld", secs, nsecs );
}
else /* absolute */
{
......@@ -477,12 +477,12 @@ const char *get_timeout_str( timeout_t timeout )
secs--;
}
if (secs >= 0)
sprintf( buffer, "%x%08x (+%ld.%07ld)",
(unsigned int)(timeout >> 32), (unsigned int)timeout, secs, nsecs );
snprintf( buffer, sizeof(buffer), "%x%08x (+%ld.%07ld)",
(unsigned int)(timeout >> 32), (unsigned int)timeout, secs, nsecs );
else
sprintf( buffer, "%x%08x (-%ld.%07ld)",
(unsigned int)(timeout >> 32), (unsigned int)timeout,
-(secs + 1), TICKS_PER_SEC - nsecs );
snprintf( buffer, sizeof(buffer), "%x%08x (-%ld.%07ld)",
(unsigned int)(timeout >> 32), (unsigned int)timeout,
-(secs + 1), TICKS_PER_SEC - nsecs );
}
return buffer;
}
......
......@@ -292,7 +292,7 @@ static int make_temp_file( char name[16] )
value += (current_time >> 16) + current_time;
for (i = 0; i < 0x8000 && fd < 0; i++, value += 7777)
{
sprintf( name, "tmpmap-%08x", value );
snprintf( name, 16, "tmpmap-%08x", value );
fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0600 );
}
return fd;
......
......@@ -1552,7 +1552,7 @@ DECL_HANDLER(get_process_vm_counters)
char proc_path[32], line[256];
unsigned long value;
sprintf( proc_path, "/proc/%u/status", process->unix_pid );
snprintf( proc_path, sizeof(proc_path), "/proc/%u/status", process->unix_pid );
if ((f = fopen( proc_path, "r" )))
{
while (fgets( line, sizeof(line), f ))
......
......@@ -55,7 +55,7 @@ static int open_proc_as( struct process *process, int flags )
return -1;
}
sprintf( buffer, "/proc/%u/as", process->unix_pid );
snprintf( buffer, sizeof(buffer), "/proc/%u/as", process->unix_pid );
if ((fd = open( buffer, flags )) == -1)
{
if (errno == ENOENT) /* probably got killed */
......@@ -75,7 +75,7 @@ static int open_proc_lwpctl( struct thread *thread )
if (thread->unix_pid == -1) return -1;
sprintf( buffer, "/proc/%u/lwp/%u/lwpctl", thread->unix_pid, thread->unix_tid );
snprintf( buffer, sizeof(buffer), "/proc/%u/lwp/%u/lwpctl", thread->unix_pid, thread->unix_tid );
if ((fd = open( buffer, O_WRONLY )) == -1)
{
if (errno == ENOENT) /* probably got killed */
......
......@@ -366,7 +366,7 @@ int read_process_memory( struct process *process, client_ptr_t ptr, data_size_t
char procmem[24];
int fd;
sprintf( procmem, "/proc/%u/mem", process->unix_pid );
snprintf( procmem, sizeof(procmem), "/proc/%u/mem", process->unix_pid );
if ((fd = open( procmem, O_RDONLY )) != -1)
{
ssize_t ret = pread( fd, dest, size, ptr );
......@@ -467,7 +467,7 @@ int write_process_memory( struct process *process, client_ptr_t ptr, data_size_t
char procmem[24];
int fd;
sprintf( procmem, "/proc/%u/mem", process->unix_pid );
snprintf( procmem, sizeof(procmem), "/proc/%u/mem", process->unix_pid );
if ((fd = open( procmem, O_WRONLY )) != -1)
{
ssize_t r = pwrite( fd, src, size, ptr );
......
......@@ -1831,15 +1831,16 @@ static int load_init_registry_from_file( const char *filename, struct key *key )
static WCHAR *format_user_registry_path( const struct sid *sid, struct unicode_str *path )
{
char buffer[7 + 11 + 11 + 11 * ARRAY_SIZE(sid->sub_auth)], *p = buffer;
char buffer[7 + 11 + 11 + 11 * ARRAY_SIZE(sid->sub_auth)];
unsigned int i;
p += sprintf( p, "User\\S-%u-%u", sid->revision,
((unsigned int)sid->id_auth[2] << 24) |
((unsigned int)sid->id_auth[3] << 16) |
((unsigned int)sid->id_auth[4] << 8) |
((unsigned int)sid->id_auth[5]) );
for (i = 0; i < sid->sub_count; i++) p += sprintf( p, "-%u", sid->sub_auth[i] );
int len;
len = snprintf( buffer, sizeof(buffer), "User\\S-%u-%u", sid->revision,
((unsigned int)sid->id_auth[2] << 24) |
((unsigned int)sid->id_auth[3] << 16) |
((unsigned int)sid->id_auth[4] << 8) |
((unsigned int)sid->id_auth[5]) );
for (i = 0; i < sid->sub_count; i++) len += snprintf( buffer + len, sizeof(buffer) - len, "-%u", sid->sub_auth[i] );
return ascii_to_unicode_str( buffer, path );
}
......
......@@ -5645,7 +5645,7 @@ static const char *get_status_name( unsigned int status )
for (i = 0; status_names[i].name; i++)
if (status_names[i].value == status) return status_names[i].name;
}
sprintf( buffer, "%x", status );
snprintf( buffer, sizeof(buffer), "%x", status );
return buffer;
}
......
......@@ -212,19 +212,19 @@ int dump_strW( const WCHAR *str, data_size_t len, FILE *f, const char escape[2]
if (*str > 127) /* hex escape */
{
if (len > 1 && str[1] < 128 && isxdigit((char)str[1]))
pos += sprintf( pos, "\\x%04x", *str );
pos += snprintf( pos, sizeof(buffer) - (pos - buffer), "\\x%04x", *str );
else
pos += sprintf( pos, "\\x%x", *str );
pos += snprintf( pos, sizeof(buffer) - (pos - buffer), "\\x%x", *str );
continue;
}
if (*str < 32) /* octal or C escape */
{
if (escapes[*str] != '.')
pos += sprintf( pos, "\\%c", escapes[*str] );
pos += snprintf( pos, sizeof(buffer) - (pos - buffer), "\\%c", escapes[*str] );
else if (len > 1 && str[1] >= '0' && str[1] <= '7')
pos += sprintf( pos, "\\%03o", *str );
pos += snprintf( pos, sizeof(buffer) - (pos - buffer), "\\%03o", *str );
else
pos += sprintf( pos, "\\%o", *str );
pos += snprintf( pos, sizeof(buffer) - (pos - buffer), "\\%o", *str );
continue;
}
if (*str == '\\' || *str == escape[0] || *str == escape[1]) *pos++ = '\\';
......
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