(svn r16024) -Codechange: harden string copying on places where it's possible

This commit is contained in:
rubidium 2009-04-10 20:37:05 +00:00
parent 4bf3508680
commit bee930f9b3
8 changed files with 16 additions and 16 deletions

View File

@ -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());
}

View File

@ -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';

View File

@ -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;
}

View File

@ -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);

View File

@ -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 */

View File

@ -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';

View File

@ -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);

View File

@ -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