Fix a few potential segfaults found in device.c
This commit is contained in:
49
src/device.c
49
src/device.c
@@ -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;
|
||||
@@ -746,13 +757,15 @@ 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;
|
||||
@@ -761,13 +774,15 @@ 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;
|
||||
@@ -776,13 +791,15 @@ 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;
|
||||
@@ -791,6 +808,7 @@ device_set_config_mac(const char *str, int val)
|
||||
cfg++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
device_is_valid(const device_t *device, int mch)
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user