[colm] segfault during iter on stdin [noob]

Adrian Thurston thurston at colm.net
Sat Jan 20 19:11:18 UTC 2018


Hi Peter,

The program is segfaulting because parsing fails, Input comes back nil 
and the for loop causes a crash. Colm does not handle bad programs 
gracefully.

If you compile the program using -D PARSE and then run it you'll gain 
some insight into why parsing failed. Note that when compiling with -D 
PARSE you also get lots of output concerning the parse of the colm 
program.

-Adrian

On 2018-01-17 08:08, peter.reijnders at verpeteren.nl wrote:
> Hello
> 
> I tried to pickup colm because I realy like its potential.
> Due to the lack of examples and documentation I am fiddeling along and
> I am currently stuck with a simple task.
> 
> I try to parse a simple list with bullets and get a segfault.
> 
> 
> 
> A simple markdown file 'input.md':
> 
> ```
> * A list:
> * thing 1
> * thing 2:
> 	* thing 2a
> * thing 3
> 
> * Another list:
> * thang 1
> * thang 2:
> 	* thang 2a
> * thang 3
> ```
> 
> A simple script 'bullets.lm':
> 
> ```colm
> #!/usr/bin/env colm
> 
> lex
> #ignore 			/space+/
> literal 			`* `: `\n `\t
> token ws	 		/ ' ' /
> token bullet		/ '*' /
> token colon 		/ ':' /
> token newline 		/ '\n' /
> token tab 			/ 't' /
> token indent 		/ tab* /
> token identifier	/[a-zA-Z_]+/
> end
> 
> def item
> [bullet ws+ identifier ws* newline]
> |	[bullet ws+ itemlist]
> 
> def itemlist
> [identifier ws* colon ws* newline itemlist]
> 
> def itemlists
> [itemlist newline+ itemlists]
> |	[itemlist]
> |	[]
> 
> parse Input: itemlists[ stdin ]
> 
> for Id: itemlist in Input {
> print( Id.identifier )
> }
> ```
> 
> It compiles without problems, but crashes in the for loop.
> 
> ```bash
> $colm bullets.lm
> $gdb ./bullets
> ...
> (gdb) run <input.md
> Starting program: /redacted/bullets <input.md
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff7bafdb3 in iter_find (prg=0x55555575c010,
> psp=0x7fffffffbdc8, iter=0x55555576c160, try_first=1)
>     at iter.c:363
> 363		if ( try_first && ( iter->ref.kid->tree->id == iter->search_id ||
> any_tree ) ) {
> (gdb) bt
> #0  0x00007ffff7bafdb3 in iter_find (prg=0x55555575c010,
> psp=0x7fffffffbdc8, iter=0x55555576c160,
>     try_first=1) at iter.c:363
> #1  0x00007ffff7bb0090 in tree_iter_advance (prg=0x55555575c010,
> psp=0x7fffffffbdc8, iter=0x55555576c160)
>     at iter.c:401
> #2  0x00007ffff7bbc0bb in colm_execute_code (prg=0x55555575c010,
> exec=0x7fffffffe080, sp=0x55555576c160,
>     instr=0x555555758736 <parser_rootCode+54> "\270\r") at 
> bytecode.c:1998
> #3  0x00007ffff7bb1fbb in colm_execute (prg=0x55555575c010, 
> exec=0x7fffffffe080,
>     code=0x555555758700 <parser_rootCode> "\378\b\001") at 
> bytecode.c:413
> #4  0x00007ffff7bcee18 in colm_run_program2 (prg=0x55555575c010,
> argc=1, argv=0x7fffffffe218, argl=0x0)
>     at program.c:218
> #5  0x00007ffff7bcee5f in colm_run_program (prg=0x55555575c010,
> argc=1, argv=0x7fffffffe218) at program.c:227
> #6  0x0000555555556d8c in main (argc=1, argv=0x7fffffffe218) at 
> bullets.c:799
> (gdb)
> ```
> 
> What am I doing wrong?
> I am using a freshly cloned colm version '83e3cbcb25' and gcc version
> '(Debian 6.3.0-18) 6.3.0 20170516'.
> .
> I'd apreciate some tips.
> 
> Peter Reijnders
> 
> _______________________________________________
> colm mailing list
> colm at colm.net
> http://www.colm.net/cgi-bin/mailman/listinfo/colm




More information about the colm-users mailing list