diff --git a/src/device.c b/src/device.c index d7c80be7a..fa7378c1a 100644 --- a/src/device.c +++ b/src/device.c @@ -637,16 +637,24 @@ device_get_instance(void) const char * device_get_config_string(const char *str) { - const device_config_t *cfg = device_current.dev->config; + const char *ret = ""; - while (cfg && cfg->type != CONFIG_END) { - if (!strcmp(str, cfg->name)) - return (config_get_string((char *) device_current.name, (char *) str, (char *) cfg->default_string)); + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - cfg++; + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + const char *s = (config_get_string((char *) device_current.name, + (char *) str, (char *) cfg->default_string)); + ret = (s == NULL) ? "" : s; + break; + } + + cfg++; + } } - return (NULL); + return ret; } int @@ -870,24 +878,29 @@ machine_get_config_int(char *str) return 0; } -char * +const char * machine_get_config_string(char *str) { - const device_t *dev = machine_get_device(machine); - const device_config_t *cfg; + const device_t *dev = machine_get_device(machine); + const char *ret = ""; - if (dev == NULL) - return 0; + if (dev != NULL) { + const device_config_t *cfg; - cfg = dev->config; - while (cfg && cfg->type != CONFIG_END) { - if (!strcmp(str, cfg->name)) - return (config_get_string((char *) dev->name, str, (char *) cfg->default_string)); + 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, + (char *) cfg->default_string); + ret = (s == NULL) ? "" : s; + break; + } - cfg++; + cfg++; + } } - return NULL; + return ret; } const device_t * diff --git a/src/device/serial_passthrough.c b/src/device/serial_passthrough.c index 3da2e09ff..256f9eaa9 100644 --- a/src/device/serial_passthrough.c +++ b/src/device/serial_passthrough.c @@ -260,7 +260,7 @@ static const device_config_t serial_passthrough_config[] = { .name = "host_serial_path", .description = "Host Serial Device", .type = CONFIG_SERPORT, - .default_string = "", + .default_string = NULL, .default_int = 0, .file_filter = NULL, .spinner = { 0 }, diff --git a/src/include/86box/device.h b/src/include/86box/device.h index 6902ffdfd..b5a4c1925 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -231,8 +231,8 @@ extern int device_get_instance(void); extern const char *device_get_internal_name(const device_t *dev); -extern int machine_get_config_int(char *str); -extern char *machine_get_config_string(char *str); +extern int machine_get_config_int(char *str); +extern const char *machine_get_config_string(char *str); extern const device_t device_none; extern const device_t device_internal;