Archive: Bug in compiler


Bug in compiler
 


Section "ThisName"

MessageBox MB_YESNO "Are you male?" IDYES IsMale
MessageBox MB_OK "You aren’t male, possibly female."
Goto +3 ; Jumps to the third instruction from here, skipping the
; “You are male.” messagebox.
IsMale: ; To this label jumps the messagebox if Yes is clicked.
MessageBox MB_OK "You are male."
EndOfSection:
>SectionEnd
>
This doesn't generate an error when compiling, but does when executing: Invalid OPcode. I think this is a bug. I know how to solve this with replacing +3 by a label, but anyway...

There is no third instruction from that Goto... You should be careful with relative jumps.


I know, but the compiler doesn't see that, only when I execute it.


Fixing this one specific case is probably not too hard but making the compiler attempt to spot the users mistakes is a lot of work for relatively little return. Personally this just strikes me as a case of garbage in leads to garbage out :P


When I do this in .onInit function, with Modern UI and Install Options 2, show a strange window (you only can close this window by using Ctrl+Alt+Del) :


When I don't use Install Options, don't show any window.

This is the normal window (When I don't use this goto at .onInit function finish) :


deguix, that code makes the installer jump 3 commands ahead, you can't know what affect a code that's not related to the function will have on the installer. In your case, this was it, in another case there is no command there, if the function is at the end of the script it might just access random memory. In any case, putting wrong code in the compiler on purpose is a bad idea.


Yes, but when I wrote that code, I didn't know that it was wrong code:
Jumping from Goto +3, where does that lead?
To the third line from the Goto Instruction, the third instruction from the Goto instruction (labels, section ends, function ends or macro ends included?).

To me, the above code should jump to the messagebox.


I guess this is just an issue with what you expect to happen. I read your code and expected trouble because I count only things that I think will generate an opcode as valid goto targets. After reading the docs thoroughly I'm a little unsure as to whether or not a label is counted when using offsets. I don't think they are but then you *can* goto to a label. Add to that the fact that you can use GetXXXAddress() to find goto targets and it really gets confusing...


If you can go to labels, no error would ne generated, since 'EndOfSection:' is the third instruction (labels included) from the Goto Instruction.


It only counts instructions.

From Goto's docs:

If +offset or -offset is specified, jump is relative by offset instructions. Goto +1 goes to the next instruction, Goto -1 goes to the previous instruction, etc.

Where is instruction defined though? Is it necessarily clear what an instruction is or isn't to people other than yourself KiCHiK? Logically I can usually work it out by looking at the code, it tends to "goto" as I expect. However I'm just trying to play Devil's Advocate here :D


Welp, from Label:

Labels are the targets of Goto instructions, or of the various branching instructions (such as IfErrors, MessageBox, IfFileExists, and StrCmp). Labels must be within a Section or a Function. Labels are local in scope, meaning they are only accessible from within the Section or Function that they reside in. To declare a label, simply do:

MyLabel:

Labels cannot begin with a -, +, !, $, or 0-9. When specifying labels for the various instructions that require them, remember that both an empty string ("") and 0 both represent the next instruction (meaning no Goto will occur). Labels beginning with a period (.) are global, meaning you can jump to them from any function or section (though you cannot jump to an uninstall global label from the installer, and vice versa).
And from Goto:

If a user variable is specified, jumps to absolute address (generally you will want to get this value from a function like GetLabelAddress). Compiler flag commands and SectionIn aren't instructions so jumping over them has no effect.

Yep, I'd already read that. Doesn't really answer my question about what is or isn't an instruction though. But since I don't really have a problem with goto and was just playing Devil's Advocate I'll shut up now :)


The label part doesn't mention a thing about label being an instruction and the goto part tells you exactly what +* jumps over.


That is something that will propably change with the new documentation of NSIS:
Listed where you can use sertain instructions (in sections, functions, macros or outside them).
Listed to what instructions you can(not) jump to with Goto +n or Goto -n.


Who put that there? :p
http://nsis.sourceforge.net/Docs/Chapter3.html#3.4


Great work! I didn't even need the Goto +3, but my thread became a discussion about what to jump and what not. Now you see what's the result!