Skip to content

Commit

Permalink
fbc: sf.net # 996: fix null pointer access checking for defined(udt.c…
Browse files Browse the repository at this point in the history
…ast)

fixed an internal null pointer access:

    type T
        field as long
        declare sub proc()
    end type

    #if defined( T.cast )
    #endif

    Aborting due to runtime error 7 (null pointer access) at line 704
    of src\compiler\parser-identifier.bas::CIDENTIFIERORUDTMEMBER()
  • Loading branch information
jayrm committed Dec 3, 2023
1 parent 82f3342 commit e6e9b7e
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -25,6 +25,7 @@ Version 1.10.1
- emscripten/fbc: -sASYNCIFY wasn't passed to emcc at link-time as needed by recent Emscripten
- sf.net #993: ignore (parse) single line comments for macros invoked with optional parentheses instead of passing as an argument to macro
- sf.net #994: Bad handling of macro argument evaluation - reset file pointers to previous context after evaluating arguments in __fb_query_symbol__, __fb_eval__, __fb_arg_extract__, __fb_iif__, and releasing lexer context
- sf.net #996: fbc null pointer access testing defined(UDT.cast)


Version 1.10.0
Expand Down
16 changes: 15 additions & 1 deletion src/compiler/parser-identifier.bas
Expand Up @@ -689,19 +689,33 @@ function cIdentifierOrUDTMember _
end if

'' else there are member procs, so search for keywords as members
'' !!!TODO!!! - optimize lookups
'' symbGetCompXXX() functions test for things we already know here

select case as const lexGetToken( )
case FB_TK_CONSTRUCTOR
sym = symbGetCompCtorHead( base_parent )
'' if( base_parent->udt.ext ) then
'' sym = base_parent->udt.ext->ctorhead
'' end if

case FB_TK_DESTRUCTOR
sym = symbGetCompDtor1( base_parent )
'' if( base_parent->udt.ext ) then
'' sym = base_parent->udt.ext->dtor1
'' end if

case FB_TK_LET
sym = symbGetCompOpOvlHead( base_parent, AST_OP_ASSIGN )
'' if( base_parent->udt.ext ) then
'' sym = symbGetUDTOpOvlTb( base_parent )(AST_OP_ASSIGN - AST_OP_SELFBASE)
'' end if

case FB_TK_CAST
sym = symbGetUDTOpOvlTb( base_parent )(AST_OP_CAST - AST_OP_SELFBASE)
sym = symbGetCompOpOvlHead( base_parent, AST_OP_CAST )
'' if( base_parent->udt.ext ) then
'' sym = symbGetUDTOpOvlTb( base_parent )(AST_OP_CAST - AST_OP_SELFBASE)
'' end if

end select

Expand Down
90 changes: 75 additions & 15 deletions tests/syntax/defined-3.bas
@@ -1,11 +1,47 @@
type T
#print "T1 -- fields only"
type T1
value as integer
end type

#if defined( T1.value )
#print "T1.value defined"
#else
#print "T1.value not defined - NOK"
#endif

#if defined( T1.constructor )
#print "T1.constructor defined - NOK"
#else
#print "T1.constructor not defined"
#endif

#if defined( T1.destructor )
#print "T1.constructor defined - NOK"
#else
#print "T1.constructor not defined"
#endif

#if defined( T1.let )
#print "T1.let defined - NOK"
#else
#print "T1.let not defined"
#endif

#if defined( T1.cast )
#print "T1.cast defined - NOK"
#else
#print "T1.cast not defined"
#endif

#print "T2 -- fields and procedures"
type T2
value as integer
static svalue as integer
declare sub proc()
declare static sub sproc()
end type

sub T.proc()
sub T2.proc()

#if defined( value )
#print "value defined"
Expand All @@ -31,31 +67,55 @@ sub T.proc()
#print "sproc not defined - NOK"
#endif

#if ENABLE_CHECK_BUGS
#if defined( T2.value )
#print "T2.value defined"
#else
#print "T2.value not defined - NOK"
#endif

#if defined( T.value )
#print "T.value defined"
#if defined( T2.proc )
#print "T2.proc defined"
#else
#print "T.value not defined - NOK"
#print "T2.proc not defined - NOK"
#endif

#if defined( T.proc )
#print "T.proc defined"
#if defined( T2.svalue )
#print "T2.svalue defined"
#else
#print "T.proc not defined - NOK"
#print "T2.svalue not defined - NOK"
#endif

#if defined( T.svalue )
#print "T.svalue defined"
#if defined( T2.sproc )
#print "T2.sproc defined"
#else
#print "T.svalue not defined - NOK"
#print "T2.sproc not defined - NOK"
#endif

#if defined( T.sproc )
#print "T.sproc defined"
#if defined( T2.constructor )
#print "T2.constructor defined - NOK"
#else
#print "T2.constructor not defined"
#endif

#if defined( T2.destructor )
#print "T2.constructor defined - NOK"
#else
#print "T.sproc not defined - NOK"
#print "T2.constructor not defined"
#endif

#if defined( T2.let )
#print "T2.let defined - NOK"
#else
#print "T2.let not defined"
#endif

#if defined( T2.cast )
#print "T2.cast defined - NOK"
#else
#print "T2.cast not defined"
#endif

#if ENABLE_CHECK_BUGS

#if defined( this.svalue )
#print "this.svalue defined"
Expand Down
15 changes: 15 additions & 0 deletions tests/syntax/r/dos/defined-3.txt
@@ -1,4 +1,19 @@
T1 -- fields only
T1.value defined
T1.constructor not defined
T1.constructor not defined
T1.let not defined
T1.cast not defined
T2 -- fields and procedures
value defined
proc defined
svalue defined
sproc defined
T2.value defined
T2.proc defined
T2.svalue defined
T2.sproc defined
T2.constructor not defined
T2.constructor not defined
T2.let not defined
T2.cast not defined
15 changes: 15 additions & 0 deletions tests/syntax/r/linux-x86/defined-3.txt
@@ -1,4 +1,19 @@
T1 -- fields only
T1.value defined
T1.constructor not defined
T1.constructor not defined
T1.let not defined
T1.cast not defined
T2 -- fields and procedures
value defined
proc defined
svalue defined
sproc defined
T2.value defined
T2.proc defined
T2.svalue defined
T2.sproc defined
T2.constructor not defined
T2.constructor not defined
T2.let not defined
T2.cast not defined
15 changes: 15 additions & 0 deletions tests/syntax/r/linux-x86_64/defined-3.txt
@@ -1,4 +1,19 @@
T1 -- fields only
T1.value defined
T1.constructor not defined
T1.constructor not defined
T1.let not defined
T1.cast not defined
T2 -- fields and procedures
value defined
proc defined
svalue defined
sproc defined
T2.value defined
T2.proc defined
T2.svalue defined
T2.sproc defined
T2.constructor not defined
T2.constructor not defined
T2.let not defined
T2.cast not defined
15 changes: 15 additions & 0 deletions tests/syntax/r/win32/defined-3.txt
@@ -1,4 +1,19 @@
T1 -- fields only
T1.value defined
T1.constructor not defined
T1.constructor not defined
T1.let not defined
T1.cast not defined
T2 -- fields and procedures
value defined
proc defined
svalue defined
sproc defined
T2.value defined
T2.proc defined
T2.svalue defined
T2.sproc defined
T2.constructor not defined
T2.constructor not defined
T2.let not defined
T2.cast not defined
15 changes: 15 additions & 0 deletions tests/syntax/r/win64/defined-3.txt
@@ -1,4 +1,19 @@
T1 -- fields only
T1.value defined
T1.constructor not defined
T1.constructor not defined
T1.let not defined
T1.cast not defined
T2 -- fields and procedures
value defined
proc defined
svalue defined
sproc defined
T2.value defined
T2.proc defined
T2.svalue defined
T2.sproc defined
T2.constructor not defined
T2.constructor not defined
T2.let not defined
T2.cast not defined

0 comments on commit e6e9b7e

Please sign in to comment.