ThomasMertes / seed7

Source code of Seed7
GNU General Public License v2.0
207 stars 11 forks source link

Segfault with an incomplete s7 source #3

Closed mingodad closed 3 years ago

mingodad commented 3 years ago

When testing s7 with the (incomplete) source file code bellow we get a segfault.

const proc: main is func
  begin
    writeln("hello world");
  end func;

Output:

gdb --args s7 hello-bug.sd7 
GNU gdb (Ubuntu 8.2-0ubuntu1~18.04) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from s7...done.
(gdb) r
Starting program: /home/mingo/dev/c/A_programming-languages/seed7/prg/s7 hello-bug.sd7
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
SEED7 INTERPRETER Version 5.0.11752  Copyright (c) 1990-2020 Thomas Mertes
*** hello-bug.sd7(1):46: ";" expected found "proc"
const proc: main is func
----------^
evaluate unknown const: const is <SYMBOLOBJECT> 93824995462896
*** hello-bug.sd7(1):33: Exception raised
const proc: main is func
----------^
*** hello-bug.sd7(1):46: ";" expected found ":"
const proc: main is func
-----------^
evaluate unknown const: proc is <SYMBOLOBJECT> 93824995462992
*** hello-bug.sd7(1):33: Exception raised
const proc: main is func
-----------^
*** hello-bug.sd7(1):46: ";" expected found "main"
const proc: main is func
----------------^
evaluate unknown const: : is <SYMBOLOBJECT> 93824995463072
*** hello-bug.sd7(1):33: Exception raised
const proc: main is func
----------------^
*** hello-bug.sd7(1):46: ";" expected found "is"
const proc: main is func
-------------------^
evaluate unknown const: main is <SYMBOLOBJECT> 93824995463168
*** hello-bug.sd7(1):33: Exception raised
const proc: main is func
-------------------^
*** hello-bug.sd7(1):46: ";" expected found "func"
const proc: main is func
------------------------^
evaluate unknown const: is is <SYMBOLOBJECT> 93824995463248
*** hello-bug.sd7(1):33: Exception raised
const proc: main is func
------------------------^
*** hello-bug.sd7(2):46: ";" expected found "begin"
  begin
-------^
evaluate unknown const: func is <SYMBOLOBJECT> 93824995463328
*** hello-bug.sd7(2):33: Exception raised
  begin
-------^
*** hello-bug.sd7(3):46: ";" expected found "writeln"
    writeln("hello world");
-----------^
evaluate unknown const: begin is <SYMBOLOBJECT> 93824995463424
*** hello-bug.sd7(3):33: Exception raised
    writeln("hello world");
-----------^
*** hello-bug.sd7(3):48: Undefined type for literal "hello world"
    writeln("hello world");
-------------------------^

Program received signal SIGSEGV, Segmentation fault.
new_nonempty_expression_object (first_element=0x555555869180, list=0x7fffffffd600, typeof_object=<optimized out>)
    at object.c:98
98      created_list->type_of = take_type(typeof_object);
(gdb) bt
#0  new_nonempty_expression_object (first_element=0x555555869180, list=0x7fffffffd600, typeof_object=<optimized out>)
    at object.c:98
#1  0x00005555555f9e7f in read_call_expression (do_match_expr=do_match_expr@entry=false) at expr.c:132
#2  0x00005555555fa129 in read_dot_expression (do_match_expr=do_match_expr@entry=false) at expr.c:236
#3  0x00005555555fa42e in pars_infix_expression (priority=49, do_match_expr=false) at expr.c:353
#4  0x00005555555fce5c in declAny (objects=0x555555868ea0) at analyze.c:337
#5  analyzeProg (sourceFileArgument=sourceFileArgument@entry=0x555555868010, 
    sourceFilePath=sourceFilePath@entry=0x555555868480, options=options@entry=256, 
    libraryDirs=libraryDirs@entry=0x55555583ce10, protFileName=protFileName@entry=0x0, 
    err_info=err_info@entry=0x7fffffffd830) at analyze.c:482
#6  0x00005555555ff58f in analyzeFile (sourceFileArgument=0x555555868010, options=256, libraryDirs=0x55555583ce10, 
    protFileName=0x0, err_info=0x7fffffffd830) at analyze.c:604
#7  0x0000555555567993 in analyze (protFileName=<optimized out>, libraryDirs=<optimized out>, 
    options=<optimized out>, sourceFileArgument=0x555555868010) at analyze.c:631
#8  main (argc=<optimized out>, argv=<optimized out>) at s7.c:414
ThomasMertes commented 3 years ago

I can confirm this error. Seed7 is defined in the library seed7_05.s7i. Without including this library nothing will work. In this regard this is a rather strange test case. On the other hand a segfault should not happen. IIRC I investigated this years ago and found out that it could be avoided by adding a check in a performance critical part of the parser. If I have time I will take another look and there is hopefully a possibility to fix this without hindering performance.

ThomasMertes commented 3 years ago

This has been fixed with release 2021-01-30.