X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fgom_modify.c;h=7e31a974e3b26b4e767263aeff937f9ed88ed393;hb=866835ac8928d7e40919c2ca59799cb37023856f;hp=5bfb34592fb981b9be37d098261eb2ba9f8726ce;hpb=3155d964e15a3c49121c01d2808e5a846779b812;p=gedcom-parse.git diff --git a/gom/gom_modify.c b/gom/gom_modify.c index 5bfb345..7e31a97 100644 --- a/gom/gom_modify.c +++ b/gom/gom_modify.c @@ -48,17 +48,22 @@ char* gom_set_string(char** data, const char* utf8_str) char* result = NULL; char* newptr; - if (!is_utf8_string(utf8_str)) { - gedcom_error(_("The input '%s' is not a valid UTF-8 string"), utf8_str); + if (utf8_str == NULL) { + SAFE_FREE(*data); } else { - newptr = strdup(utf8_str); - if (!newptr) - MEMORY_ERROR; + if (!is_utf8_string(utf8_str)) { + gedcom_error(_("The input '%s' is not a valid UTF-8 string"), utf8_str); + } else { - if (*data) free(*data); - *data = newptr; - result = *data; + newptr = strdup(utf8_str); + if (!newptr) + MEMORY_ERROR; + else { + SAFE_FREE(*data); + *data = newptr; + result = *data; + } } } @@ -68,13 +73,19 @@ char* gom_set_string(char** data, const char* utf8_str) char* gom_set_string_for_locale(char** data, const char* locale_str) { char* result = NULL; - char* utf8_str = convert_locale_to_utf8(locale_str); - - if (!utf8_str) - gedcom_error(_("The input '%s' is not a valid string for the locale"), - locale_str); - else - result = gom_set_string(data, utf8_str); + + if (locale_str == NULL) { + result = gom_set_string(data, NULL); + } + else { + char* utf8_str = convert_locale_to_utf8(locale_str); + + if (!utf8_str) + gedcom_error(_("The input '%s' is not a valid string for the locale"), + locale_str); + else + result = gom_set_string(data, utf8_str); + } return result; }