From: <svn...@op...> - 2009-02-24 15:08:13
|
Author: bellmich Date: Tue Feb 24 16:08:07 2009 New Revision: 944 URL: http://libsyncml.opensync.org/changeset/944 Log: better implementation of the automatic UTF-16 to UTF-8 conversion Modified: trunk/libsyncml/parser/sml_xml_parse.c Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Tue Feb 24 16:00:53 2009 (r943) +++ trunk/libsyncml/parser/sml_xml_parse.c Tue Feb 24 16:08:07 2009 (r944) @@ -1692,20 +1692,20 @@ smlTrace(TRACE_INTERNAL, "%s: read %d --> written %d --> %d ::= %s", __func__, read, written, strlen(conv_string), conv_string); /* replace the embedded string */ - char *new_data = smlTryMalloc0(*fixed_size - (last_utf16 - position + 1) + strlen(conv_string) + 1, error); + char *new_data = smlTryMalloc0(*fixed_size - read + written + 1, error); if (!new_data) { smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); return FALSE; } memcpy(new_data, *fixed_data, (size_t) position - (size_t) *fixed_data); - memcpy(new_data + (size_t) position - (size_t) *fixed_data, conv_string, strlen(conv_string)); - memcpy(new_data + (size_t) position - (size_t) *fixed_data + strlen(conv_string), - last_utf16 + 1, *fixed_size - ( last_utf16 + 1 - *fixed_data )); + memcpy(new_data + (size_t) position - (size_t) *fixed_data, conv_string, written); + memcpy(new_data + (size_t) position - (size_t) *fixed_data + written, + position + read, *fixed_size - ( (size_t) position - (size_t) *fixed_data ) - read ); /* fix pointers */ - *fixed_size = *fixed_size - (last_utf16 - position + 1) + strlen(conv_string); - position = new_data + (position - *fixed_data) + strlen(conv_string) + 1; + *fixed_size = *fixed_size - read + written; + position = new_data + (position - *fixed_data) + written; smlSafeCFree(fixed_data); *fixed_data = new_data; new_data = NULL; |