User:Hanya/Iif Problem

From Apache OpenOffice Wiki
< User:Hanya
Revision as of 17:43, 20 December 2014 by Hanya (Talk | contribs)

Jump to: navigation, search

Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614

Error code 87302 is produced when some code is modified contains Iif runtime function.

Disassembled Original

Sub Main
IIf(true, 1.0, "")
End Sub
Position Op Op1      Op2        OpStr   
-----------------------------------------
00000000                            Lbl00000000:
00000000 45 00000000          	JUMP	Lbl0000  // Label
; Sub Main
00000005                            Main:
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)
; IIf(true, 1.0, "")
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)
00000017 18                   	ARGC	     // new argv
00000018 80 00000002 0000000C 	RTL	true	; Variant
00000021 19                   	ARGV	
00000022 40 00000004          	NUMBER	"1"
00000027 19                   	ARGV	
00000028 41 00000005          	STRING	""
0000002D 19                   	ARGV	
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args
00000037 1C                   	GET	
; End Sub
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)
00000041 2B                   	LEAVE	

Disassembled with Problem

Second argument for IIf function is changed from 1.0 to "". Execute the code after the change -> strange error.

Sub Main
IIf(true, "", "")
End Sub
00000000                            Lbl00000000:
00000000 45 00000000          	JUMP	Lbl0000
; Sub Main
00000005                            Main:
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)
; IIf(true, "", "")
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)
00000017 18                   	ARGC	
00000018 80 00000002 0000000C 	RTL	true	; Variant
00000021 19                   	ARGV	
00000022 41 00000004          	STRING	""
00000027 19                   	ARGV	
00000028 41 00000004          	STRING	""
0000002D 19                   	ARGV	
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args
00000037 1C                   	GET	
; End Sub
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)
00000041 2B                   	LEAVE	

Disassembled without Problem after Restarting

After the modification and error mentioned above, restart the office. And then execute the code, no error.

00000000                            Lbl00000000:
00000000 45 00000000          	JUMP	Lbl0000
; Sub Main
00000005                            Main:
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)
; IIf(true, "", "")
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)
00000017 18                   	ARGC	
00000018 80 00000002 0000000C 	RTL	true	; Variant
00000021 19                   	ARGV	
00000022 41 00000004          	STRING	""
00000027 19                   	ARGV	
00000028 41 00000004          	STRING	""
0000002D 19                   	ARGV	
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args
00000037 1C                   	GET	
; End Sub
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)
00000041 2B                   	LEAVE	

Differences

With the same code, different operation codes are generated for IIf function.

Position Op Op1      Op2        OpStr   
-----------------------------------------
// with problem
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args
// restarted
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args

Op2 is type for this OpCode:

// SbiDisas::TypeOp
pTypes[][13] = {
  "Empty","Null","Integer","Long","Single","Double",
  "Currency","Date","String","Object","Error","Boolean",
  "Variant" };

The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. Therefore the problem is caused by the wrong compilation when the code is modified.

Code

00000000                            Lbl00000000:
00000000 45 00000000          	JUMP	Lbl0000
; Sub Main
00000005                            Main:
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)
; IIf(true, "", "")
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)
00000017 18                   	ARGC 
// SbiExprList::Gen in exprgen.cxx
00000018 80 00000002 0000000C 	RTL	true	; Variant
00000021 19                   	ARGV 
// SbiExprList::Gen in exprgen.cxx
00000022 41 00000004          	STRING	""
00000027 19                   	ARGV	
00000028 41 00000004          	STRING	""
0000002D 19                   	ARGV 
// SbiExprNode::GenElement in exprgen.cxx
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args
00000037 1C                   	GET 
// SbiParser::Symbol in parser.cxx
; End Sub
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)
00000041 2B                   	LEAVE 
// SbiParser::DefProc in dim.cxx

In SbiParser::CheckRTLForSym method, pVar->GetType() call should return SbxEMPTY for rSym == "IIf". But SbxINTEGER is returned when the problem was happen. The return value of the function, instance of SbiSymDef gets wrong type. Then the wrong type is passed to new SbiExprNode instance in SbiExpression::Term method. When I change the second argument from "" to false, I got SbxSTRING for the type.

While first compilation, SbxObject::Find( rName, t ) returns NULL in SbiStdObject::Find method for rName = "IIf". But the second compilation, the call returns something. Who does define IIf as something in the runtime?

Personal tools