Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash if endtype is missing #75

Open
crushroll opened this issue Jun 6, 2022 · 3 comments
Open

Crash if endtype is missing #75

crushroll opened this issue Jun 6, 2022 · 3 comments

Comments

@crushroll
Copy link

I've been using BlitzMax for years and never discovered this issue.

I accidently left out the EndType, and MaxIDE popped up a dialog titled "Windows Exception" and the message says "EXCEPTION_ACCESS_VIOLATION". When you click "OK" it crashes.

Easy to test. Open a new file, type "Type A" and press the the compile button.

Note: When using VSCode extension, I think the compiler crashes instead (assume it doesn't use MaxIDE).

@GWRon
Copy link

GWRon commented Jun 20, 2022

Compiling MaxIDE in Debug, adding Type A and pressing compile leads to this:

[100%] Linking:maxide.debug
Executing:maxide.debug
DebugLog:WARNING: Toolbars should *only* be parented to window gadgets.
Assertion [partition >= 0] failed at BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/scintilla/src/Partitioning.h 162
Aborted (core dumped)

gdb:

Assertion [partition >= 0] failed at /BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/scintilla/src/Partitioning.h 162

Thread 1 "maxide.debug" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: Datei oder Verzeichnis nicht gefunden.
(gdb) bt
#0  0x00007ffff14e6e87 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff14e87f1 in __GI_abort () at abort.c:79
#2  0x000000000078277d in Scintilla::Platform::Assert(char const*, char const*, int) (c=<optimized out>, file=<optimized out>, line=<optimized out>)
    at /BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/scintilla/gtk/PlatGTK.cxx:2029
#3  0x00000000004f0668 in LineVector<int>::IndexLineStart(long, int) const ()
#4  0x00000000005427f0 in Scintilla::Editor::WndProc(unsigned int, unsigned long, long) ()
#5  0x0000000000570c1e in Scintilla::ScintillaBase::WndProc(unsigned int, unsigned long, long) (this=0x1ab9c00, iMessage=<optimized out>, wParam=18446744073709551615, lParam=2)
    at /BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/scintilla/src/ScintillaBase.cxx:1162
#6  0x00000000004d3bb6 in scintilla_send_message () at /BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/scintilla/gtk/ScintillaGTK.cxx:872
#7  0x00000000004e07d6 in bmx_mgta_scintilla_positionfromline (sci=<optimized out>, line=line@entry=-1, valueInBytes=valueInBytes@entry=1)
    at /BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/glue.c:181
#8  0x00000000004c0b8c in _maxgui_maxguitextareascintilla_linuxgtk_TGTKScintillaTextArea_SetSelection_iii (o=<optimized out>, bbt_pos=<optimized out>, bbt_length=<optimized out>, bbt_units=<optimized out>) at /BlitzMaxNG/mod/maxgui.mod/maxguitextareascintilla.mod/linuxgtk.bmx:155
#9  0x000000000082f005 in maxgui_maxgui_SelectTextAreaText (bbt_textarea=<optimized out>, bbt_pos=<optimized out>, bbt_pos@entry=-1, bbt_length=<optimized out>, 
    bbt_length@entry=0, bbt_units=<optimized out>, bbt_units@entry=2) at /BlitzMaxNG/mod/maxgui.mod/maxgui.mod/maxgui.bmx:1664
#10 0x0000000000460a65 in __m_maxide_TOpenCode_HighlightLine_ii (o=<optimized out>, bbt_line=<optimized out>, bbt_column=<optimized out>)
    at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:4424
#11 0x000000000041f824 in __m_maxide_TOpenCode_Debug_ii (o=<optimized out>, bbt_line=<optimized out>, bbt_column=<optimized out>)
    at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:4443
#12 0x000000000048415b in __m_maxide_TCodePlay_SelectError_Sii (o=<optimized out>, bbt_path=<optimized out>, bbt_column=<optimized out>, bbt_line=<optimized out>)
    at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:6454
#13 0x0000000000492157 in __m_maxide_TCodePlay_ParseError_S (o=<optimized out>, bbt_err=<optimized out>, bbt_err@entry=0x7fffd6ec1ea0)
    at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:6480
#14 0x000000000046b9d3 in __m_maxide_TOutputPanel_OnEvent (o=<optimized out>) at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:4038
#15 0x000000000045a678 in __m_maxide_TCodePlay_poll (o=<optimized out>) at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:7979
#16 0x00000000004be0e8 in _bb_main () at /home/ronny/Arbeit/Projekte/BlitzMax/BlitzMaxNG.project/maxide/maxide.bmx:272
#17 0x0000000000918763 in __bb_brl_appstub_appstub () at /BlitzMaxNG/mod/brl.mod/appstub.mod/.bmx/appstub.bmx.debug.linux.x64.c:8
#18 0x000000000041d4ff in main ()
(gdb) q

@GWRon
Copy link

GWRon commented Jun 20, 2022

	Method HighlightLine(line,column = 0)
		Local i:Int, tmpCharLineStart% = TextAreaChar(textarea,line)
		Local tmpLine$ = TextAreaText( textarea, line, 1, TEXTAREA_LINES ).Replace("~r","").Replace("~n","")
		For i = column Until tmpLine.Length
			If IsNotAlpha(tmpLine[i]) Then tmpCharLineStart:+1 Else Exit
		Next
		SelectTextAreaText textarea,line-1,0,TEXTAREA_LINES '<----------- error happens here
		SelectTextAreaText textarea,line+1,0,TEXTAREA_LINES
		If i = tmpLine.Length Or ..
		( TextAreaCharX( textarea, tmpCharLineStart + tmpLine.Length-i ) - TextAreaCharX( textarea, tmpCharLineStart ) >= ClientWidth(textarea) ) Then
			SelectTextAreaText textarea,line,1,TEXTAREA_LINES
		Else
			SelectTextAreaText textarea,tmpCharLineStart,tmpLine.Length-i,TEXTAREA_CHARS
		EndIf
	EndMethod

Seems it must be:

...
		SelectTextAreaText textarea,Max(line-1,0),0,TEXTAREA_LINES
		SelectTextAreaText textarea,line+1,0,TEXTAREA_LINES
...

Or "SelectTextAreaText" should take care (btw in this case the scintilla textarea implementation)

-> bmx_mgta_scintilla_positionfromline should not be fed with negative numbers it seems.

@GWRon
Copy link

GWRon commented Jun 20, 2022

adding this to maxgui.mod/maxguitextarescintilla.mod/glue.c:

int bmx_mgta_scintilla_positionfromline(SCI_HANDLE sci, int line, int valueInBytes) {
	if (line < 0) { line = 0; } 
	return scintilla_send_message(sci, SCI_INDEXPOSITIONFROMLINE, line, SC_LINECHARACTERINDEX_UTF16);
}

void bmx_mgta_scintilla_setselectionstart(SCI_HANDLE sci, int pos) {
	if (pos < 0) { pos = 0; } 
	scintilla_send_message(sci, SCI_SETSELECTIONSTART, pos, 0);
}

does work too.
Dunno what other functions need to ensure not using negative values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants