texmacs-dev
[Top][All Lists]
Advanced

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

Re: [Texmacs-dev] character encoding


From: Joris van der Hoeven
Subject: Re: [Texmacs-dev] character encoding
Date: Tue, 28 Jan 2003 16:44:03 +0100 (MET)

> On Tue, 2003-01-28 at 14:28, Joris van der Hoeven wrote:
> > > Any idea why?
> > 
> > Yes: you should use delete[] instead of delete
> > in order to delete arrays.
> 
> I now tried
> 
> string
> convert_using_iconv(string input, string from, string to) {
>   char* in_buf = as_charp(input);
>   char* from_cp = as_charp(from);
>   char* to_cp = as_charp(to);
>   size_t inbytesleft = (size_t) N(input);
>   string result;
> 
>   iconv_t cd = iconv_open(to_cp,from_cp);
>   if(cd==(iconv_t)-1) return "";
>   
>   while (inbytesleft > 0) {
>     size_t out_buf_len = max(inbytesleft,10);
>     size_t outbytesleft = out_buf_len;
>     char* out_buf = new char[out_buf_len];
>     char* start_out_buf = out_buf;
>     size_t flag = iconv (cd, &in_buf, &inbytesleft, &out_buf, &outbytesleft);
>     if(flag==(size_t)-1 && errno != E2BIG) { system_error("String conversion 
> using iconv failed!"); return "";}
>     result << string(start_out_buf, out_buf_len - outbytesleft);
>     //delete[] out_buf;
>   }
>   iconv_close(cd);
>   delete[] in_buf; delete[] from_cp; delete[] to_cp;
>   return result;
> }
> 
> which worked, but as soon as I remove the comment befor delete[]
> out_buf, I got a segfault again. Obviously this is because I allocated
> out_buf manually. But what did I do wrong?

I think that the string::string(char* s, int n)
does not make a copy of the memory.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]