From 03e513365b530983d27dfc57cc61ab37e21a4cb2 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 31 Aug 2019 01:34:51 +0100 Subject: [PATCH] PATH_LENGTH is actually Windows's MAX_PATH When MAX_PATH isn't available, use FILENAME_MAX. This might be a bad idea. --- src/ArmsItem.cpp | 2 +- src/Back.cpp | 2 +- src/CommonDefines.h | 2 -- src/Config.cpp | 3 +-- src/Draw.cpp | 2 +- src/Ending.cpp | 2 +- src/Game.cpp | 2 +- src/Generic.cpp | 21 ++++++++++----------- src/Main.cpp | 4 ++-- src/Map.cpp | 4 ++-- src/MycParam.cpp | 4 ++-- src/NpChar.cpp | 3 +-- src/Profile.cpp | 7 +++---- src/Sound.cpp | 3 +-- src/Stage.cpp | 3 +-- src/Tags.h | 6 +++--- src/TextScr.cpp | 2 +- src/TextScr.h | 4 +--- src/WindowsWrapper.h | 6 ++++++ 19 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 83fad027..d4a8d710 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -365,7 +365,7 @@ void PutCampObject() int CampLoop() { int arms_num; - char old_script_path[PATH_LENGTH]; + char old_script_path[MAX_PATH]; RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; diff --git a/src/Back.cpp b/src/Back.cpp index a81d41f7..443503a2 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -25,7 +25,7 @@ BOOL InitBack(const char *fName, int type) color_black = GetCortBoxColor(RGB(0, 0, 0x10)); // Get width and height - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s.pbm", gDataPath, fName); FILE *fp = fopen(path, "rb"); diff --git a/src/CommonDefines.h b/src/CommonDefines.h index e280beb3..de0c7298 100644 --- a/src/CommonDefines.h +++ b/src/CommonDefines.h @@ -1,6 +1,4 @@ #pragma once -#define PATH_LENGTH 260 // Pixel had the path size locked to 260 (dangerously low), if you tried to open the executable in a path with more than around 220 characters, it'd crash. - #define WINDOW_WIDTH 320 #define WINDOW_HEIGHT 240 diff --git a/src/Config.cpp b/src/Config.cpp index 732466be..d66d1fd6 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -4,7 +4,6 @@ #include "WindowsWrapper.h" -#include "CommonDefines.h" #include "Config.h" #include "File.h" #include "Tags.h" @@ -18,7 +17,7 @@ BOOL LoadConfigData(CONFIG *conf) memset(conf, 0, sizeof(CONFIG)); // Get path - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gModulePath, config_filename); // Open file diff --git a/src/Draw.cpp b/src/Draw.cpp index 12cf8ec9..70c4f593 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -290,7 +290,7 @@ static unsigned char* LoadFileToMemory(const char *path, size_t *size) static BOOL LoadBitmap_File(const char *name, SurfaceID surf_no, BOOL create_surface) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; unsigned char *data; size_t size; diff --git a/src/Ending.cpp b/src/Ending.cpp index 0c92b428..a1eaf3d7 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -189,7 +189,7 @@ BOOL StartCreditScript() } // Open file - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gDataPath, credit_script); Credit.size = GetFileSizeLong(path); diff --git a/src/Game.cpp b/src/Game.cpp index 2513b9b2..d939bfc6 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -702,7 +702,7 @@ BOOL Game(HWND hWnd) PlaySoundObject(7, -1); - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/npc.tbl", gDataPath); if (!LoadNpcTable(path)) diff --git a/src/Generic.cpp b/src/Generic.cpp index 2a71d3db..892e8165 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -6,7 +6,6 @@ #include "WindowsWrapper.h" -#include "CommonDefines.h" #include "Tags.h" void GetCompileDate(int *year, int *month, int *day) @@ -45,7 +44,7 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) VS_FIXEDFILEINFO *lpBuffer; DWORD dwHandle; DWORD dwLen; - char path[PATH_LENGTH]; + char path[MAX_PATH]; LPVOID lpData; BOOL bResult; @@ -112,9 +111,9 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) // TODO - Inaccurate stack frame BOOL OpenVolumeConfiguration(HWND hWnd) { - char path[PATH_LENGTH]; - char path2[PATH_LENGTH]; - char path3[PATH_LENGTH]; + char path[MAX_PATH]; + char path2[MAX_PATH]; + char path3[MAX_PATH]; int error1; int error2; size_t i; @@ -142,7 +141,7 @@ BOOL OpenVolumeConfiguration(HWND hWnd) #ifdef WINDOWS void DeleteDebugLog(void) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s\\debug.txt", gModulePath); DeleteFileA(path); @@ -150,7 +149,7 @@ void DeleteDebugLog(void) BOOL PrintDebugLog(const char *string, int value1, int value2, int value3) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; FILE *fp; sprintf(path, "%s\\debug.txt", gModulePath); @@ -198,7 +197,7 @@ int CheckTime(SYSTEMTIME *system_time_low, SYSTEMTIME *system_time_high) BOOL CheckFileExists(const char *name) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; #ifdef NONPORTABLE sprintf(path, "%s\\%s", gModulePath, name); @@ -250,7 +249,7 @@ long GetFileSizeLong(const char *path) #ifdef WINDOWS BOOL PrintBitmapError(char *string, int value) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; FILE *fp; sprintf(path, "%s\\%s", gModulePath, "error.log"); @@ -320,7 +319,7 @@ BOOL CenterWindow(HWND hWnd) // TODO - Inaccurate stack frame BOOL LoadWindowRect(HWND hWnd, char *filename, BOOL unknown) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; int min_window_width; int min_window_height; int max_window_width; @@ -399,7 +398,7 @@ BOOL LoadWindowRect(HWND hWnd, char *filename, BOOL unknown) BOOL SaveWindowRect(HWND hWnd, const char *filename) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; WINDOWPLACEMENT wndpl; FILE *fp; RECT rect; diff --git a/src/Main.cpp b/src/Main.cpp index e309048d..023cd152 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -26,8 +26,8 @@ extern SDL_Window *gWindow; extern SDL_Renderer *gRenderer; -char gModulePath[PATH_LENGTH]; -char gDataPath[PATH_LENGTH]; +char gModulePath[MAX_PATH]; +char gDataPath[MAX_PATH]; int gJoystickButtonTable[8]; diff --git a/src/Map.cpp b/src/Map.cpp index 25decba2..f0cd6b9e 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -30,7 +30,7 @@ BOOL LoadMapData2(const char *path_map) unsigned char dum; // Get path - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gDataPath, path_map); // Open file @@ -80,7 +80,7 @@ BOOL LoadMapData2(const char *path_map) BOOL LoadAttributeData(const char *path_atrb) { // Open file - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gDataPath, path_atrb); FILE *fp = fopen(path, "rb"); diff --git a/src/MycParam.cpp b/src/MycParam.cpp index ede5fcdb..120421fe 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -445,7 +445,7 @@ BOOL SaveTimeCounter() return TRUE; // Get last time - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/290.rec", gModulePath); FILE *fp = fopen(path, "rb"); @@ -530,7 +530,7 @@ int LoadTimeCounter() int i; // Open file - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/290.rec", gModulePath); FILE *fp = fopen(path, "rb"); diff --git a/src/NpChar.cpp b/src/NpChar.cpp index ca83c369..bef60e69 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -7,7 +7,6 @@ #include "WindowsWrapper.h" #include "ArmsItem.h" -#include "CommonDefines.h" #include "Caret.h" #include "Draw.h" #include "File.h" @@ -60,7 +59,7 @@ BOOL LoadEvent(const char *path_event) int n; EVENT eve; - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gDataPath, path_event); fp = fopen(path, "rb"); diff --git a/src/Profile.cpp b/src/Profile.cpp index 8181a97c..b57e1300 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -10,7 +10,6 @@ #include "ArmsItem.h" #include "BossLife.h" -#include "CommonDefines.h" #include "Fade.h" #include "File.h" #include "Flags.h" @@ -30,7 +29,7 @@ const char *gProfileCode = "Do041220"; BOOL IsProfile() { - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gModulePath, gDefaultName); FILE *fp = fopen(path, "rb"); @@ -46,7 +45,7 @@ BOOL SaveProfile(const char *name) PROFILE profile; FILE *fp; const char *FLAG = "FLAG"; - char path[PATH_LENGTH]; + char path[MAX_PATH]; // Get path if (name) @@ -128,7 +127,7 @@ BOOL SaveProfile(const char *name) BOOL LoadProfile(const char *name) { // Get path - char path[PATH_LENGTH]; + char path[MAX_PATH]; if (name) sprintf(path, "%s", name); diff --git a/src/Sound.cpp b/src/Sound.cpp index 64272c2b..30da484d 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -21,7 +21,6 @@ equivalents. #include "WindowsWrapper.h" -#include "CommonDefines.h" #include "Organya.h" #include "PixTone.h" #include "Tags.h" @@ -132,7 +131,7 @@ BOOL InitSoundObject(LPCSTR resname, int no) BOOL LoadSoundObject(LPCSTR file_name, int no) { - char path[PATH_LENGTH]; + char path[MAX_PATH]; DWORD i; DWORD file_size = 0; char check_box[58]; diff --git a/src/Stage.cpp b/src/Stage.cpp index 25781595..29ab34e0 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -9,7 +9,6 @@ #include "Boss.h" #include "Bullet.h" #include "Caret.h" -#include "CommonDefines.h" #include "Draw.h" #include "Flash.h" #include "Frame.h" @@ -139,7 +138,7 @@ BOOL TransferStage(int no, int w, int x, int y) strcpy(path_dir, "Stage"); //Load tileset - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/Prt%s", path_dir, gTMT[no].parts); if (!ReloadBitmap_File(path, SURFACE_ID_LEVEL_TILESET)) bError = TRUE; diff --git a/src/Tags.h b/src/Tags.h index 6c240cab..d66bf478 100644 --- a/src/Tags.h +++ b/src/Tags.h @@ -1,6 +1,6 @@ #pragma once -#include "CommonDefines.h" +#include "WindowsWrapper.h" -extern char gModulePath[PATH_LENGTH]; -extern char gDataPath[PATH_LENGTH]; +extern char gModulePath[MAX_PATH]; +extern char gDataPath[MAX_PATH]; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index 35917069..3e039768 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -146,7 +146,7 @@ BOOL LoadTextScript2(const char *name) BOOL LoadTextScript_Stage(const char *name) { //Open Head.tsc - char path[PATH_LENGTH]; + char path[MAX_PATH]; sprintf(path, "%s/%s", gDataPath, "Head.tsc"); long head_size = GetFileSizeLong(path); diff --git a/src/TextScr.h b/src/TextScr.h index edcc5fe5..ec6f0c92 100644 --- a/src/TextScr.h +++ b/src/TextScr.h @@ -2,12 +2,10 @@ #include "WindowsWrapper.h" -#include "CommonDefines.h" - struct TEXT_SCRIPT { //Path (reload when exit teleporter menu/inventory) - char path[PATH_LENGTH]; + char path[MAX_PATH]; //Script buffer int size; diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 0cc1438f..a26e450e 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -8,6 +8,8 @@ #undef CreateWindow #else +#include + typedef int HWND; typedef int BOOL; @@ -35,6 +37,10 @@ struct RECT rect.right = r; \ rect.bottom = b; +#ifndef MAX_PATH +#define MAX_PATH FILENAME_MAX +#endif + int rep_rand(); void rep_srand(unsigned int seed);