diff options
author | rubidium <rubidium@openttd.org> | 2009-04-10 20:37:05 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-10 20:37:05 +0000 |
commit | bee930f9b3b9dad52945c1186227519cf9d566aa (patch) | |
tree | 4316044d109b49be7854ac19dd38cbc7d94367c1 | |
parent | 4bf35086802f6f778e987cf0a4ca377068cb27ed (diff) | |
download | openttd-bee930f9b3b9dad52945c1186227519cf9d566aa.tar.xz |
(svn r16024) -Codechange: harden string copying on places where it's possible
-rw-r--r-- | src/ai/ai_scanner.cpp | 2 | ||||
-rw-r--r-- | src/fileio.cpp | 10 | ||||
-rw-r--r-- | src/misc_gui.cpp | 2 | ||||
-rw-r--r-- | src/music/win32_m.cpp | 2 | ||||
-rw-r--r-- | src/screenshot.cpp | 2 | ||||
-rw-r--r-- | src/settings.cpp | 6 | ||||
-rw-r--r-- | src/strgen/strgen.cpp | 6 | ||||
-rw-r--r-- | src/video/dedicated_v.cpp | 2 |
8 files changed, 16 insertions, 16 deletions
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp index af452f086..ab9036cf7 100644 --- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -52,7 +52,7 @@ AIScanner::AIScanner() : /* Create the dummy AI */ this->engine->ResetCrashed(); - strcpy(this->main_script, "%_dummy"); + strecpy(this->main_script, "%_dummy", lastof(this->main_script)); extern void AI_CreateAIInfoDummy(HSQUIRRELVM vm); AI_CreateAIInfoDummy(this->engine->GetVM()); } diff --git a/src/fileio.cpp b/src/fileio.cpp index 79d2283f6..8252f5b90 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -363,7 +363,7 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, char resolved_name[MAX_RESOLVED_LENGTH]; /* Filenames in tars are always forced to be lowercase */ - strcpy(resolved_name, filename); + strecpy(resolved_name, filename, lastof(resolved_name)); strtolower(resolved_name); size_t resolved_len = strlen(resolved_name); @@ -376,9 +376,9 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, /* Apply link */ char resolved_name2[MAX_RESOLVED_LENGTH]; const std::string &dest = link->second; - strcpy(resolved_name2, &(resolved_name[len])); - strcpy(resolved_name, dest.c_str()); - strcpy(&(resolved_name[dest.length()]), resolved_name2); + strecpy(resolved_name2, &(resolved_name[len]), lastof(resolved_name2)); + strecpy(resolved_name, dest.c_str(), lastof(resolved_name)); + strecpy(&(resolved_name[dest.length()]), resolved_name2, lastof(resolved_name)); break; // Only resolve one level } } @@ -640,7 +640,7 @@ bool TarListAddFile(const char *filename) /* Process relative path. * Note: The destination of links must not contain any directory-links. */ - strcpy(dest, name); + strecpy(dest, name, lastof(dest)); char *destpos = strrchr(dest, PATHSEPCHAR); if (destpos == NULL) destpos = dest; *destpos = '\0'; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 4c3c0ea90..1db5226d6 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1508,7 +1508,7 @@ public: this->vscroll.cap--; case SLD_SAVE_GAME: this->GenerateFileName(); break; - case SLD_SAVE_SCENARIO: strcpy(this->edit_str_buf, "UNNAMED"); break; + case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break; default: break; } diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp index abcbffd27..54ea6e74f 100644 --- a/src/music/win32_m.cpp +++ b/src/music/win32_m.cpp @@ -23,7 +23,7 @@ static FMusicDriver_Win32 iFMusicDriver_Win32; void MusicDriver_Win32::PlaySong(const char *filename) { assert(filename != NULL); - strcpy(_midi.start_song, filename); + strecpy(_midi.start_song, filename, lastof(_midi.start_song)); _midi.playing = true; _midi.stop_song = false; SetEvent(_midi.wait_obj); diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 01dac79a0..17b18993e 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -456,7 +456,7 @@ const char *GetScreenshotFormatDesc(int i) void SetScreenshotFormat(int i) { _cur_screenshot_format = i; - strcpy(_screenshot_format_name, _screenshot_formats[i].extension); + strecpy(_screenshot_format_name, _screenshot_formats[i].extension, lastof(_screenshot_format_name)); } /* screenshot generator that dumps the current video buffer */ diff --git a/src/settings.cpp b/src/settings.cpp index 7df70d7c1..2b020a679 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -554,7 +554,7 @@ static void ini_save_settings(IniFile *ini, const SettingDesc *sd, const char *g uint32 i = (uint32)ReadValue(ptr, sld->conv); switch (sdb->cmd) { - case SDT_BOOLX: strcpy(buf, (i != 0) ? "true" : "false"); break; + case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break; case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break; case SDT_ONEOFMANY: make_oneofmany(buf, lastof(buf), sdb->many, i); break; case SDT_MANYOFMANY: make_manyofmany(buf, lastof(buf), sdb->many, i); break; @@ -564,9 +564,9 @@ static void ini_save_settings(IniFile *ini, const SettingDesc *sd, const char *g case SDT_STRING: switch (GetVarMemType(sld->conv)) { - case SLE_VAR_STRB: strcpy(buf, (char*)ptr); break; + case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break; case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break; - case SLE_VAR_STR: strcpy(buf, *(char**)ptr); break; + case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break; case SLE_VAR_STRQ: if (*(char**)ptr == NULL) { buf[0] = '\0'; diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index 6bec63094..b769d55fe 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -1193,9 +1193,9 @@ static void WriteLangfile(const char *filename) hdr.text_dir = _lang_textdir; hdr.winlangid = TO_LE16(_lang_winlangid); hdr.newgrflangid = _lang_newgrflangid; - strcpy(hdr.name, _lang_name); - strcpy(hdr.own_name, _lang_ownname); - strcpy(hdr.isocode, _lang_isocode); + strecpy(hdr.name, _lang_name, lastof(hdr.name)); + strecpy(hdr.own_name, _lang_ownname, lastof(hdr.own_name)); + strecpy(hdr.isocode, _lang_isocode, lastof(hdr.isocode)); fwrite(&hdr, sizeof(hdr), 1, f); diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index 93ea1c7e2..486ea547e 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -222,7 +222,7 @@ static void DedicatedHandleKeyInput() #else /* Handle console input, and singal console thread, it can accept input again */ assert_compile(lengthof(_win_console_thread_buffer) <= lengthof(input_line)); - strcpy(input_line, _win_console_thread_buffer); + strecpy(input_line, _win_console_thread_buffer, lastof(input_line)); SetEvent(_hWaitForInputHandling); #endif |