Date: prev next · Thread: first prev next last
2010 Archives by date, by thread · List index


Fix for http://qa.openoffice.org/issues/show_bug.cgi?id=108228.

The problem behaviour occurs because the boolean expression "true"
evaluates to -1 rather than +1 in formulas in Writer. So if, for
example, you create a table formula in Writer, (Table->Formula) and
enter something like 1+(2==2), it evaluates to 0 rather than 2. It
turns out the reason for this is buried in sbxdef.hxx, where we have

// The numeric values of TRUE and FALSE
enum SbxBOOL { SbxFALSE = 0, SbxTRUE = -1 };

Bizarre, although I have very vague memories of Visual Basic defining
-1 to be true. Is that the reason? If it is supposed to be -1, someone
didn't get the memo, because struct SbxValues in sbxvar.hxx defines a
field "UINT16 nUShort", i.e. an unsigned int, which appears to be
where bools are stored. This is borne out by the code in sbxvalue.cxx
which has

SbxValue::PutBool( BOOL b )
    aRes.eType = SbxBOOL;
    aRes.nUShort = sal::static_int_cast< UINT16 >(b ? SbxTRUE : SbxFALSE);
    Put( aRes );

Weird - the cast changes the -1 to 65535. But wait! If we actually
look at the Put code, we have

SbxValue::Put( const SbxValues& rVal )
...
case SbxBOOL:           ImpPutBool( &p->aData, rVal.nInteger ); break;

i.e. we're now back to considering ints rather than uints, and since
SbxValues is defined as a union, the value we've stuffed into it looks
like -1 again if we try to pull an integer out of it. A lot of the
code to do with bools in SbxValues looks like this - it can't make up
its mind if the bool is supposed to be uint or an int, there are casts
everywhere, and it's a miracle it works. Or occasionally doesn't work,
according to the bug.

Lest someone think this bug is correct behaviour, (2==2) currently
gives 1 as expected, not -1; there's an explicit check in the output
in this case to get around the SbxTRUE = -1 thing. Anyway, this patch
fixes the bug, while leaving the whole SbxTRUE = -1 infrastructure
intact. Presumably it should be applied to master rather than 3.3,
since it's hardly an RC blocker :-P

Code contributed under MPL 1.1 / GPLv3+ / LGPLv3+ licenses.

Cheers,
Mattias
From cacb952d14de82625a93373d82c541810f2c38c5 Mon Sep 17 00:00:00 2001
From: Mattias Johnsson <m.t.johnsson@gmail.com>
Date: Wed, 8 Dec 2010 21:15:43 +1100
Subject: [PATCH] Fix i#108228 : bool has negative sign when used in formula expression

---
 sw/source/core/bastyp/calc.cxx |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 9f4b77c..a2a2a1f 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -1726,7 +1726,7 @@ double SwSbxValue::GetDouble() const
 
 SwSbxValue& SwSbxValue::MakeDouble()
 {
-    if( SbxSTRING == GetType() )
+    if( GetType() == SbxSTRING  || GetType() == SbxBOOL )
         PutDouble( GetDouble() );
     return *this;
 }
-- 
1.7.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.