fix for segfault on screenshot w/ no dir specified

This commit is contained in:
Dagen Brock 2017-01-19 22:53:30 -06:00
parent 4918fa3c48
commit 8d1161b224
3 changed files with 37 additions and 36 deletions

View File

@ -575,8 +575,7 @@ config_init()
// Find the configuration file
g_config_gsplus_name[0] = 0;
can_create = 1;
setup_gsplus_file(&g_config_gsplus_name[0], sizeof(g_config_gsplus_name), 0,
can_create, &g_config_gsplus_name_list[0]);
setup_gsplus_file(&g_config_gsplus_name[0], sizeof(g_config_gsplus_name), 0, can_create, &g_config_gsplus_name_list[0]);
config_parse_config_gsplus_file();
}
@ -726,8 +725,9 @@ config_parse_option(char *buf, int pos, int len, int line)
}
// find "name" as first contiguous string
printf("...parse_option: line %d, %p,%p = %s (%s) len:%d\n", line,
&buf[pos], buf, &buf[pos], buf, len);
gloghead(); printf("...parse_option: line %d, len:%d \"%s\"\n", line, len, &buf[pos]);
// printf("...parse_option: line %d, %p,%p = %s (%s) len:%d\n", line, &buf[pos], buf, &buf[pos], buf, len);
nameptr = &buf[pos];
while(pos < len) {
@ -921,8 +921,7 @@ config_load_roms()
if(*names_ptr == 0) {
continue;
}
setup_gsplus_file(&g_cfg_tmp_path[0], CFG_PATH_MAX, 1, 0,
names_ptr);
setup_gsplus_file(&g_cfg_tmp_path[0], CFG_PATH_MAX, 1, 0, names_ptr);
if(g_cfg_tmp_path[0] != 0) {
file = fopen(&(g_cfg_tmp_path[0]), "rb");
if(!file) {

View File

@ -53,7 +53,7 @@ int kb_shift_control_state = 0;
void x_take_screenshot(); // screenshot stuff
int g_screenshot_requested = 0; // DB to know if we want to save a screenshot
extern char g_config_gsplus_name[];
extern char *g_config_gsplus_screenshot_dir;
extern char g_config_gsplus_screenshot_dir[];
int screenshot_index = 0; // allows us to save time by not scanning from 0 each time
char screenshot_filename[256];
@ -650,7 +650,8 @@ void make_next_screenshot_filename()
// workaround is this horrible hack of saving the bmp -> load bmp -> save png
void x_take_screenshot() {
make_next_screenshot_filename();
printf("Screenshot! ---> %s\n", screenshot_filename);
gloghead();
printf("Taking screenshot - %s\n", screenshot_filename);
SDL_Surface *sshot = SDL_CreateRGBSurface(0, BASE_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
SDL_LockSurface(sshot);
int read = SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);

View File

@ -29,7 +29,7 @@
#include "glog.h"
extern const char *g_config_gsplus_name_list[];
extern char *g_config_gsplus_screenshot_dir;
extern char g_config_gsplus_screenshot_dir[];
#ifdef UNDER_CE
#define vsnprintf _vsnprintf
#endif
@ -946,6 +946,10 @@ gsplusmain(int argc, char **argv)
sim65816_initglobals();
moremem_init();
printf("FOOOAAA\n" );
// initialize ss dir to default value (current path)
strcpy(g_config_gsplus_screenshot_dir, "./");
/* parse args */
for(i = 1; i < argc; i++) {
if(!strcmp("-badrd", argv[i])) {
@ -1055,11 +1059,11 @@ gsplusmain(int argc, char **argv)
exit(1);
}
printf("Using %s as configuration file\n", argv[i+1]);
g_config_gsplus_name_list[0] = argv[i+1]; // super dangerous ?
g_config_gsplus_name_list[0] = argv[i+1]; // overwrite default list with passed item as sole option
g_config_gsplus_name_list[1] = 0; // terminate string array
i++;
} else if (!strcmp("-ssdir", argv[i])) { // screenshot directory passed
g_config_gsplus_screenshot_dir = argv[i+1];
strcpy(g_config_gsplus_screenshot_dir, argv[i+1]);
struct stat path_stat;
int ret = stat(g_config_gsplus_screenshot_dir, &path_stat); // (weakly) validate path
if (!S_ISDIR(path_stat.st_mode)) {
@ -1308,9 +1312,7 @@ gsport_expand_path(char *out_ptr, const char *in_ptr, int maxlen)
}
}
void
setup_gsplus_file(char *outname, int maxlen, int ok_if_missing,
int can_create_file, const char **name_ptr)
void setup_gsplus_file(char *outname, int maxlen, int ok_if_missing, int can_create_file, const char **name_ptr)
{
char local_path[256];
struct stat stat_buf;
@ -1329,7 +1331,7 @@ setup_gsplus_file(char *outname, int maxlen, int ok_if_missing,
while(*cur_name_ptr) {
strcpy(outname, &(local_path[0]));
strncat(outname, *cur_name_ptr, 255-strlen(outname));
if(!ok_if_missing) {
if(!ok_if_missing) { // ??
gloghead(); printf("Trying '%s'\n", outname);
}
ret = stat(outname, &stat_buf);
@ -1382,8 +1384,7 @@ setup_gsplus_file(char *outname, int maxlen, int ok_if_missing,
// But clear out the fatal_printfs first
clear_fatal_logs();
setup_gsplus_file(outname, maxlen, ok_if_missing,
can_create_file, name_ptr);
setup_gsplus_file(outname, maxlen, ok_if_missing, can_create_file, name_ptr);
// It's one-level of recursion--it cannot loop since we
// clear can_create_file.
// If it returns, then there was succes and we should get out