Skip to content

Commit

Permalink
win32u: Replace sprintf with snprintf to avoid deprecation warnings o…
Browse files Browse the repository at this point in the history
…n macOS.
  • Loading branch information
mrpippy authored and julliard committed Apr 3, 2024
1 parent 3992a76 commit 9960702
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 83 deletions.
8 changes: 4 additions & 4 deletions dlls/win32u/defwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2967,10 +2967,10 @@ LRESULT desktop_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )

if (NtUserGetAncestor( hwnd, GA_PARENT )) return FALSE; /* refuse to create non-desktop window */

sprintf( buffer, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(unsigned int)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] );
snprintf( buffer, sizeof(buffer), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(unsigned int)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] );
NtAddAtom( bufferW, asciiz_to_unicode( bufferW, buffer ) - sizeof(WCHAR), &atom );
NtUserSetProp( hwnd, wine_display_device_guidW, ULongToHandle( atom ) );
}
Expand Down
10 changes: 5 additions & 5 deletions dlls/win32u/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ static void add_face_to_cache( struct gdi_font_face *face )
WCHAR nameW[10];
char name[10];

sprintf( name, "%d", face->size.y_ppem );
snprintf( name, sizeof(name), "%d", face->size.y_ppem );
hkey_face = reg_create_key( hkey_family, nameW,
asciiz_to_unicode( nameW, name ) - sizeof(WCHAR),
REG_OPTION_VOLATILE, NULL );
Expand Down Expand Up @@ -1411,7 +1411,7 @@ static void remove_face_from_cache( struct gdi_font_face *face )
{
WCHAR nameW[10];
char name[10];
sprintf( name, "%d", face->size.y_ppem );
snprintf( name, sizeof(name), "%d", face->size.y_ppem );
if ((hkey = reg_open_key( hkey_family, nameW,
asciiz_to_unicode( nameW, name ) - sizeof(WCHAR) )))
{
Expand Down Expand Up @@ -3143,7 +3143,7 @@ static void update_codepage( UINT screen_dpi )
RtlInitCodePageTable( NtCurrentTeb()->Peb->OemCodePageData, &oem_cp );
else
oem_cp = utf8_cp;
sprintf( cpbuf, "%u,%u", ansi_cp.CodePage, oem_cp.CodePage );
snprintf( cpbuf, sizeof(cpbuf), "%u,%u", ansi_cp.CodePage, oem_cp.CodePage );
asciiz_to_unicode( cpbufW, cpbuf );

if (query_reg_ascii_value( wine_fonts_key, "Codepages", info, sizeof(value_buffer) ))
Expand Down Expand Up @@ -6767,11 +6767,11 @@ static HKEY open_hkcu(void)
return 0;

sid = ((TOKEN_USER *)sid_data)->User.Sid;
len = sprintf( buffer, "\\Registry\\User\\S-%u-%u", (int)sid->Revision,
len = snprintf( buffer, sizeof(buffer), "\\Registry\\User\\S-%u-%u", (int)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 += snprintf( buffer + len, sizeof(buffer) - len, "-%u", (int)sid->SubAuthority[i] );
ascii_to_unicode( bufferW, buffer, len + 1 );

return reg_open_key( NULL, bufferW, len * sizeof(WCHAR) );
Expand Down
4 changes: 2 additions & 2 deletions dlls/win32u/freetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ static char **expand_mac_font(const char *path)
{
int fd;

sprintf(output, "%s/%s_%04x.ttf", out_dir, filename, font_id);
snprintf(output, output_len, "%s/%s_%04x.ttf", out_dir, filename, font_id);

fd = open(output, O_CREAT | O_EXCL | O_WRONLY, 0600);
if(fd != -1 || errno == EEXIST)
Expand Down Expand Up @@ -1456,7 +1456,7 @@ static BOOL ReadFontDir(const char *dirname, BOOL external_fonts)

TRACE("Found %s in %s\n", debugstr_a(dent->d_name), debugstr_a(dirname));

sprintf(path, "%s/%s", dirname, dent->d_name);
snprintf(path, sizeof(path), "%s/%s", dirname, dent->d_name);

if(stat(path, &statbuf) == -1)
{
Expand Down
4 changes: 2 additions & 2 deletions dlls/win32u/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,15 +1341,15 @@ BOOL WINAPI NtUserGetKeyboardLayoutName( WCHAR *name )

if (info->kbd_layout_id)
{
sprintf( buffer, "%08X", info->kbd_layout_id );
snprintf( buffer, sizeof(buffer), "%08X", info->kbd_layout_id );
asciiz_to_unicode( name, buffer );
return TRUE;
}

layout = NtUserGetKeyboardLayout( 0 );
id = HandleToUlong( layout );
if (HIWORD( id ) == LOWORD( id )) id = LOWORD( id );
sprintf( buffer, "%08X", id );
snprintf( buffer, sizeof(buffer), "%08X", id );
asciiz_to_unicode( name, buffer );

if ((hkey = reg_open_key( NULL, keyboard_layouts_keyW, sizeof(keyboard_layouts_keyW) )))
Expand Down
27 changes: 14 additions & 13 deletions dlls/win32u/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ BOOL WINAPI NtUserDestroyAcceleratorTable( HACCEL handle )

#define MENUFLAG(bit,text) \
do { \
if (flags & (bit)) { flags &= ~(bit); strcat(buf, (text)); } \
if (flags & (bit)) { flags &= ~(bit); len += snprintf(buf + len, sizeof(buf) - len, (text)); } \
} while (0)

static const char *debugstr_menuitem( const struct menu_item *item )
Expand All @@ -243,16 +243,17 @@ static const char *debugstr_menuitem( const struct menu_item *item )
"HBMMENU_POPUP_RESTORE", "HBMMENU_POPUP_MAXIMIZE", "HBMMENU_POPUP_MINIMIZE" };
char buf[256];
UINT flags;
int len;

if (!item) return "NULL";

sprintf( buf, "{ ID=0x%lx", (long)item->wID );
if (item->hSubMenu) sprintf( buf + strlen(buf), ", Sub=%p", item->hSubMenu );
len = snprintf( buf, sizeof(buf), "{ ID=0x%lx", (long)item->wID );
if (item->hSubMenu) len += snprintf( buf + len, sizeof(buf) - len, ", Sub=%p", item->hSubMenu );

flags = item->fType;
if (flags)
{
strcat( buf, ", fType=" );
len += snprintf( buf + len, sizeof(buf) - len, ", fType=" );
MENUFLAG( MFT_SEPARATOR, "sep" );
MENUFLAG( MFT_OWNERDRAW, "own" );
MENUFLAG( MFT_BITMAP, "bit" );
Expand All @@ -263,34 +264,34 @@ static const char *debugstr_menuitem( const struct menu_item *item )
MENUFLAG( MFT_RIGHTORDER, "rorder" );
MENUFLAG( MF_SYSMENU, "sys" );
MENUFLAG( MFT_RIGHTJUSTIFY, "right" ); /* same as MF_HELP */
if (flags) sprintf( buf + strlen(buf), "+0x%x", flags );
if (flags) len += snprintf( buf + len, sizeof(buf) - len, "+0x%x", flags );
}

flags = item->fState;
if (flags)
{
strcat( buf, ", State=" );
len += snprintf( buf + len, sizeof(buf) - len, ", State=" );
MENUFLAG( MFS_GRAYED, "grey" );
MENUFLAG( MFS_DEFAULT, "default" );
MENUFLAG( MFS_DISABLED, "dis" );
MENUFLAG( MFS_CHECKED, "check" );
MENUFLAG( MFS_HILITE, "hi" );
MENUFLAG( MF_USECHECKBITMAPS, "usebit" );
MENUFLAG( MF_MOUSESELECT, "mouse" );
if (flags) sprintf( buf + strlen(buf), "+0x%x", flags );
if (flags) len += snprintf( buf + len, sizeof(buf) - len, "+0x%x", flags );
}

if (item->hCheckBit) sprintf( buf + strlen(buf), ", Chk=%p", item->hCheckBit );
if (item->hUnCheckBit) sprintf( buf + strlen(buf), ", Unc=%p", item->hUnCheckBit );
if (item->text) sprintf( buf + strlen(buf), ", Text=%s", debugstr_w(item->text) );
if (item->dwItemData) sprintf( buf + strlen(buf), ", ItemData=0x%08lx", item->dwItemData );
if (item->hCheckBit) len += snprintf( buf + len, sizeof(buf) - len, ", Chk=%p", item->hCheckBit );
if (item->hUnCheckBit) len += snprintf( buf + len, sizeof(buf) - len, ", Unc=%p", item->hUnCheckBit );
if (item->text) len += snprintf( buf + len, sizeof(buf) - len, ", Text=%s", debugstr_w(item->text) );
if (item->dwItemData) len += snprintf( buf + len, sizeof(buf) - len, ", ItemData=0x%08lx", item->dwItemData );

if (item->hbmpItem)
{
if (IS_MAGIC_BITMAP( item->hbmpItem ))
sprintf( buf + strlen(buf), ", hbitmap=%s", hbmmenus[(INT_PTR)item->hbmpItem + 1] );
len += snprintf( buf + len, sizeof(buf) - len, ", hbitmap=%s", hbmmenus[(INT_PTR)item->hbmpItem + 1] );
else
sprintf( buf + strlen(buf), ", hbitmap=%p", item->hbmpItem );
len += snprintf( buf + len, sizeof(buf) - len, ", hbitmap=%p", item->hbmpItem );
}
return wine_dbg_sprintf( "%s }", buf );
}
Expand Down
6 changes: 3 additions & 3 deletions dlls/win32u/spy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2166,9 +2166,9 @@ static void SPY_GetMsgStuff( SPY_INSTANCE *sp_e )
}
}
if (sp_e->msgnum >= WM_USER && sp_e->msgnum <= WM_APP)
sprintf( sp_e->msg_name, "WM_USER+%d", sp_e->msgnum - WM_USER );
snprintf( sp_e->msg_name, sizeof(sp_e->msg_name), "WM_USER+%d", sp_e->msgnum - WM_USER );
else
sprintf( sp_e->msg_name, "%04x", sp_e->msgnum );
snprintf( sp_e->msg_name, sizeof(sp_e->msg_name), "%04x", sp_e->msgnum );
}
else
{
Expand Down Expand Up @@ -2623,7 +2623,7 @@ void spy_enter_message( INT iFlag, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
DWORD tid = get_window_thread( hWnd, NULL );

if (tid == GetCurrentThreadId()) strcpy( taskName, "self" );
else sprintf( taskName, "tid %04x", (int)GetCurrentThreadId() );
else snprintf( taskName, sizeof(taskName), "tid %04x", (int)GetCurrentThreadId() );

TRACE("%*s(%p) %-16s [%04x] %s sent from %s wp=%08lx lp=%08lx\n",
indent, "", hWnd, debugstr_w(sp_e.wnd_name), msg,
Expand Down
Loading

0 comments on commit 9960702

Please sign in to comment.