Re: Segmentation fault on append to Glib::ustring



I thought about it, but the problem is with the unreferencing of the Glib::ustring, not with the data (however if it tries to append a shorter string in a larger space it shouldn't be a problem, i think. (The matter could be if he tries to read more characters than the char * has allocated.)) Even if i try, in the "writefunction" to do anything else with the Glib::ustring it fails with segmentation fault.

Tomorrow morning i'll try the way you suggested me and i'll let you know.

The data is a website content and for compatibility reason (with the other application's function) i used Glib::ustring, but if i try with std::string the result is the same.

Thanks for the answer.
Stefano.

Il 09/12/2011 20:47, Kjell Ahlstedt ha scritto:
Hi,

I don't know anything about libcurl, and I haven't tried to build and execute your program. I've just studied your code a bit.

Are you aware that n in Glib::append(const char* src, size_type n) is _not_ the number of bytes to append? It's the number of UTF-8 encoded Unicode characters.

If size*nmemb in writefunction() is the number of bytes to append, and data contains utf-8 encoded data with multi-byte characters, buffer->append(data, size*nmemb) will try to append too much. You can try using template<class In> Glib::ustring& Glib::append(In pbegin, In pend):
  buffer->append(data, data + size*nmemb);
If data does not contain utf-8 encoded data, you should not use Glib::ustring.

Kjell

2011-12-09 19:16, Spazzatura.Live skrev:
Hello!

Sorry, it was a part of a bigger code, in the new attached archive i added a simple main.cc which can be compiled with: g++ $(pkg-config gtkmm-2.4 libcurl --libs --cflags) main.cc -o main
(if you want i can also add a makefile)

Thanks.
Regars,
Stefano

Il 09/12/2011 19:01, Milosz Derezynski ha scritto:
Hello,

Your testcase is broken, I was not able to compile it (I didn't edit any files), and details are missing:

- What is your version of gtkmm?

Please provide a code example that does compile; a makefile would make it perfect.

Regards
Milosz

On Fri, Dec 9, 2011 at 5:24 PM, Spazzatura.Live <kharhonte hotmail com> wrote:
Probably this is more a libcurl question than a gtkmm one, but i saw an example in which a std::string works so:

When i let curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writefunction), on my ustring:

   int writefunction(char *data, size_t size, size_t nmemb, Glib::ustring *buffer)
   {tow
       if(buffer!=NULL)
       {
           buffer->append(data, size*nmemb);
           return size*nmemb;
       }
       return 0;
   }

it gives always a segmentation fault.

Attached the code.

_



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