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

View File

@ -53,7 +53,7 @@ int kb_shift_control_state = 0;
void x_take_screenshot(); // screenshot stuff void x_take_screenshot(); // screenshot stuff
int g_screenshot_requested = 0; // DB to know if we want to save a screenshot 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_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 int screenshot_index = 0; // allows us to save time by not scanning from 0 each time
char screenshot_filename[256]; 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 // workaround is this horrible hack of saving the bmp -> load bmp -> save png
void x_take_screenshot() { void x_take_screenshot() {
make_next_screenshot_filename(); 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_Surface *sshot = SDL_CreateRGBSurface(0, BASE_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
SDL_LockSurface(sshot); SDL_LockSurface(sshot);
int read = SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch); int read = SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);

View File

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