From d7fc00757d1cfe1b985786c3b0f000eefc4acd9b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 29 Jul 2012 18:46:52 +0200 Subject: [PATCH] (Xbox 1) Change sprintfs to snprintfs --- xbox1/frontend/RetroLaunch/IoSupport.cpp | 28 ++++++++++-------------- xbox1/frontend/RetroLaunch/IoSupport.h | 8 +++---- xbox1/xdk_d3d8.cpp | 4 ++-- xdk/xdk_resources.cpp | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/xbox1/frontend/RetroLaunch/IoSupport.cpp b/xbox1/frontend/RetroLaunch/IoSupport.cpp index 53fc5c6528..37ebc411f3 100644 --- a/xbox1/frontend/RetroLaunch/IoSupport.cpp +++ b/xbox1/frontend/RetroLaunch/IoSupport.cpp @@ -28,13 +28,13 @@ CIoSupport::~CIoSupport() // szDrive e.g. "D:" // szDevice e.g. "Cdrom0" or "Harddisk0\Partition6" -HRESULT CIoSupport::Mount(CHAR* szDrive, CHAR* szDevice) +HRESULT CIoSupport::Mount(char *szDrive, char *szDevice) { - CHAR szSourceDevice[48]; - CHAR szDestinationDrive[16]; + char szSourceDevice[48]; + char szDestinationDrive[16]; - sprintf(szSourceDevice, "\\Device\\%s", szDevice); - sprintf(szDestinationDrive, "\\??\\%s", szDrive); + snprintf(szSourceDevice, sizeof(szSourceDevice), "\\Device\\%s", szDevice); + snprintf(szDestinationDrive, sizeof(szDestinationDrive), "\\??\\%s", szDrive); STRING DeviceName = { @@ -59,10 +59,10 @@ HRESULT CIoSupport::Mount(CHAR* szDrive, CHAR* szDevice) // szDrive e.g. "D:" -HRESULT CIoSupport::Unmount(CHAR* szDrive) +HRESULT CIoSupport::Unmount(char *szDrive) { char szDestinationDrive[16]; - sprintf(szDestinationDrive, "\\??\\%s", szDrive); + snprintf(szDestinationDrive, sizeof(szDestinationDrive), "\\??\\%s", szDrive); STRING LinkName = { @@ -76,14 +76,10 @@ HRESULT CIoSupport::Unmount(CHAR* szDrive) return S_OK; } - - - - -HRESULT CIoSupport::Remount(CHAR* szDrive, CHAR* szDevice) +HRESULT CIoSupport::Remount(char *szDrive, char *szDevice) { - CHAR szSourceDevice[48]; - sprintf(szSourceDevice, "\\Device\\%s", szDevice); + char szSourceDevice[48]; + snprintf(szSourceDevice, sizeof(szSourceDevice), "\\Device\\%s", szDevice); Unmount(szDrive); @@ -117,12 +113,12 @@ HRESULT CIoSupport::Remount(CHAR* szDrive, CHAR* szDevice) return S_OK; } -HRESULT CIoSupport::Remap(CHAR* szMapping) +HRESULT CIoSupport::Remap(char *szMapping) { char szMap[32]; strlcpy(szMap, szMapping, sizeof(szMap)); - char* pComma = strstr(szMap, ","); + char *pComma = strstr(szMap, ","); if (pComma) { *pComma = 0; diff --git a/xbox1/frontend/RetroLaunch/IoSupport.h b/xbox1/frontend/RetroLaunch/IoSupport.h index 14268e6b25..32224397e2 100644 --- a/xbox1/frontend/RetroLaunch/IoSupport.h +++ b/xbox1/frontend/RetroLaunch/IoSupport.h @@ -28,11 +28,11 @@ public: CIoSupport(); virtual ~CIoSupport(); - HRESULT Mount(CHAR* szDrive, CHAR* szDevice); - HRESULT Unmount(CHAR* szDrive); + HRESULT Mount(char *szDrive, char *szDevice); + HRESULT Unmount(char *szDrive); - HRESULT Remount(CHAR* szDrive, CHAR* szDevice); - HRESULT Remap(CHAR* szMapping); + HRESULT Remount(char *szDrive, char *szDevice); + HRESULT Remap(char *szMapping); DWORD GetTrayState(); HRESULT EjectTray(); diff --git a/xbox1/xdk_d3d8.cpp b/xbox1/xdk_d3d8.cpp index 0927996a65..ceecbd9ecb 100644 --- a/xbox1/xdk_d3d8.cpp +++ b/xbox1/xdk_d3d8.cpp @@ -454,7 +454,7 @@ static bool xdk_d3d_frame(void *data, const void *frame, char buf[128], buf2[128], buf_fps_last[128]; bool ret = false; - sprintf(buf, "%.2f MB free / %.2f MB total", stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f)); + snprintf(buf, sizeof(buf), "%.2f MB free / %.2f MB total", stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f)); convert_char_to_wchar(strw_buffer, buf, sizeof(strw_buffer)); d3d->debug_font->TextOut(d3d->pFrontBuffer, strw_buffer, (unsigned)-1, font_x + 30, font_y + 50 ); d3d->debug_font->TextOut(d3d->pBackBuffer, strw_buffer, (unsigned)-1, font_x + 30, font_y + 50 ); @@ -463,7 +463,7 @@ static bool xdk_d3d_frame(void *data, const void *frame, { if(ret) { - sprintf(buf_fps_last, buf2); + snprintf(buf_fps_last, sizeof(buf_fps_last), buf2); convert_char_to_wchar(strw_buffer, buf2, sizeof(strw_buffer)); } else if(buf_fps_last) diff --git a/xdk/xdk_resources.cpp b/xdk/xdk_resources.cpp index 285132f83d..7df3a4902e 100644 --- a/xdk/xdk_resources.cpp +++ b/xdk/xdk_resources.cpp @@ -107,8 +107,8 @@ static HRESULT FindMediaFile( char *strPath, const char *strFilename, size_t str // Check for the ':' character to see if the filename is a fully // qualified path. If not, pre-pend the media directory - if( strFilename[1] != ':' ) - sprintf( strPath, "%s%s", g_strMediaPath, strFilename ); + if(strFilename[1] != ':') + snprintf(strPath, strPathsize, "%s%s", g_strMediaPath, strFilename); // Try to open the file HANDLE hFile = CreateFile( strPath, GENERIC_READ, FILE_SHARE_READ, NULL,