From 5e804463c8b1ef9bbea059b9fb28196cc80311a8 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Fri, 7 Aug 2015 02:04:32 +0100 Subject: [PATCH] fix #1740 --- src/config.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 0d98282e60..d5b49afef9 100644 --- a/src/config.c +++ b/src/config.c @@ -266,9 +266,9 @@ void config_set_defaults() config_section_definition *section = &_sectionDefinitions[i]; for (j = 0; j < section->property_definitions_count; j++) { config_property_definition *property = §ion->property_definitions[j]; - value_union *destValue = (value_union*)((size_t)section->base_address + (size_t)property->offset); + // Special dynamic defaults if (strcmp(property->property_name, "language") == 0){ destValue->value_uint16 = platform_get_locale_language(); if (destValue->value_uint16 == LANGUAGE_UNDEFINED) @@ -284,7 +284,17 @@ void config_set_defaults() destValue->value_uint8 = platform_get_locale_temperature_format(); } else { - memcpy(destValue, &property->default_value, _configValueTypeSize[property->type]); + // Use static default + if (property->type == CONFIG_VALUE_TYPE_STRING) { + // Copy the string to new memory + const utf8 *src = property->default_value.value_string; + const utf8 **dst = &(destValue->value_string); + if (src != NULL) { + *dst = _strdup(property->default_value.value_string); + } + } else { + memcpy(destValue, &property->default_value, _configValueTypeSize[property->type]); + } } } }