Skip to content

Commit 402520c

Browse files
committed
fbc: use uinteger types for count in new[count]
1 parent 6c65ce2 commit 402520c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/compiler/ast-node-mem.bas

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private function hCallCtorList _
6363
dim as FBSYMBOL ptr cnt = any, label = any, iter = any
6464
dim as ASTNODE ptr tree = any
6565

66-
cnt = symbAddTempVar( FB_DATATYPE_INTEGER )
66+
cnt = symbAddTempVar( FB_DATATYPE_UINT )
6767
label = symbAddLabel( NULL )
6868
iter = symbAddTempVar( typeAddrOf( dtype ), subtype )
6969

@@ -199,7 +199,7 @@ function astBuildNewOp _
199199
if( save_elmts ) then
200200
'' length + sizeof( integer ) (to store the vector size)
201201
lenexpr = astNewBOP( AST_OP_ADD, lenexpr, _
202-
astNewCONSTi( typeGetSize( FB_DATATYPE_INTEGER ), FB_DATATYPE_UINT ) )
202+
astNewCONSTi( typeGetSize( FB_DATATYPE_UINT ), FB_DATATYPE_UINT ) )
203203
end if
204204

205205
newexpr = rtlMemNewOp( op, lenexpr, dtype, subtype )
@@ -216,15 +216,15 @@ function astBuildNewOp _
216216
'' *tempptr = elements
217217
tree = astNewLINK( tree, _
218218
astNewASSIGN( _
219-
astNewDEREF( astNewVAR( tmp, , typeAddrOf( FB_DATATYPE_INTEGER ) ) ), _
219+
astNewDEREF( astNewVAR( tmp, , typeAddrOf( FB_DATATYPE_UINT ) ) ), _
220220
hElements( elementsexpr, elementstreecount ), _
221221
AST_OPOPT_ISINI ) )
222222

223-
'' tempptr += len( integer )
223+
'' tempptr += len( uinteger )
224224
tree = astNewLINK( tree, _
225225
astNewSelfBOP( AST_OP_ADD_SELF, _
226226
astNewVAR( tmp, , typeAddrOf( FB_DATATYPE_VOID ) ), _
227-
astNewCONSTi( typeGetSize( FB_DATATYPE_INTEGER ) ), _
227+
astNewCONSTi( typeGetSize( FB_DATATYPE_UINT ) ), _
228228
NULL ) )
229229
end if
230230

@@ -271,15 +271,15 @@ private function hCallDtorList( byval ptrexpr as ASTNODE ptr ) as ASTNODE ptr
271271

272272
'' DELETE[]'s counter is at: cast(integer ptr, vector)[-1]
273273

274-
'' elmts = *cast( integer ptr, cast( any ptr, vector ) + -sizeof( integer ) )
274+
'' elmts = *cast( uinteger ptr, cast( any ptr, vector ) + -sizeof( uinteger ) )
275275
'' (using AST_CONVOPT_DONTCHKPTR to support derived UDT pointers)
276276
tree = astBuildVarAssign( _
277277
elmts, _
278278
astNewDEREF( _
279-
astNewCONV( typeAddrOf( FB_DATATYPE_INTEGER ), NULL, _
279+
astNewCONV( typeAddrOf( FB_DATATYPE_UINT ), NULL, _
280280
astNewBOP( AST_OP_ADD, _
281281
astCloneTree( ptrexpr ), _
282-
astNewCONSTi( -typeGetSize( FB_DATATYPE_INTEGER ) ) ), _
282+
astNewCONSTi( -typeGetSize( FB_DATATYPE_UINT ) ) ), _
283283
AST_CONVOPT_DONTCHKPTR ) ), _
284284
AST_OPOPT_ISINI )
285285

src/compiler/parser-quirk-mem.bas

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,14 @@ function cOperatorNew( ) as ASTNODE ptr
114114
if( elementsexpr = NULL ) then
115115
elementsexpr = astNewCONSTi( 1, FB_DATATYPE_UINT )
116116
else
117-
'' hack(?): make sure it's a uinteger, otherwise it may crash later, fixes bug #2533376 (counting_pine)
118-
elementsexpr = astNewCONV( FB_DATATYPE_UINT, NULL, elementsexpr )
117+
'' Constant?
118+
if( astIsCONST( elementsexpr ) ) then
119+
'' check at compile time
120+
elementsexpr = astNewCONSTi( cConstIntExprRanged( elementsexpr, FB_DATATYPE_UINT ), FB_DATATYPE_UINT )
121+
else
122+
'' make sure it's a uinteger, otherwise it may crash later, fixes bug #2533376 (counting_pine)
123+
elementsexpr = astNewCONV( FB_DATATYPE_UINT, NULL, elementsexpr, AST_CONVOPT_SIGNCONV )
124+
end if
119125
if( elementsexpr = NULL ) then
120126
errReport( FB_ERRMSG_TYPEMISMATCH, TRUE )
121127
elementsexpr = astNewCONSTi( 1, FB_DATATYPE_UINT )

0 commit comments

Comments
 (0)