Fix a few potential segfaults found in device.c

This commit is contained in:
Jasmine Iwanek
2025-01-06 21:48:38 -05:00
parent 3d7df5f87c
commit 29b6cd484c

View File

@@ -660,14 +660,16 @@ device_get_config_string(const char *str)
int
device_get_config_int(const char *str)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name))
return (config_get_int((char *) device_current.name, (char *) str, cfg->default_int));
cfg++;
}
}
return 0;
}
@@ -675,14 +677,16 @@ device_get_config_int(const char *str)
int
device_get_config_int_ex(const char *str, int def)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name))
return (config_get_int((char *) device_current.name, (char *) str, def));
cfg++;
}
}
return def;
}
@@ -690,14 +694,16 @@ device_get_config_int_ex(const char *str, int def)
int
device_get_config_hex16(const char *str)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name))
return (config_get_hex16((char *) device_current.name, (char *) str, cfg->default_int));
cfg++;
}
}
return 0;
}
@@ -705,14 +711,16 @@ device_get_config_hex16(const char *str)
int
device_get_config_hex20(const char *str)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name))
return (config_get_hex20((char *) device_current.name, (char *) str, cfg->default_int));
cfg++;
}
}
return 0;
}
@@ -720,14 +728,16 @@ device_get_config_hex20(const char *str)
int
device_get_config_mac(const char *str, int def)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name))
return (config_get_mac((char *) device_current.name, (char *) str, def));
cfg++;
}
}
return def;
}
@@ -735,9 +745,10 @@ device_get_config_mac(const char *str, int def)
void
device_set_config_int(const char *str, int val)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name)) {
config_set_int((char *) device_current.name, (char *) str, val);
break;
@@ -745,14 +756,16 @@ device_set_config_int(const char *str, int val)
cfg++;
}
}
}
void
device_set_config_hex16(const char *str, int val)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name)) {
config_set_hex16((char *) device_current.name, (char *) str, val);
break;
@@ -760,14 +773,16 @@ device_set_config_hex16(const char *str, int val)
cfg++;
}
}
}
void
device_set_config_hex20(const char *str, int val)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name)) {
config_set_hex20((char *) device_current.name, (char *) str, val);
break;
@@ -775,14 +790,16 @@ device_set_config_hex20(const char *str, int val)
cfg++;
}
}
}
void
device_set_config_mac(const char *str, int val)
{
if (device_current.dev != NULL) {
const device_config_t *cfg = device_current.dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name)) {
config_set_mac((char *) device_current.name, (char *) str, val);
break;
@@ -790,6 +807,7 @@ device_set_config_mac(const char *str, int val)
cfg++;
}
}
}
int
@@ -807,19 +825,17 @@ int
machine_get_config_int(char *str)
{
const device_t *dev = machine_get_device(machine);
const device_config_t *cfg;
if (dev == NULL)
return 0;
if (dev != NULL) {
const device_config_t *cfg = dev->config;
cfg = dev->config;
while (cfg && cfg->type != CONFIG_END) {
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name))
return (config_get_int((char *) dev->name, str, cfg->default_int));
cfg++;
}
}
return 0;
}
@@ -830,9 +846,8 @@ machine_get_config_string(char *str)
const char *ret = "";
if (dev != NULL) {
const device_config_t *cfg;
const device_config_t *cfg = dev->config;
cfg = dev->config;
while ((cfg != NULL) && (cfg->type != CONFIG_END)) {
if (!strcmp(str, cfg->name)) {
const char *s = config_get_string((char *) dev->name, str,