Merge pull request #236 from lab313ru/patch-2

[libretro] Fixed options reading nullpointer
This commit is contained in:
ekeeke 2018-07-07 17:43:24 +02:00 committed by GitHub
commit 0ac750010e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -870,7 +870,7 @@ static void check_variables(void)
char slash = '/'; char slash = '/';
#endif #endif
if (!strcmp(var.value, "per bios")) if (!var.value || !strcmp(var.value, "per bios"))
{ {
snprintf(CD_BRAM_EU, sizeof(CD_BRAM_EU), "%s%cscd_E.brm", save_dir, slash); snprintf(CD_BRAM_EU, sizeof(CD_BRAM_EU), "%s%cscd_E.brm", save_dir, slash);
snprintf(CD_BRAM_US, sizeof(CD_BRAM_US), "%s%cscd_U.brm", save_dir, slash); snprintf(CD_BRAM_US, sizeof(CD_BRAM_US), "%s%cscd_U.brm", save_dir, slash);
@ -888,19 +888,19 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.system; orig_value = config.system;
if (!strcmp(var.value, "sg-1000")) if (var.value && !strcmp(var.value, "sg-1000"))
config.system = SYSTEM_SG; config.system = SYSTEM_SG;
else if (!strcmp(var.value, "sg-1000 II")) else if (var.value && !strcmp(var.value, "sg-1000 II"))
config.system = SYSTEM_SGII; config.system = SYSTEM_SGII;
else if (!strcmp(var.value, "mark-III")) else if (var.value && !strcmp(var.value, "mark-III"))
config.system = SYSTEM_MARKIII; config.system = SYSTEM_MARKIII;
else if (!strcmp(var.value, "master system")) else if (var.value && !strcmp(var.value, "master system"))
config.system = SYSTEM_SMS; config.system = SYSTEM_SMS;
else if (!strcmp(var.value, "master system II")) else if (var.value && !strcmp(var.value, "master system II"))
config.system = SYSTEM_SMS2; config.system = SYSTEM_SMS2;
else if (!strcmp(var.value, "game gear")) else if (var.value && !strcmp(var.value, "game gear"))
config.system = SYSTEM_GG; config.system = SYSTEM_GG;
else if (!strcmp(var.value, "mega drive / genesis")) else if (var.value && !strcmp(var.value, "mega drive / genesis"))
config.system = SYSTEM_MD; config.system = SYSTEM_MD;
else else
config.system = 0; config.system = 0;
@ -937,7 +937,7 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.bios; orig_value = config.bios;
if (!strcmp(var.value, "enabled")) if (var.value && !strcmp(var.value, "enabled"))
config.bios = 3; config.bios = 3;
else else
config.bios = 0; config.bios = 0;
@ -955,11 +955,11 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.region_detect; orig_value = config.region_detect;
if (!strcmp(var.value, "ntsc-u")) if (var.value && !strcmp(var.value, "ntsc-u"))
config.region_detect = 1; config.region_detect = 1;
else if (!strcmp(var.value, "pal")) else if (var.value && !strcmp(var.value, "pal"))
config.region_detect = 2; config.region_detect = 2;
else if (!strcmp(var.value, "ntsc-j")) else if (var.value && !strcmp(var.value, "ntsc-j"))
config.region_detect = 3; config.region_detect = 3;
else else
config.region_detect = 0; config.region_detect = 0;
@ -1035,7 +1035,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_force_dtack"; var.key = "genesis_plus_gx_force_dtack";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (!strcmp(var.value, "enabled")) if (!var.value || !strcmp(var.value, "enabled"))
config.force_dtack = 1; config.force_dtack = 1;
else else
config.force_dtack = 0; config.force_dtack = 0;
@ -1044,7 +1044,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_addr_error"; var.key = "genesis_plus_gx_addr_error";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (!strcmp(var.value, "enabled")) if (!var.value || !strcmp(var.value, "enabled"))
m68k.aerr_enabled = config.addr_error = 1; m68k.aerr_enabled = config.addr_error = 1;
else else
m68k.aerr_enabled = config.addr_error = 0; m68k.aerr_enabled = config.addr_error = 0;
@ -1054,11 +1054,11 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.lock_on; orig_value = config.lock_on;
if (!strcmp(var.value, "game genie")) if (var.value && !strcmp(var.value, "game genie"))
config.lock_on = TYPE_GG; config.lock_on = TYPE_GG;
else if (!strcmp(var.value, "action replay (pro)")) else if (var.value && !strcmp(var.value, "action replay (pro)"))
config.lock_on = TYPE_AR; config.lock_on = TYPE_AR;
else if (!strcmp(var.value, "sonic & knuckles")) else if (var.value && !strcmp(var.value, "sonic & knuckles"))
config.lock_on = TYPE_SK; config.lock_on = TYPE_SK;
else else
config.lock_on = 0; config.lock_on = 0;
@ -1074,9 +1074,9 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.ym2413; orig_value = config.ym2413;
if (!strcmp(var.value, "enabled")) if (var.value && !strcmp(var.value, "enabled"))
config.ym2413 = 1; config.ym2413 = 1;
else if (!strcmp(var.value, "disabled")) else if (var.value && !strcmp(var.value, "disabled"))
config.ym2413 = 0; config.ym2413 = 0;
else else
config.ym2413 = 2; config.ym2413 = 2;
@ -1095,20 +1095,20 @@ static void check_variables(void)
var.key = "genesis_plus_gx_sound_output"; var.key = "genesis_plus_gx_sound_output";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (!strcmp(var.value, "mono")) if (var.value && !strcmp(var.value, "mono"))
config.mono = 1; config.mono = 1;
else if (!strcmp(var.value, "stereo")) else if (!var.value || !strcmp(var.value, "stereo"))
config.mono = 0; config.mono = 0;
} }
var.key = "genesis_plus_gx_audio_filter"; var.key = "genesis_plus_gx_audio_filter";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (!strcmp(var.value, "low-pass")) if (var.value && !strcmp(var.value, "low-pass"))
config.filter = 1; config.filter = 1;
#if HAVE_EQ #if HAVE_EQ
else if (!strcmp(var.value, "EQ")) else if (var.value && !strcmp(var.value, "EQ"))
config.filter = 2; config.filter = 2;
#endif #endif
@ -1119,14 +1119,14 @@ static void check_variables(void)
var.key = "genesis_plus_gx_lowpass_range"; var.key = "genesis_plus_gx_lowpass_range";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
config.lp_range = (atoi(var.value) * 65536) / 100; config.lp_range = (!var.value) ? 60 : ((atoi(var.value) * 65536) / 100);
} }
#if HAVE_EQ #if HAVE_EQ
var.key = "genesis_plus_gx_audio_eq_low"; var.key = "genesis_plus_gx_audio_eq_low";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
uint8_t new_lg = atoi(var.value); uint8_t new_lg = (!var.value) ? 100 : atoi(var.value);
if (new_lg != config.lg) restart_eq = true; if (new_lg != config.lg) restart_eq = true;
config.lg = new_lg; config.lg = new_lg;
} }
@ -1134,7 +1134,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_audio_eq_mid"; var.key = "genesis_plus_gx_audio_eq_mid";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
uint8_t new_mg = atoi(var.value); uint8_t new_mg = (!var.value) ? 100 : atoi(var.value);
if (new_mg != config.mg) restart_eq = true; if (new_mg != config.mg) restart_eq = true;
config.mg = new_mg; config.mg = new_mg;
} }
@ -1142,7 +1142,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_audio_eq_high"; var.key = "genesis_plus_gx_audio_eq_high";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
uint8_t new_hg = atoi(var.value); uint8_t new_hg = (!var.value) ? 100 : atoi(var.value);
if (new_hg != config.hg) restart_eq = true; if (new_hg != config.hg) restart_eq = true;
config.hg = new_hg; config.hg = new_hg;
@ -1154,12 +1154,12 @@ static void check_variables(void)
{ {
#ifdef HAVE_YM3438_CORE #ifdef HAVE_YM3438_CORE
orig_value = config.ym3438; orig_value = config.ym3438;
if (!strcmp(var.value, "nuked (ym2612)")) if (var.value && !strcmp(var.value, "nuked (ym2612)"))
{ {
OPN2_SetChipType(ym3438_mode_ym2612); OPN2_SetChipType(ym3438_mode_ym2612);
config.ym3438 = 1; config.ym3438 = 1;
} }
else if (!strcmp(var.value, "nuked (ym3438)")) else if (var.value && !strcmp(var.value, "nuked (ym3438)"))
{ {
OPN2_SetChipType(ym3438_mode_readmode); OPN2_SetChipType(ym3438_mode_readmode);
config.ym3438 = 2; config.ym3438 = 2;
@ -1176,12 +1176,12 @@ static void check_variables(void)
} }
#endif #endif
if (!strcmp(var.value, "mame (ym2612)")) if (!var.value || !strcmp(var.value, "mame (ym2612)"))
{ {
config.ym2612 = YM2612_DISCRETE; config.ym2612 = YM2612_DISCRETE;
YM2612Config(YM2612_DISCRETE); YM2612Config(YM2612_DISCRETE);
} }
else if (!strcmp(var.value, "mame (asic ym3438)")) else if (var.value && !strcmp(var.value, "mame (asic ym3438)"))
{ {
config.ym2612 = YM2612_INTEGRATED; config.ym2612 = YM2612_INTEGRATED;
YM2612Config(YM2612_INTEGRATED); YM2612Config(YM2612_INTEGRATED);
@ -1198,27 +1198,27 @@ static void check_variables(void)
{ {
orig_value = config.ntsc; orig_value = config.ntsc;
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.ntsc = 0; config.ntsc = 0;
else if (strcmp(var.value, "monochrome") == 0) else if (var.value && !strcmp(var.value, "monochrome"))
{ {
config.ntsc = 1; config.ntsc = 1;
sms_ntsc_init(sms_ntsc, &sms_ntsc_monochrome); sms_ntsc_init(sms_ntsc, &sms_ntsc_monochrome);
md_ntsc_init(md_ntsc, &md_ntsc_monochrome); md_ntsc_init(md_ntsc, &md_ntsc_monochrome);
} }
else if (strcmp(var.value, "composite") == 0) else if (var.value && !strcmp(var.value, "composite"))
{ {
config.ntsc = 1; config.ntsc = 1;
sms_ntsc_init(sms_ntsc, &sms_ntsc_composite); sms_ntsc_init(sms_ntsc, &sms_ntsc_composite);
md_ntsc_init(md_ntsc, &md_ntsc_composite); md_ntsc_init(md_ntsc, &md_ntsc_composite);
} }
else if (strcmp(var.value, "svideo") == 0) else if (var.value && !strcmp(var.value, "svideo"))
{ {
config.ntsc = 1; config.ntsc = 1;
sms_ntsc_init(sms_ntsc, &sms_ntsc_svideo); sms_ntsc_init(sms_ntsc, &sms_ntsc_svideo);
md_ntsc_init(md_ntsc, &md_ntsc_svideo); md_ntsc_init(md_ntsc, &md_ntsc_svideo);
} }
else if (strcmp(var.value, "rgb") == 0) else if (var.value && !strcmp(var.value, "rgb"))
{ {
config.ntsc = 1; config.ntsc = 1;
sms_ntsc_init(sms_ntsc, &sms_ntsc_rgb); sms_ntsc_init(sms_ntsc, &sms_ntsc_rgb);
@ -1232,9 +1232,9 @@ static void check_variables(void)
var.key = "genesis_plus_gx_lcd_filter"; var.key = "genesis_plus_gx_lcd_filter";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.lcd = 0; config.lcd = 0;
else if (strcmp(var.value, "enabled") == 0) else if (var.value && !strcmp(var.value, "enabled"))
config.lcd = (uint8)(0.80 * 256); config.lcd = (uint8)(0.80 * 256);
} }
@ -1242,13 +1242,13 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.overscan; orig_value = config.overscan;
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.overscan = 0; config.overscan = 0;
else if (strcmp(var.value, "top/bottom") == 0) else if (var.value && !strcmp(var.value, "top/bottom"))
config.overscan = 1; config.overscan = 1;
else if (strcmp(var.value, "left/right") == 0) else if (var.value && !strcmp(var.value, "left/right"))
config.overscan = 2; config.overscan = 2;
else if (strcmp(var.value, "full") == 0) else if (var.value && !strcmp(var.value, "full"))
config.overscan = 3; config.overscan = 3;
if (orig_value != config.overscan) if (orig_value != config.overscan)
update_viewports = true; update_viewports = true;
@ -1258,9 +1258,9 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.gg_extra; orig_value = config.gg_extra;
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.gg_extra = 0; config.gg_extra = 0;
else if (strcmp(var.value, "enabled") == 0) else if (var.value && !strcmp(var.value, "enabled"))
config.gg_extra = 1; config.gg_extra = 1;
if (orig_value != config.gg_extra) if (orig_value != config.gg_extra)
update_viewports = true; update_viewports = true;
@ -1270,9 +1270,9 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.aspect_ratio; orig_value = config.aspect_ratio;
if (strcmp(var.value, "NTSC PAR") == 0) if (var.value && !strcmp(var.value, "NTSC PAR"))
config.aspect_ratio = 1; config.aspect_ratio = 1;
else if (strcmp(var.value, "PAL PAR") == 0) else if (var.value && !strcmp(var.value, "PAL PAR"))
config.aspect_ratio = 2; config.aspect_ratio = 2;
else else
config.aspect_ratio = 0; config.aspect_ratio = 0;
@ -1284,7 +1284,7 @@ static void check_variables(void)
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
orig_value = config.render; orig_value = config.render;
if (strcmp(var.value, "single field") == 0) if (!var.value || !strcmp(var.value, "single field"))
config.render = 0; config.render = 0;
else else
config.render = 1; config.render = 1;
@ -1295,7 +1295,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_gun_cursor"; var.key = "genesis_plus_gx_gun_cursor";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.gun_cursor = 0; config.gun_cursor = 0;
else else
config.gun_cursor = 1; config.gun_cursor = 1;
@ -1304,7 +1304,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_invert_mouse"; var.key = "genesis_plus_gx_invert_mouse";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.invert_mouse = 0; config.invert_mouse = 0;
else else
config.invert_mouse = 1; config.invert_mouse = 1;
@ -1314,15 +1314,15 @@ static void check_variables(void)
var.key = "genesis_plus_gx_overclock"; var.key = "genesis_plus_gx_overclock";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (strcmp(var.value, "100%") == 0) if (!var.value || !strcmp(var.value, "100%"))
config.overclock = 100; config.overclock = 100;
else if (strcmp(var.value, "125%") == 0) else if (var.value && !strcmp(var.value, "125%"))
config.overclock = 125; config.overclock = 125;
else if (strcmp(var.value, "150%") == 0) else if (var.value && !strcmp(var.value, "150%"))
config.overclock = 150; config.overclock = 150;
else if (strcmp(var.value, "175%") == 0) else if (var.value && !strcmp(var.value, "175%"))
config.overclock = 175; config.overclock = 175;
else if (strcmp(var.value, "200%") == 0) else if (var.value && !strcmp(var.value, "200%"))
config.overclock = 200; config.overclock = 200;
if (system_hw) if (system_hw)
@ -1333,7 +1333,7 @@ static void check_variables(void)
var.key = "genesis_plus_gx_no_sprite_limit"; var.key = "genesis_plus_gx_no_sprite_limit";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{ {
if (strcmp(var.value, "disabled") == 0) if (!var.value || !strcmp(var.value, "disabled"))
config.no_sprite_limit = 0; config.no_sprite_limit = 0;
else else
config.no_sprite_limit = 1; config.no_sprite_limit = 1;