Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

This code crashes AHK/U32: a := 1 /* 0x1000 */



  • Please log in to reply
9 replies to this topic
atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007
Hello there.
 
I was writing a bit if code when suddenly AHK/U32 crashed on me. After trimming the offending code to its minimal expression, I've been able to determine that the following code crashes Autohotkey 1.1.10.1 U32 (that is, Unicode x86):
a := 1 /* 0x1000 */
The spaces don't matter nor does the variable name or the value assigned, but everything else does: it has to be a :=, not an =, it has to be a slash-star comment, not a semicolon, it has to be an hexadecimal number inside the comment, and the number must be 0x1000 or higher. How's that for specific?
Regards,
Antonio

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

As per docs:

In addition, the /* and */ symbols can be used to comment out an entire section, but only if the symbols appear at the beginning of a line...

In your example, /**/(and anything between it), is not treated as a comment but rather as an expression.



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
wink.png

a := 1    ; 0x1000 


atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007

Thanks for the comments, Coco, that certainly helps explaining the specificity of the bug, but also please notice that AutoHotkey doesn't complain about an invalid expression or a syntax problem. It crashes:

autohotkey_crash.png


Regards,
Antonio

uname
  • Members
  • 194 posts
  • Last active: Oct 17 2015 08:46 AM
  • Joined: 13 Jun 2012
a := 1 /* 0x1000 */
varname assignment number division dereference memoryOffset
You get what you pay for ©

atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007
@uname: do you mean it's not a bug or that I should accept bugs in AHK because it's free? :-P
Regards,
Antonio

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
✓  Best Answer
The crash isn't a bug, but the direct result of carrying out your instructions. By writing a := 1 /* 0x1000, you instructed the program to dereference the address 0x1000. The expected result when dereferencing an invalid address is an Access Violation exception - code c0000005. This code is (just barely) shown in your screenshot.

Any address below 0x1000 is immediately known to be invalid, so is not dereferenced.

AutoHotkey allows you to write invalid expressions, and does its best to make sense from them. This is by design. Perhaps a future version will detect the error in your code - specifically, the two operators at the end of your expression which have insufficient operands - */ (multiplication and division).

If there are insufficient values on the stack to carry out an operation, the expression is safely aborted and results in an empty string. However, in this case evaluation of the expression doesn't get that far.

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

It's not a bug per se, but rather an invalid expression. You get the crash because of the expression.



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007
Thanks for the detailed explanation, Lexikos. 
 
Perhaps it will be worth it to see what I was (wrongly, I know) trying to do:
UnicodeSpaces := {0x0020: "Space", 0x00A0: "No-Break Space", 0x1680: "Ogham Space Mark"
	, 0x180E: "Mongolian Vowel Separator", 0x2000: "En quad" /* 0x2002 is preferred */
	, 0x2001: "Em quad" /* 0x2003 is preferred */, 0x2002: "En Space", 0x2003: "Em Space"
	, 0x2004: "Three-Per-Em Space", 0x2005: "Four-Per-Em Space", 0x2006: "Six-Per-Em Space"
	, 0x2007: "Figure Space", 0x2008: "Punctuation Space", 0x2009: "Thin Space", 0x200A: "Hair Space"
	, 0x200B: "Zero Width Space", 0x200C: "Zero Width Non Joiner", 0x200D: "Zero Width Joiner"
	, 0x202F: "Narrow No-Break Space", 0x205F: "Medium Mathematical Space", 0x2060: "Word Joiner"
	, 0x3000: "Ideographic Space", 0xFEFF: "Zero Width No-Break Space" /* Deprecated except as BOM */}
(just in case it helps decide what to change, if there's any inclination to it)
 
Thanks again for the explanations.
Regards,
Antonio

RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010

UnicodeSpaces := {0x0020: "Space", 0x00A0: "No-Break Space", 0x1680: "Ogham Space Mark"
, 0x180E: "Mongolian Vowel Separator", 0x2000: "En quad" ; 0x2002 is preferred
, 0x2001: "Em quad", 0x2002: "En Space", 0x2003: "Em Space" ; 0x2003 is preferred
, 0x2004: "Three-Per-Em Space", 0x2005: "Four-Per-Em Space", 0x2006: "Six-Per-Em Space"
, 0x2007: "Figure Space", 0x2008: "Punctuation Space", 0x2009: "Thin Space", 0x200A: "Hair Space"
, 0x200B: "Zero Width Space", 0x200C: "Zero Width Non Joiner", 0x200D: "Zero Width Joiner"
, 0x202F: "Narrow No-Break Space", 0x205F: "Medium Mathematical Space", 0x2060: "Word Joiner"
, 0x3000: "Ideographic Space", 0xFEFF: "Zero Width No-Break Space"} ; Deprecated except as BOM

This would be the correct way of doing it in AHK language since as explained in the help file:
 

In addition, the /* and */ symbols can be used to comment out an entire section, but only if the symbols appear at the beginning of a line as in this example:
/*
MsgBox, This line is commented out (disabled).
MsgBox, This one too.
*/


AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL