Use a sstrncpy function that behaves like strlcpy.

This commit is contained in:
Brandon Wright 2018-11-18 11:18:27 -06:00
parent 600de05244
commit 047cfe2f9d
5 changed files with 12 additions and 11 deletions

View File

@ -456,7 +456,7 @@ S9xOpenROMDialog ()
gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
if (directory)
{
strncpy (gui_config->last_directory, directory, PATH_MAX - 1);
sstrncpy (gui_config->last_directory, directory, PATH_MAX);
g_free (directory);
}
}

View File

@ -96,8 +96,8 @@ Snes9xNetplayDialog::settings_to_dialog ()
void
Snes9xNetplayDialog::settings_from_dialog ()
{
strncpy (config->netplay_last_rom, get_entry_text ("rom_image"), PATH_MAX - 1);
strncpy (config->netplay_last_host, get_entry_text ("ip_entry"), PATH_MAX - 1);
sstrncpy (config->netplay_last_rom, get_entry_text ("rom_image"), PATH_MAX);
sstrncpy (config->netplay_last_host, get_entry_text ("ip_entry"), PATH_MAX);
config->netplay_sync_reset = get_check ("sync_reset");
config->netplay_send_rom = get_check ("send_image");
config->netplay_last_port = get_spin ("port");

View File

@ -905,17 +905,17 @@ Snes9xPreferences::get_settings_from_dialog ()
config->use_shaders = get_check ("use_shaders");
config->sync_every_frame = get_check ("sync_every_frame");
strncpy (config->fragment_shader, get_entry_text ("fragment_shader"), PATH_MAX - 1);
sstrncpy (config->fragment_shader, get_entry_text ("fragment_shader"), PATH_MAX);
config->pbo_format = pbo_format;
#endif
char safety_sram_directory [PATH_MAX];
strncpy (safety_sram_directory, get_entry_text ("sram_directory"), PATH_MAX - 1);
strncpy (config->savestate_directory, get_entry_text ("savestate_directory"), PATH_MAX - 1);
strncpy (config->patch_directory, get_entry_text ("patch_directory"), PATH_MAX - 1);
strncpy (config->cheat_directory, get_entry_text ("cheat_directory"), PATH_MAX - 1);
strncpy (config->export_directory, get_entry_text ("export_directory"), PATH_MAX - 1);
sstrncpy (safety_sram_directory, get_entry_text ("sram_directory"), PATH_MAX);
sstrncpy (config->savestate_directory, get_entry_text ("savestate_directory"), PATH_MAX);
sstrncpy (config->patch_directory, get_entry_text ("patch_directory"), PATH_MAX);
sstrncpy (config->cheat_directory, get_entry_text ("cheat_directory"), PATH_MAX);
sstrncpy (config->export_directory, get_entry_text ("export_directory"), PATH_MAX);
if (!strcmp (safety_sram_directory, SAME_GAME))
safety_sram_directory[0] = '\0';

View File

@ -434,7 +434,7 @@ static int read_movie_extrarominfo (FILE *fd, SMovie *movie)
ptr += 3; // zero bytes
movie->ROMCRC32 = Read32(ptr);
strncpy(movie->ROMName, (char *) ptr, 22);
sstrncpy(movie->ROMName, (char *) ptr, 23);
return (SUCCESS);
}

1
port.h
View File

@ -149,6 +149,7 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
#endif // __WIN32__
#define ssnprintf(dst, size, fmt, ...) if (snprintf(dst, size, fmt, __VA_ARGS__) >= (int) size) dst[size - 1] = '\0';
#define sstrncpy(dst, src, size) strncpy(dst, src, size - 1); dst[size - 1] = '\0';
#if defined(__DJGPP) || defined(__WIN32__)
#define SLASH_STR "\\"