From d489095bcdf9603053ebd514588093a991605ffb Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Fri, 9 Dec 2011 15:37:22 +0000 Subject: More string and fopen safety measures --- FoundationEx/MemDebug.cpp | 4 ++-- Stars45/Main.cpp | 2 +- nGenEx/ActiveWindow.cpp | 2 +- nGenEx/Archive.cpp | 20 ++++++++++------- nGenEx/Bitmap.cpp | 14 ++++++------ nGenEx/Bmp.cpp | 4 ++-- nGenEx/Bolt.cpp | 2 +- nGenEx/Button.cpp | 4 ++-- nGenEx/Color.cpp | 7 +++--- nGenEx/ComboBox.cpp | 4 ++-- nGenEx/D3DXImage.cpp | 5 +++-- nGenEx/DataLoader.cpp | 57 ++++++++++++++++++++++++++--------------------- nGenEx/EditBox.cpp | 4 ++-- nGenEx/FormDef.cpp | 24 ++++++++++---------- nGenEx/Game.cpp | 20 ++++++++--------- nGenEx/Graphic.cpp | 2 +- nGenEx/ImageBox.cpp | 4 ++-- nGenEx/Joystick.cpp | 2 +- nGenEx/MachineInfo.cpp | 48 +++++++++++++++++++-------------------- nGenEx/PCX.CPP | 8 +++---- nGenEx/PngImage.cpp | 12 +++++----- nGenEx/RichTextBox.cpp | 2 +- nGenEx/Sound.cpp | 6 +++-- nGenEx/SoundD3D.cpp | 4 +++- nGenEx/VideoDX9.cpp | 3 ++- 25 files changed, 140 insertions(+), 124 deletions(-) diff --git a/FoundationEx/MemDebug.cpp b/FoundationEx/MemDebug.cpp index ce8a63c..5030653 100644 --- a/FoundationEx/MemDebug.cpp +++ b/FoundationEx/MemDebug.cpp @@ -47,7 +47,7 @@ static void heapdump() hinfo._pentry = NULL; while ((heapstatus = _heapwalk( &hinfo )) == _HEAPOK) { - sprintf(report, "%6s block at %Fp of size %4.4X\n", + sprintf_s(report, "%6s block at %Fp of size %4.4X\n", ( hinfo._useflag == _USEDENTRY ? "USED" : "FREE" ), hinfo._pentry, hinfo._size); @@ -59,7 +59,7 @@ static void heapdump() avail += hinfo._size; } - sprintf(report, "------\nUsed Blocks: %d\nAvail Blocks: %d\nTotal Blocks: %d\n", used, avail, used+avail); + sprintf_s(report, "------\nUsed Blocks: %d\nAvail Blocks: %d\nTotal Blocks: %d\n", used, avail, used+avail); _RPT0(_CRT_WARN, report); switch (heapstatus) { diff --git a/Stars45/Main.cpp b/Stars45/Main.cpp index c71bd4d..6f26245 100644 --- a/Stars45/Main.cpp +++ b/Stars45/Main.cpp @@ -41,7 +41,7 @@ int dump_missions = 0; #ifdef STARSHATTER_DEMO_RELEASE const char* versionInfo = "5.0 DEMO"; #else -const char* versionInfo = "5.0.4"; +const char* versionInfo = "5.0.5"; #endif static void PrintLogHeader() diff --git a/nGenEx/ActiveWindow.cpp b/nGenEx/ActiveWindow.cpp index 4eebfa6..75b291e 100644 --- a/nGenEx/ActiveWindow.cpp +++ b/nGenEx/ActiveWindow.cpp @@ -61,7 +61,7 @@ ActiveWindow::ActiveWindow(Screen* screen, int ax, int ay, int aw, int ah, Show(); char buf[32]; - sprintf(buf, "ActiveWindow %d", id); + sprintf_s(buf, "ActiveWindow %d", id); desc = buf; } diff --git a/nGenEx/Archive.cpp b/nGenEx/Archive.cpp index dfec332..7f33676 100644 --- a/nGenEx/Archive.cpp +++ b/nGenEx/Archive.cpp @@ -191,9 +191,10 @@ void DataArchive::LoadDatafile(const char* name) delete [] block_map; ZeroMemory(this, sizeof(DataArchive)); - strncpy(datafile, name, NAMELEN-1); + strncpy_s(datafile, name, NAMELEN-1); - FILE* f = fopen(datafile, "rb"); + FILE* f; + fopen_s(&f, datafile, "rb"); if (f) { fread(&header, sizeof(DataHeader), 1, f); @@ -268,7 +269,7 @@ int DataArchive::FindEntry(const char* req_name) } for (DWORD i = 0; i < header.nfiles; i++) { - if (!stricmp(directory[i].name, path)) + if (!_stricmp(directory[i].name, path)) return i; } } @@ -283,7 +284,8 @@ BYTE* DataArchive::CompressEntry(int i) if (directory && i >= 0 && i < (int) header.nfiles) { char* name = directory[i].name; - FILE* f = fopen(name, "rb"); + FILE* f; + fopen_s(&f, name, "rb"); if (f) { fseek(f, 0, SEEK_END); @@ -329,7 +331,8 @@ int DataArchive::ExpandEntry(int i, BYTE*& buf, bool null_terminate) DWORD len = 0; if (directory && i >= 0 && i < (int) header.nfiles) { - FILE* f = fopen(datafile, "rb"); + FILE* f; + fopen_s(&f, datafile, "rb"); if (f) { DWORD clen = directory[i].size_comp; @@ -398,7 +401,7 @@ int DataArchive::InsertEntry(const char* name) for (int i = 0; i < dirsize; i++) { if (directory[i].size_orig == 0) { ZeroMemory(directory[i].name, NAMELEN); - strncpy(directory[i].name, path, NAMELEN); + strncpy_s(directory[i].name, path, NAMELEN); directory[i].name[NAMELEN-1] = '\0'; directory[i].size_orig = 1; @@ -420,7 +423,7 @@ int DataArchive::InsertEntry(const char* name) directory = dir; ZeroMemory(directory[dirsize].name, NAMELEN); - strncpy(directory[dirsize].name, path, NAMELEN); + strncpy_s(directory[dirsize].name, path, NAMELEN); directory[dirsize].name[NAMELEN-1] = '\0'; directory[dirsize].size_orig = 1; @@ -520,7 +523,8 @@ void DataArchive::Extract(const char* name) BYTE* buf; ExpandEntry(index, buf); - FILE* f = fopen(directory[index].name, "wb"); + FILE* f; + fopen_s(&f, directory[index].name, "wb"); if (f) { fwrite(buf, directory[index].size_orig, 1, f); fclose(f); diff --git a/nGenEx/Bitmap.cpp b/nGenEx/Bitmap.cpp index 54cd458..e7badbd 100644 --- a/nGenEx/Bitmap.cpp +++ b/nGenEx/Bitmap.cpp @@ -67,7 +67,7 @@ Bitmap::Bitmap() pix(0), hipix(0), mapsize(0), last_modified(0) { - strcpy(filename, "Bitmap()"); + strcpy_s(filename, "Bitmap()"); } Bitmap::Bitmap(int w, int h, ColorIndex* p, int t) @@ -76,7 +76,7 @@ Bitmap::Bitmap(int w, int h, ColorIndex* p, int t) pix(p), hipix(0), mapsize(w*h), last_modified(GetRealTime()) { - sprintf(filename, "Bitmap(%d, %d, index, type=%d)", w, h, (int) t); + sprintf_s(filename, "Bitmap(%d, %d, index, type=%d)", w, h, (int) t); } Bitmap::Bitmap(int w, int h, Color* p, int t) @@ -85,7 +85,7 @@ Bitmap::Bitmap(int w, int h, Color* p, int t) pix(0), hipix(p), mapsize(w*h), last_modified(GetRealTime()) { - sprintf(filename, "Bitmap(%d, %d, hicolor, type=%d)", w, h, (int) t); + sprintf_s(filename, "Bitmap(%d, %d, hicolor, type=%d)", w, h, (int) t); } // +--------------------------------------------------------------------+ @@ -781,13 +781,13 @@ Bitmap::SetFilename(const char* s) if (n >= 60) { ZeroMemory(filename, sizeof(filename)); - strcpy(filename, "..."); - strcat(filename, s + n - 59); + strcpy_s(filename, "..."); + strcat_s(filename, s + n - 59); filename[63] = 0; } else { - strcpy(filename, s); + strcpy_s(filename, s); } } } @@ -847,7 +847,7 @@ Bitmap* Bitmap::CheckCache(const char* filename) { for (int i = 0; i < bitmap_cache.size(); i++) { - if (!stricmp(bitmap_cache[i]->GetFilename(), filename)) { + if (!_stricmp(bitmap_cache[i]->GetFilename(), filename)) { return bitmap_cache[i]; } } diff --git a/nGenEx/Bmp.cpp b/nGenEx/Bmp.cpp index 18c5870..db81e8f 100644 --- a/nGenEx/Bmp.cpp +++ b/nGenEx/Bmp.cpp @@ -69,7 +69,7 @@ int BmpImage::Load(char *filename) int status = BMP_INVALID; FILE* f; - f = fopen(filename,"rb"); + fopen_s(&f, filename,"rb"); if (f == NULL) return BMP_NOFILE; @@ -214,7 +214,7 @@ int BmpImage::Save(char *filename) int status = BMP_INVALID; FILE* f; - f = fopen(filename,"wb"); + fopen_s(&f, filename,"wb"); if (f == NULL) return BMP_NOFILE; diff --git a/nGenEx/Bolt.cpp b/nGenEx/Bolt.cpp index af758b8..997ee51 100644 --- a/nGenEx/Bolt.cpp +++ b/nGenEx/Bolt.cpp @@ -71,7 +71,7 @@ Bolt::Bolt(double len, double wid, Bitmap* tex, int share) radius = (float) ((length>width) ? (length) : (width*2)); if (texture) { - strncpy(name, texture->GetFilename(), 31); + strncpy_s(name, texture->GetFilename(), 31); name[31] = 0; } } diff --git a/nGenEx/Button.cpp b/nGenEx/Button.cpp index 2a52b57..f69a41b 100644 --- a/nGenEx/Button.cpp +++ b/nGenEx/Button.cpp @@ -64,7 +64,7 @@ Button::Button(Screen* s, int ax, int ay, int aw, int ah, DWORD aid) transition_image = 0; char buf[32]; - sprintf(buf, "Button %d", id); + sprintf_s(buf, "Button %d", id); desc = buf; } @@ -87,7 +87,7 @@ Button::Button(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid) transition_image = 0; char buf[32]; - sprintf(buf, "Button %d", id); + sprintf_s(buf, "Button %d", id); desc = buf; } diff --git a/nGenEx/Color.cpp b/nGenEx/Color.cpp index 05f5fa2..55ea071 100644 --- a/nGenEx/Color.cpp +++ b/nGenEx/Color.cpp @@ -503,8 +503,9 @@ Color::SavePalette(const char* basename) { char filename[256]; - sprintf(filename, "%s.ipl", basename); - FILE* f = fopen(filename, "wb"); + sprintf_s(filename, "%s.ipl", basename); + FILE* f; + fopen_s(&f, filename, "wb"); if (f) { fwrite(table, sizeof(table), 1, f); fclose(f); @@ -599,7 +600,7 @@ Color::SaveShadeTable(const char* basename) return; char filename[256]; - sprintf(filename, "%s_clut.pcx", basename); + sprintf_s(filename, "%s_clut.pcx", basename); BYTE clut[256*256]; BYTE* pc = clut; diff --git a/nGenEx/ComboBox.cpp b/nGenEx/ComboBox.cpp index 82880de..29cc87f 100644 --- a/nGenEx/ComboBox.cpp +++ b/nGenEx/ComboBox.cpp @@ -43,7 +43,7 @@ ComboBox::ComboBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid) bevel_width = 5; char buf[32]; - sprintf(buf, "ComboBox %d", id); + sprintf_s(buf, "ComboBox %d", id); desc = buf; } @@ -61,7 +61,7 @@ ComboBox::ComboBox(Screen* s, int ax, int ay, int aw, int ah, DWORD aid) bevel_width = 5; char buf[32]; - sprintf(buf, "ComboBox %d", id); + sprintf_s(buf, "ComboBox %d", id); desc = buf; } diff --git a/nGenEx/D3DXImage.cpp b/nGenEx/D3DXImage.cpp index 3300253..721f0e9 100644 --- a/nGenEx/D3DXImage.cpp +++ b/nGenEx/D3DXImage.cpp @@ -52,7 +52,7 @@ bool D3DXImage::Load(char *filename) bool success = false; FILE* f; - f = fopen(filename,"rb"); + fopen_s(&f, filename,"rb"); if (f == NULL) return success; @@ -162,7 +162,8 @@ bool D3DXImage::Save(char *filename) if (!image || !width || !height) return success; - FILE* f = fopen(filename,"wb"); + FILE* f; + fopen_s(&f, filename,"wb"); if (f == NULL) return success; diff --git a/nGenEx/DataLoader.cpp b/nGenEx/DataLoader.cpp index 354232b..2f7d5a3 100644 --- a/nGenEx/DataLoader.cpp +++ b/nGenEx/DataLoader.cpp @@ -91,7 +91,9 @@ DataLoader::EnableDatafile(const char* name) { int status = DATAFILE_NOTEXIST; - FILE* f = fopen(name, "rb"); + FILE* f; + fopen_s(&f, name, "rb"); + if (f) { ::fclose(f); @@ -162,12 +164,13 @@ DataLoader::FindFile(const char* name) { // assemble file name: char filename[1024]; - strcpy(filename, datapath); - strcat(filename, name); + strcpy_s(filename, datapath); + strcat_s(filename, name); // first check current directory: if (use_file_system) { - FILE* f = ::fopen(filename, "rb"); + FILE* f; + ::fopen_s(&f, filename, "rb"); if (f) { ::fclose(f); @@ -217,7 +220,7 @@ DataLoader::ListArchiveFiles(const char* archive_name, const char* filter, List< for (int i = 0; i < narchives && !a; i++) { a = archives[narchives-1-i]; - if (stricmp(a->Name(), archive_name)) + if (_stricmp(a->Name(), archive_name)) a = 0; } } @@ -295,12 +298,12 @@ DataLoader::ListFileSystem(const char* filter, List& list, Text base_path, // assemble win32 find filter: char win32_filter[1024]; - strcpy(win32_filter, datapath); + strcpy_s(win32_filter, datapath); if (recurse) - strcat(win32_filter, "*.*"); + strcat_s(win32_filter, "*.*"); else - strcat(win32_filter, filter); + strcat_s(win32_filter, filter); // first check current directory: WIN32_FIND_DATA data; @@ -345,12 +348,13 @@ DataLoader::LoadBuffer(const char* name, BYTE*& buf, bool null_terminate, bool o // assemble file name: char filename[1024]; - strcpy(filename, datapath); - strcat(filename, name); + strcpy_s(filename, datapath); + strcat_s(filename, name); if (use_file_system) { // first check current directory: - FILE* f = ::fopen(filename, "rb"); + FILE* f; + ::fopen_s(&f, filename, "rb"); if (f) { ::fseek(f, 0, SEEK_END); @@ -413,11 +417,12 @@ DataLoader::LoadPartialFile(const char* name, BYTE*& buf, int max_load, bool opt // assemble file name: char filename[1024]; - strcpy(filename, datapath); - strcat(filename, name); + strcpy_s(filename, datapath); + strcat_s(filename, name); // first check current directory: - FILE* f = ::fopen(filename, "rb"); + FILE* f; + ::fopen_s(&f, filename, "rb"); if (f) { ::fseek(f, 0, SEEK_END); @@ -522,8 +527,8 @@ DataLoader::LoadTexture(const char* name, Bitmap*& bitmap, int type, bool preloa // assemble file name: char filename[256]; - strcpy(filename, datapath); - strcat(filename, name); + strcpy_s(filename, datapath); + strcat_s(filename, name); // search cache: bitmap = Bitmap::CheckCache(filename); @@ -575,8 +580,8 @@ DataLoader::LoadIndexed(const char* name, Bitmap& bitmap, int type) // assemble file name: char filename[256]; - strcpy(filename, datapath); - strcat(filename, name); + strcpy_s(filename, datapath); + strcat_s(filename, name); // first try to load from current directory: bool loaded = false; @@ -659,7 +664,7 @@ DataLoader::LoadHiColor(const char* name, Bitmap& bitmap, int type) // check for a matching high color bitmap: char filename[256]; char name2[256]; - strcpy(name2, name); + strcpy_s(name2, name); char* dot = strrchr(name2, '.'); if (dot && pcx_file) @@ -671,8 +676,8 @@ DataLoader::LoadHiColor(const char* name, Bitmap& bitmap, int type) else return result; - strcpy(filename, datapath); - strcat(filename, name2); + strcpy_s(filename, datapath); + strcat_s(filename, name2); // first try to load from current directory: bool loaded = false; @@ -741,7 +746,7 @@ DataLoader::LoadAlpha(const char* name, Bitmap& bitmap, int type) // check for an associated alpha-only (grayscale) bitmap: char filename[256]; char name2[256]; - strcpy(name2, name); + strcpy_s(name2, name); char* dot = strrchr(name2, '.'); if (dot && pcx_file) strcpy(dot, "@.pcx"); @@ -754,8 +759,8 @@ DataLoader::LoadAlpha(const char* name, Bitmap& bitmap, int type) else return 0; - strcpy(filename, datapath); - strcat(filename, name2); + strcpy_s(filename, datapath); + strcat_s(filename, name2); // first try to load from current directory: bool loaded = false; @@ -987,8 +992,8 @@ DataLoader::LoadStream(const char* name, Sound*& snd, bool optional) if (snd) { // assemble file name: char filename[1024]; - strcpy(filename, datapath); - strcat(filename, name); + strcpy_s(filename, datapath); + strcat_s(filename, name); snd->StreamFile(filename, p - buf); diff --git a/nGenEx/EditBox.cpp b/nGenEx/EditBox.cpp index 0cc780d..bc78a1f 100644 --- a/nGenEx/EditBox.cpp +++ b/nGenEx/EditBox.cpp @@ -39,7 +39,7 @@ EditBox::EditBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid) selected_color = Color::Yellow; char buf[32]; - sprintf(buf, "EditBox %d", id); + sprintf_s(buf, "EditBox %d", id); desc = buf; } @@ -54,7 +54,7 @@ EditBox::EditBox(Screen* s, int ax, int ay, int aw, int ah, DWORD aid) selected_color = Color::Yellow; char buf[32]; - sprintf(buf, "EditBox %d", id); + sprintf_s(buf, "EditBox %d", id); desc = buf; } diff --git a/nGenEx/FormDef.cpp b/nGenEx/FormDef.cpp index 9cef31f..125fb94 100644 --- a/nGenEx/FormDef.cpp +++ b/nGenEx/FormDef.cpp @@ -565,11 +565,11 @@ static char path_name[64]; void FormDef::Load(const char* fname) { - sprintf(filename, "%s.frm", fname); + sprintf_s(filename, "%s.frm", fname); Print("Loading Form '%s'\n", fname); - sprintf(path_name, "Screens/"); + sprintf_s(path_name, "Screens/"); // Load Design File: DataLoader* loader = DataLoader::GetLoader(); @@ -686,7 +686,7 @@ FormDef::Load(const char* fname) GetDefText(buf, pdef, filename); if (*buf && !strchr(buf, '.')) - strcat(buf, ".pcx"); + strcat_s(buf, ".pcx"); form->SetTexture(buf); } @@ -708,11 +708,11 @@ FormDef::Load(const char* fname) DWORD a = DT_LEFT; if (GetDefText(buf, pdef, filename)) { - if (!stricmp(buf, "left")) + if (!_stricmp(buf, "left")) a = DT_LEFT; - else if (!stricmp(buf, "right")) + else if (!_stricmp(buf, "right")) a = DT_RIGHT; - else if (!stricmp(buf, "center")) + else if (!_stricmp(buf, "center")) a = DT_CENTER; } @@ -1052,11 +1052,11 @@ void FormDef::ParseCtrlDef(CtrlDef* ctrl, TermStruct* val) DWORD a = DT_LEFT; if (GetDefText(buf, pdef, filename)) { - if (!stricmp(buf, "left")) + if (!_stricmp(buf, "left")) a = DT_LEFT; - else if (!stricmp(buf, "right")) + else if (!_stricmp(buf, "right")) a = DT_RIGHT; - else if (!stricmp(buf, "center")) + else if (!_stricmp(buf, "center")) a = DT_CENTER; } @@ -1194,11 +1194,11 @@ void FormDef::ParseColumnDef(CtrlDef* ctrl, TermStruct* val) align = DT_LEFT; if (GetDefText(buf, pdef, filename)) { - if (!stricmp(buf, "left")) + if (!_stricmp(buf, "left")) align = DT_LEFT; - else if (!stricmp(buf, "right")) + else if (!_stricmp(buf, "right")) align = DT_RIGHT; - else if (!stricmp(buf, "center")) + else if (!_stricmp(buf, "center")) align = DT_CENTER; } diff --git a/nGenEx/Game.cpp b/nGenEx/Game.cpp index 8c20432..b9d1f25 100644 --- a/nGenEx/Game.cpp +++ b/nGenEx/Game.cpp @@ -790,7 +790,7 @@ Game::LoadPalette(PALETTEENTRY* pal, BYTE* inv) DataLoader* loader = DataLoader::GetLoader(); BYTE* block; char fname[256]; - sprintf(fname, "%s.pal", palette_name); + sprintf_s(fname, "%s.pal", palette_name); if (!loader->LoadBuffer(fname, block)) { Print(" Could not open file '%s'\n", fname); @@ -806,7 +806,7 @@ Game::LoadPalette(PALETTEENTRY* pal, BYTE* inv) loader->ReleaseBuffer(block); - sprintf(fname, "%s.ipl", palette_name); + sprintf_s(fname, "%s.ipl", palette_name); int size = loader->LoadBuffer(fname, block); if (size < 32768) { Print(" Could not open file '%s'\n", fname); @@ -866,7 +866,7 @@ Game::Panic(const char* msg) else Print("*** PANIC! ***\n"); if (!msg) msg = "Unspecified fatal error."; - sprintf(panicbuf, "%s\nThis game will now terminate.", msg); + sprintf_s(panicbuf, "%s\nThis game will now terminate.", msg); if (game) { game->status = PANIC; @@ -1116,7 +1116,7 @@ Game::ScreenCapture(const char* name) Text* s = shot_list[i]; int n = 0; - sscanf(s->data()+1, "%d", &n); + sscanf_s(s->data()+1, "%d", &n); if (shot_num <= (DWORD) n) shot_num = n+1; } @@ -1125,9 +1125,9 @@ Game::ScreenCapture(const char* name) } if (name) - strcpy(filename, name); + strcpy_s(filename, name); else - sprintf(filename, "A%d.PCX", shot_num++); + sprintf_s(filename, "A%d.PCX", shot_num++); Bitmap bmp; @@ -1165,7 +1165,7 @@ Game::AVICapture(const char* name) Text* s = avi_list[i]; int n = 0; - sscanf(s->data()+1, "%d", &n); + sscanf_s(s->data()+1, "%d", &n); if (avi_num <= (DWORD) n) avi_num = n+1; } @@ -1174,9 +1174,9 @@ Game::AVICapture(const char* name) } if (name) - strcpy(filename, name); + strcpy_s(filename, name); else - sprintf(filename, "A%d.avi", avi_num); + sprintf_s(filename, "A%d.avi", avi_num); if (video && video->Capture(bmp)) { //bmp.ScaleTo(bmp.Width()/2, bmp.Height()/2); @@ -1517,7 +1517,7 @@ GetKeyPlus(int& key, int& shift) void Print(const char* fmt, ...) { if (ErrLog) { - vsprintf(ErrBuf, fmt, (char *)(&fmt+1)); + vsprintf_s(ErrBuf, fmt, (char *)(&fmt+1)); fprintf(ErrLog, ErrBuf); fflush(ErrLog); diff --git a/nGenEx/Graphic.cpp b/nGenEx/Graphic.cpp index 7d63301..5cdf14e 100644 --- a/nGenEx/Graphic.cpp +++ b/nGenEx/Graphic.cpp @@ -34,7 +34,7 @@ Graphic::Graphic() screen_rect.h = 0; ZeroMemory(name, sizeof(name)); - strcpy(name, "Graphic"); + strcpy_s(name, "Graphic"); } // +--------------------------------------------------------------------+ diff --git a/nGenEx/ImageBox.cpp b/nGenEx/ImageBox.cpp index 36b866d..144e1d4 100644 --- a/nGenEx/ImageBox.cpp +++ b/nGenEx/ImageBox.cpp @@ -28,7 +28,7 @@ ImageBox::ImageBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid) text_align = DT_CENTER; char buf[32]; - sprintf(buf, "ImageBox %d", id); + sprintf_s(buf, "ImageBox %d", id); desc = buf; } @@ -39,7 +39,7 @@ ImageBox::ImageBox(Screen* s, int ax, int ay, int aw, int ah, DWORD aid) text_align = DT_CENTER; char buf[32]; - sprintf(buf, "ImageBox %d", id); + sprintf_s(buf, "ImageBox %d", id); desc = buf; } diff --git a/nGenEx/Joystick.cpp b/nGenEx/Joystick.cpp index a2b80af..22dbfba 100644 --- a/nGenEx/Joystick.cpp +++ b/nGenEx/Joystick.cpp @@ -837,7 +837,7 @@ char* DIErrStr(HRESULT hr) { switch (hr) { default: - sprintf(errstrbuf, "Unrecognized error value = %08x.", hr); + sprintf_s(errstrbuf, "Unrecognized error value = %08x.", hr); return errstrbuf; case DI_OK: diff --git a/nGenEx/MachineInfo.cpp b/nGenEx/MachineInfo.cpp index 89e6a47..b281c36 100644 --- a/nGenEx/MachineInfo.cpp +++ b/nGenEx/MachineInfo.cpp @@ -74,7 +74,7 @@ MachineInfo::GetShortDescription() if (os_index < 0) os_index = 0; else if (os_index > 5) os_index = 5; - sprintf(desc, "%s %d MHz %d MB RAM %s", + sprintf_s(desc, "%s %d MHz %d MB RAM %s", cpu_names[cpu_index], GetCpuSpeed(), GetTotalRam(), @@ -233,7 +233,7 @@ MachineInfo::GetPlatform() default: case VER_PLATFORM_WIN32s: { char msg[256]; - sprintf(msg, "Invalid Operating System Platform: %d\n", os_ver.dwPlatformId); + sprintf_s(msg, "Invalid Operating System Platform: %d\n", os_ver.dwPlatformId); Print(msg); } break; @@ -293,7 +293,7 @@ MachineInfo::DescribeMachine() switch (platform) { case OS_WIN95: - sprintf(txt, "Windows 95 version %d.%d.%d %s", + sprintf_s(txt, "Windows 95 version %d.%d.%d %s", os_ver.dwMajorVersion, os_ver.dwMinorVersion, LOWORD(os_ver.dwBuildNumber), @@ -301,7 +301,7 @@ MachineInfo::DescribeMachine() break; case OS_WIN98: - sprintf(txt, "Windows 98 version %d.%d.%d %s", + sprintf_s(txt, "Windows 98 version %d.%d.%d %s", os_ver.dwMajorVersion, os_ver.dwMinorVersion, LOWORD(os_ver.dwBuildNumber), @@ -309,7 +309,7 @@ MachineInfo::DescribeMachine() break; case OS_WINNT: - sprintf(txt, "Windows NT %d.%d (Build %d) %s", + sprintf_s(txt, "Windows NT %d.%d (Build %d) %s", os_ver.dwMajorVersion, os_ver.dwMinorVersion, os_ver.dwBuildNumber, @@ -317,14 +317,14 @@ MachineInfo::DescribeMachine() break; case OS_WIN2K: - sprintf(txt, "Windows 2000 %d.%d (Build %d) %s", + sprintf_s(txt, "Windows 2000 %d.%d (Build %d) %s", os_ver.dwMajorVersion, os_ver.dwMinorVersion, os_ver.dwBuildNumber, os_ver.szCSDVersion); case OS_WINXP: - sprintf(txt, "Windows XP %d.%d (Build %d) %s", + sprintf_s(txt, "Windows XP %d.%d (Build %d) %s", os_ver.dwMajorVersion, os_ver.dwMinorVersion, os_ver.dwBuildNumber, @@ -332,7 +332,7 @@ MachineInfo::DescribeMachine() break; default: - sprintf(txt, "Unknown Operating System Platform"); + sprintf_s(txt, "Unknown Operating System Platform"); break; } @@ -344,7 +344,7 @@ MachineInfo::DescribeMachine() else DescribeOwnerNT(); - sprintf(txt, "CPUs Detected: %d CPU Level: %d.%d.%d CPU Speed: %d", + sprintf_s(txt, "CPUs Detected: %d CPU Level: %d.%d.%d CPU Speed: %d", cpu_info.dwNumberOfProcessors, cpu_info.wProcessorLevel, cpu_info.wProcessorRevision >> 8, @@ -359,7 +359,7 @@ MachineInfo::DescribeMachine() int swap_max = (int) (mem_info.dwTotalPageFile/(1024*1024)); int swap_avail = (int) (mem_info.dwAvailPageFile/(1024*1024)); - sprintf(txt, "%d MB RAM %d MB Max Swap %d MB Avail Swap", + sprintf_s(txt, "%d MB RAM %d MB Max Swap %d MB Avail Swap", total_ram, swap_max, swap_avail); @@ -482,7 +482,7 @@ static void DescribeOwner95() if (sRegisteredOwner[0]) { char txt[256]; - sprintf(txt, "Registered Owner: %s, %s", sRegisteredOwner, sRegisteredOrganization); + sprintf_s(txt, "Registered Owner: %s, %s", sRegisteredOwner, sRegisteredOrganization); Print("| %-66s |\n", txt); Print("| |\n"); } @@ -525,7 +525,7 @@ static void DescribeOwnerNT() if (sRegisteredOwner[0]) { char txt[256]; - sprintf(txt, "Registered Owner: %s, %s", sRegisteredOwner, sRegisteredOrganization); + sprintf_s(txt, "Registered Owner: %s, %s", sRegisteredOwner, sRegisteredOrganization); Print("| %-66s |\n", txt); Print("| |\n"); } @@ -548,8 +548,8 @@ static void DescribeDrivers95(const char* sType) do { worked = 0; - sprintf(sKey, "System\\CurrentControlSet\\Services\\Class\\%s\\%04X", sType, nKey); - sprintf(sSub, "System\\CurrentControlSet\\Services\\Class\\%s\\%04X\\DEFAULT", sType, nKey); + sprintf_s(sKey, "System\\CurrentControlSet\\Services\\Class\\%s\\%04X", sType, nKey); + sprintf_s(sSub, "System\\CurrentControlSet\\Services\\Class\\%s\\%04X\\DEFAULT", sType, nKey); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKey, @@ -566,7 +566,7 @@ static void DescribeDrivers95(const char* sType) &dwSize); if (sDriver[0]) { - sprintf(txt, "* %s", sDriver); + sprintf_s(txt, "* %s", sDriver); Print("| %-66s |\n", txt); worked = 1; } @@ -650,7 +650,7 @@ static void DescribeDriversNT(const char* sType) const char* sLeader = "\\REGISTRY\\Machine\\"; int nLeader = strlen(sLeader); - if (strnicmp(sVideo, sLeader, nLeader) == 0) { + if (_strnicmp(sVideo, sLeader, nLeader) == 0) { if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, sVideo + nLeader, 0, @@ -689,7 +689,7 @@ static void GetTranslation(const LPBYTE pBlock) (LPVOID*) &sData, &lenData)) { if (lenData && sData) { - sprintf(sTranslation, "%02X%02X%02X%02X", sData[1], sData[0], sData[3], sData[2]); + sprintf_s(sTranslation, "%02X%02X%02X%02X", sData[1], sData[0], sData[3], sData[2]); } } } @@ -699,7 +699,7 @@ void DisplayVersionString(const LPBYTE pBlock, LPTSTR sSection) char txt[256]; char sFullSection[256]; - sprintf(sFullSection, "\\StringFileInfo\\%s\\%s", sTranslation, sSection); + sprintf_s(sFullSection, "\\StringFileInfo\\%s\\%s", sTranslation, sSection); LPBYTE sData = NULL; UINT lenData = 0; @@ -707,7 +707,7 @@ void DisplayVersionString(const LPBYTE pBlock, LPTSTR sSection) if (VerQueryValue(pBlock, sFullSection, (LPVOID*) &sData, &lenData)) { if (lenData && sData) { - sprintf(txt, "%-16s %s", sSection, sData); + sprintf_s(txt, "%-16s %s", sSection, sData); Print("| %-60s |\n", txt); } } @@ -718,14 +718,14 @@ static void DescribeDriverVersion(const char* file) DWORD dwHandle = 0; TCHAR szFile[512]; - strcpy(szFile, file); + strcpy_s(szFile, file); int nBytes = GetFileVersionInfoSize(szFile, &dwHandle); if (nBytes <= 0) { char szWinDir[256]; GetSystemDirectory(szWinDir, 256); - sprintf(szFile, "%s\\%s", szWinDir, file); + sprintf_s(szFile, "%s\\%s", szWinDir, file); nBytes = GetFileVersionInfoSize(szFile, &dwHandle); @@ -762,7 +762,7 @@ static void DescribeDXVersion(const char* component) GetSystemDirectory(szWinDir, 512); - sprintf(szFile, "%s\\%s.dll", szWinDir, component); + sprintf_s(szFile, "%s\\%s.dll", szWinDir, component); int nBytes = GetFileVersionInfoSize(szFile, &dwHandle); @@ -781,11 +781,11 @@ static void DescribeDXVersion(const char* component) UINT lenData = 0; DWORD dwErr = 0; - sprintf(sFullSection, "\\StringFileInfo\\%s\\FileVersion", sTranslation); + sprintf_s(sFullSection, "\\StringFileInfo\\%s\\FileVersion", sTranslation); if (VerQueryValue(pBlock, sFullSection, (LPVOID*) &sData, &lenData)) { if (lenData && sData) { - sprintf(txt, "%-8s%s", component, sData); + sprintf_s(txt, "%-8s%s", component, sData); Print("| %-64s |\n", txt); } } diff --git a/nGenEx/PCX.CPP b/nGenEx/PCX.CPP index 9782060..095df11 100644 --- a/nGenEx/PCX.CPP +++ b/nGenEx/PCX.CPP @@ -112,7 +112,7 @@ PcxImage::PcxImage(short w, short h, unsigned char* bits, unsigned char* colors) bitmap = new(__FILE__,__LINE__) unsigned char [imagebytes]; if (bitmap) { - for (int i = 0; i < imagebytes; i++) + for (unsigned long i = 0; i < imagebytes; i++) bitmap[i] = bits[i]; unsigned char* p = pal; @@ -205,7 +205,7 @@ PcxImage::PcxImage(short w, short h, unsigned long* hibits) himap = new(__FILE__,__LINE__) unsigned long [imagebytes]; if (himap) { - for (int i = 0; i < imagebytes; i++) + for (unsigned long i = 0; i < imagebytes; i++) himap[i] = hibits[i]; } } @@ -225,7 +225,7 @@ int PcxImage::Load(char *filename) unsigned char abyte, *p; FILE *f; - f = fopen(filename,"rb"); + fopen_s(&f, filename,"rb"); if (f == NULL) return PCX_NOFILE; @@ -437,7 +437,7 @@ int PcxImage::Save(char *filename) short mode=BYTEMODE; FILE *f; - f = fopen(filename,"wb"); + fopen_s(&f, filename,"wb"); if (f == NULL) return PCX_NOFILE; diff --git a/nGenEx/PngImage.cpp b/nGenEx/PngImage.cpp index 3f429ec..abfac7d 100644 --- a/nGenEx/PngImage.cpp +++ b/nGenEx/PngImage.cpp @@ -45,7 +45,7 @@ int PngImage::Load(char *filename) int status = PNG_INVALID; FILE* f; - f = fopen(filename,"rb"); + fopen_s(&f, filename,"rb"); if (f == NULL) return PNG_NOFILE; @@ -208,11 +208,11 @@ PngImage::CreateImage(png_structp png_ptr, png_infop info_ptr) // paletted: else if (bpp == 8) { DWORD pal[256]; - - png_bytep trans_alpha; int num_trans; png_color_16p trans_color; - png_colorp palette; - int num_palette; - + + png_bytep trans_alpha; int num_trans; png_color_16p trans_color; + png_colorp palette; + int num_palette; + png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color); png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); diff --git a/nGenEx/RichTextBox.cpp b/nGenEx/RichTextBox.cpp index 6b8bff0..c03f6d0 100644 --- a/nGenEx/RichTextBox.cpp +++ b/nGenEx/RichTextBox.cpp @@ -31,7 +31,7 @@ RichTextBox::RichTextBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD leading = 2; char buf[32]; - sprintf(buf, "RichTextBox %d", id); + sprintf_s(buf, "RichTextBox %d", id); desc = buf; } diff --git a/nGenEx/Sound.cpp b/nGenEx/Sound.cpp index b6ef695..b8e502a 100644 --- a/nGenEx/Sound.cpp +++ b/nGenEx/Sound.cpp @@ -59,7 +59,8 @@ Sound::CreateStream(const char* filename) LPBYTE p = 0; int len = 0; - FILE* f = ::fopen(filename, "rb"); + FILE* f; + ::fopen_s(&f, filename, "rb"); if (f) { fseek(f, 0, SEEK_END); @@ -157,7 +158,8 @@ Sound::CreateOggStream(const char* filename) WAVEFORMATEX wfex; ZeroMemory(&wfex, sizeof(wfex)); - FILE* f = ::fopen(filename, "rb"); + FILE* f; + ::fopen_s(&f, filename, "rb"); if (f) { OggVorbis_File* povf = new(__FILE__,__LINE__) OggVorbis_File; diff --git a/nGenEx/SoundD3D.cpp b/nGenEx/SoundD3D.cpp index fb4000e..45c5c0d 100644 --- a/nGenEx/SoundD3D.cpp +++ b/nGenEx/SoundD3D.cpp @@ -835,8 +835,10 @@ SoundD3D::StreamFile(const char* name, DWORD offset) min_safety = safety_zone; read_size = buf_size; + fopen_s(&stream, name, "rb"); + // open the stream: - if ((stream = fopen(name, "rb")) == 0) { + if (stream == 0) { SoundD3DError("StreamFile: could not open stream", E_FAIL); return E_FAIL; } diff --git a/nGenEx/VideoDX9.cpp b/nGenEx/VideoDX9.cpp index d54ae1e..0cf6eda 100644 --- a/nGenEx/VideoDX9.cpp +++ b/nGenEx/VideoDX9.cpp @@ -656,7 +656,8 @@ VideoDX9::CreateBuffers() magic_fx_code_len = loader->LoadBuffer("magic.fx", magic_fx_code, true, true); } else { - FILE* f = ::fopen("magic.fx", "rb"); + FILE* f; + ::fopen_s(&f, "magic.fx", "rb"); if (f) { ::fseek(f, 0, SEEK_END); -- cgit v1.1