Re: [libxml++] program crashes when parsing XML with accent



Hi again,

Here is a little program that makes thing more clear :

#include <iostream>
#include <glibmm/ustring.h>

int main()
{
       try {
               Glib::ustring test("égal", 4);
               std::cout << "Success" << std::endl;
       } catch (...) {
               std::cout << "Failure" << std::endl;
       }
       try {
               Glib::ustring test("égal", 5);
               std::cout << "Success" << std::endl;
       } catch (...) {
               std::cout << "Failure" << std::endl;
       }
};


The output of it is:

Success
Failure


So, we have two possible conclusions :

1) Glib::ustring::ustring(const char *, ustring::size_type) does not have the good behavior. 2) We do no use correctly Glib::ustring::ustring(const char *, ustring::size_type)

I'd say that the constructor from a const char * should wait for the length in byte, and not in characters, since if I'm manipulating a char *, I have few chances to know the length in characters easily, so my personal conclusion is more 1) than 2).

Anyway I guess that Glibmm being stable, the behavior will not change. So we should probably use the Glib::ustring::ustring(const char *) constructor instead. For that we have to be sure that libxml2 will always gives us strings with a trailing '\0'. Daniel could you confirm ? Thanks.


Regards

Christophe











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