Checking string allocations (was Re: String literals, ASCII vs UTF-8)

Lubos Lunak l.lunak at suse.cz
Tue Feb 28 10:29:13 PST 2012


On Tuesday 28 of February 2012, Eike Rathke wrote:
> On Tuesday, 2012-02-28 16:37:38 +0000, Michael Meeks wrote:
> > Of course, on the very rare
> > occasions that we do a huge allocation for a string - perhaps we store
> > an entire VBA module in a single string or something silly ;-)
>
> As soon as Calc will use OUString instead of String for cell content and
> formula results exactly that will happen..
>
> I've seen Calc abused as a front end for some sort of web CMS, holding
> entire HTML "template" fragments in one cell ... complaint was that not
> more than 64k characters would fit into a formula result when
> concatenating those ...

> > which
> > might reasonably fail, then no doubt we could use the native C method,
> > and act accordingly if it failed.
>
> I doubt anyone would actually do that, so we could only hope for memory
> allocation exiting the application gracefully in that case.

 I think that is the real question. I've just found out that e.g. openSUSE 
12.1 in fact has memory overcommitting disabled by default, so such checks 
actually can work and would detect running out of memory. But I doubt anybody 
would be realistically bothered to check that these days.

 Even if the OUString ctor throws std::bad_alloc, there's unlikely any code 
catching it, except for some generic catch(), which perhaps may recover from 
it, or may not. And even if yes, the next time the larger string can cause 
running out of memory when appending to OUStringBuffer, when invokend with 
OUString's operator+, or any other of those functions that OSL_ENSURE the 
allocation result and are done with it.

-- 
 Lubos Lunak
 l.lunak at suse.cz


More information about the LibreOffice mailing list