[Libreoffice-commits] core.git: 2 commits - sw/source

Stephan Bergmann sbergman at redhat.com
Tue Feb 18 10:38:56 CET 2014


Let me shamelessly misuse this opportunity to campaign for a likely 
little-known feature of the rtl string starts/endsWith family of 
functions that can take an additional "rest" out parameter that gets 
assigned the remainder of the input iff the input matches.

That is, the code from the two commits below could boil down to 
something like

   OUString aColorStr(aValue);
   if (!aColorStr.startsWithIgnoreAsciiCase("rgb(", &aColorStr)
       || !aColorStr.endsWith(")", &aColorStr)
       || aColorStr.isEmpty())
   {
       break;
   }

(Is this feature too subtle?  Likely; but I didn't find a cooler way to 
add it.)

Stephan


On 02/17/2014 09:08 PM, Jan Holesovsky wrote:
>   sw/source/filter/html/parcss1.cxx |   12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> New commits:
> commit 3ecdc23d164d8e8632375247604cddf04f1e4df4
> Author: Jan Holesovsky <kendy at collabora.com>
> Date:   Mon Feb 17 21:00:03 2014 +0100
>
>      Let's not parse nonsensical data.
>
>      Change-Id: Icf956c3824286e8244cf5809be88568de0d6a068
>
> diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
> index 8489355..692474b 100644
> --- a/sw/source/filter/html/parcss1.cxx
> +++ b/sw/source/filter/html/parcss1.cxx
> @@ -1273,11 +1273,11 @@ sal_Bool CSS1Expression::GetColor( Color &rColor ) const
>           {
>               sal_uInt8 aColors[3] = { 0, 0, 0 };
>
> -            OSL_ENSURE( aValue.startsWithIgnoreAsciiCase( "rgb" ) &&
> -                        aValue.getLength() > 5 &&
> -                        '(' == aValue[3] &&
> -                        ')' == aValue[aValue.getLength()-1],
> -                        "keine gueltiges RGB(...)" );
> +            if (!aValue.startsWithIgnoreAsciiCase( "rgb" ) || aValue.getLength() < 6 ||
> +                    aValue[3] != '(' || aValue[aValue.getLength()-1] != ')')
> +            {
> +                break;
> +            }
>
>               OUString aColorStr(aValue.copy(4, aValue.getLength() - 5));
>
> commit 2afb605601ec0b29e177dd38e4f16bfe06590882
> Author: Jan Holesovsky <kendy at collabora.com>
> Date:   Mon Feb 17 20:49:24 2014 +0100
>
>      Fix crash in css rgb color handling.
>
>      Crashing since 2000 (or earlier).
>
>      Change-Id: I9f91d56f380be2421370b0acbee351461e1f0973
>
> diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
> index 3dfbaea..8489355 100644
> --- a/sw/source/filter/html/parcss1.cxx
> +++ b/sw/source/filter/html/parcss1.cxx
> @@ -1279,7 +1279,7 @@ sal_Bool CSS1Expression::GetColor( Color &rColor ) const
>                           ')' == aValue[aValue.getLength()-1],
>                           "keine gueltiges RGB(...)" );
>
> -            OUString aColorStr( aValue.copy( 4, aValue.getLength()-1 ) );
> +            OUString aColorStr(aValue.copy(4, aValue.getLength() - 5));
>
>               sal_Int32 nPos = 0;
>               sal_uInt16 nCol = 0;




More information about the LibreOffice mailing list