[libxml++] SIGABRT received during xmlpp::Document::write_to_string_formatted



Hi

I'm writing an XML file with the xmlpp interface.
Everything is fine with xmlpp::Document::write_to_file_formatted();
But when I'm calling xmlpp::Document::write_to_string_formatted(), I receive a SIGABRT signal.

Any idea around ?

Thanks

PS: please find hereafter my source code and the gdb 'info st' output

* source code (very simple - the ConvertInput function comes from libxml2 code API samples).

#include <libxml++/libxml++.h>
#include <libxml/tree.h>

#include <string>
#include <iostream>

/**
 * ConvertInput:
 * @in: string in a given encoding
 * @encoding: the encoding used
 *
 * Converts @in into UTF-8 for processing with libxml2 APIs
 *
 * Returns the converted UTF-8 string, or NULL in case of error.
 */
xmlChar *
ConvertInput(const char *in, const char *encoding)
{
    xmlChar *out;
    int ret;
    int size;
    int out_size;
    int temp;
    xmlCharEncodingHandlerPtr handler;

    if (in == 0)
        return 0;

    handler = xmlFindCharEncodingHandler(encoding);

    if (!handler) {
        printf("ConvertInput: no encoding handler found for '%s'\n",
               encoding ? encoding : "");
        return 0;
    }

    size = (int) strlen(in) + 1;
    out_size = size * 2 - 1;
    out = (unsigned char *) xmlMalloc((size_t) out_size);

    if (out != 0) {
        temp = size - 1;
        ret = handler->input(out, &out_size, (const xmlChar *) in, &temp);
        if ((ret < 0) || (temp - size + 1)) {
            if (ret < 0) {
                printf("ConvertInput: conversion wasn't successful.\n");
            } else {
                printf
("ConvertInput: conversion wasn't successful. converted: %i octets.\n",
                     temp);
            }

            xmlFree(out);
            out = 0;
        } else {
            out = (unsigned char *) xmlRealloc(out, out_size + 1);
            out[out_size] = 0;  /*null terminating out */
        }
    } else {
        printf("ConvertInput: no mem\n");
    }

    return out;
}

int main(int argc, char **argv)
{
  xmlpp::Document doc;
  xmlpp::Element * elem = 0;
  std::string my_encoding = "ISO-8859-1";
  doc.set_internal_subset("GEDCOM", "", "gedcom60.dtd");
  doc.add_comment("Generated by libgedcomparser - part of GHOSTS project");
  elem = doc.create_root_node("GEDCOM");

  xmlChar * converted = ConvertInput("blah é", my_encoding.c_str());
  std::cerr << converted << std::endl;
  if (converted != 0)
    {
      std::string converted_string((char *)converted);
      std::cerr << converted << std::endl;
      elem->set_child_text(converted_string);
    }

  doc.write_to_file_formatted("xmlencode.xml", my_encoding);
  std::cerr << "write_to_file_formatted OK" << std::endl;
  Glib::ustring result_xml;
  result_xml = doc.write_to_string_formatted(my_encoding);
  std::cerr << "write_to_string_formatted OK" << std::endl;
  std::cerr << result_xml << std::endl;
  return 0;
}


* gdb info st :

#0  0x403aa621 in kill () from /lib/libc.so.6
#1  0x4017826b in raise (sig=6) at signals.c:65
#2  0x403aba53 in abort () from /lib/libc.so.6
#3 0x402f7895 in __cxxabiv1::__terminate(void (*)()) () from /usr/lib/libstdc++.so.3 #4 0x402f7880 in __cxxabiv1::__terminate(void (*)()) () from /usr/lib/libstdc++.so.3
#5  0x402f79e0 in __cxa_rethrow () from /usr/lib/libstdc++.so.3
#6 0x402ede29 in std::__throw_length_error(char const*) () from /usr/lib/libstdc++.so.3 #7 0x0804aef1 in std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) (__capacity=4294967295,
    __alloc= 0xbffff500) at /usr/include/g++-v3/bits/basic_string.tcc:371
#8 0x0804ab28 in char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) ( __beg=0x80516e0 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<!DOCTYPE GEDCOM SYSTEM \"gedcom60.dtd\">\n<!--Generated by libgedcomparser - part of GHOSTS project-->\n<GEDCOM>blah é</GEDCOM>\n", __end=0x80516df "",
    __a= 0xbffff500) at /usr/include/g++-v3/bits/basic_string.tcc:143
#9 0x40034674 in std::string::string(char const*, unsigned, std::allocator<char> const&) (this=0xbffff560, __s=0x80516e0 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<!DOCTYPE GEDCOM SYSTEM \"gedcom60.dtd\">\n<!--Generated by libgedcomparser - part of GHOSTS project-->\n<GEDCOM>blah é</GEDCOM>\n", __n=4294967295,
    __a= 0xbffff500) at /usr/include/g++-v3/bits/basic_string.h:666
#10 0x401c40c4 in Glib::ustring::ustring(char const*, unsigned) (this=0xbffff560, src=0x80516e0 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<!DOCTYPE GEDCOM SYSTEM \"gedcom60.dtd\">\n<!--Generated by libgedcomparser - part of GHOSTS project-->\n<GEDCOM>blah é</GEDCOM>\n", n=169)
    at /usr/include/g++-v3/bits/stl_alloc.h:571
#11 0x40025d27 in xmlpp::Document::do_write_to_string(Glib::ustring const&, bool) (this=0xbffff6a0,
    encoding= 0xbffff5d0, format=true) at document.cc:309




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]