@@ -221,7 +221,9 @@ const char* basic_eval_str_fn(const char* fn_name, struct basic_ctx* ctx)
221221 struct ub_proc_fn_def * def = basic_find_fn (fn_name + 2 , ctx );
222222 const char * rv = "" ;
223223 if (def ) {
224- ctx -> call_stack_ptr ++ ;
224+ if (!new_stack_frame (ctx )) {
225+ return "" ;
226+ }
225227 init_local_heap (ctx );
226228
227229 int bracket_depth = 0 ;
@@ -265,7 +267,7 @@ const char* basic_eval_str_fn(const char* fn_name, struct basic_ctx* ctx)
265267 buddy_free (ctx -> allocator , atomic );
266268
267269 free_local_heap (ctx );
268- ctx -> call_stack_ptr -- ;
270+ pop_stack_frame ( ctx ) ;
269271
270272 return rv ;
271273 }
@@ -330,7 +332,9 @@ int64_t basic_eval_int_fn(const char* fn_name, struct basic_ctx* ctx)
330332 struct ub_proc_fn_def * def = basic_find_fn (fn_name + 2 , ctx );
331333 int64_t rv = 0 ;
332334 if (def ) {
333- ctx -> call_stack_ptr ++ ;
335+ if (!new_stack_frame (ctx )) {
336+ return 0 ;
337+ }
334338 init_local_heap (ctx );
335339
336340 int bracket_depth = 0 ;
@@ -370,7 +374,7 @@ int64_t basic_eval_int_fn(const char* fn_name, struct basic_ctx* ctx)
370374 buddy_free (ctx -> allocator , atomic );
371375
372376 free_local_heap (ctx );
373- ctx -> call_stack_ptr -- ;
377+ pop_stack_frame ( ctx ) ;
374378
375379 return rv ;
376380 }
@@ -382,7 +386,10 @@ void basic_eval_double_fn(const char* fn_name, struct basic_ctx* ctx, double* re
382386{
383387 struct ub_proc_fn_def * def = basic_find_fn (fn_name + 2 , ctx );
384388 if (def ) {
385- ctx -> call_stack_ptr ++ ;
389+ if (!new_stack_frame (ctx )) {
390+ * res = 0 ;
391+ return ;
392+ }
386393 init_local_heap (ctx );
387394
388395 int bracket_depth = 0 ;
@@ -427,7 +434,7 @@ void basic_eval_double_fn(const char* fn_name, struct basic_ctx* ctx, double* re
427434 buddy_free (ctx -> allocator , atomic );
428435
429436 free_local_heap (ctx );
430- ctx -> call_stack_ptr -- ;
437+ pop_stack_frame ( ctx ) ;
431438
432439 return ;
433440 }
@@ -612,19 +619,23 @@ void proc_statement(struct basic_ctx* ctx)
612619 struct ub_proc_fn_def * def = basic_find_fn (procname , ctx );
613620 if (def ) {
614621 if (* ctx -> ptr == '(' && * (ctx -> ptr + 1 ) != ')' ) {
615- ctx -> call_stack_ptr ++ ;
622+ if (!new_stack_frame (ctx )) {
623+ return ;
624+ }
616625 init_local_heap (ctx );
617626
618627 int bracket_depth = 0 ;
619628 const char * item_begin = ctx -> ptr ;
620629 struct ub_param * param = def -> params ;
621630 while (extract_comma_list (def , ctx , & bracket_depth , & item_begin , & param ));
622631
623- ctx -> call_stack_ptr -- ;
632+ pop_stack_frame ( ctx ) ;
624633 } else {
625- ctx -> call_stack_ptr ++ ;
634+ if (!new_stack_frame (ctx )) {
635+ return ;
636+ }
626637 init_local_heap (ctx );
627- ctx -> call_stack_ptr -- ;
638+ pop_stack_frame ( ctx ) ;
628639 }
629640
630641 ctx -> fn_type_stack [ctx -> call_stack_ptr ] = ctx -> fn_type ; // save caller’s type
@@ -638,7 +649,9 @@ void proc_statement(struct basic_ctx* ctx)
638649 if (ctx -> call_stack_ptr < MAX_CALL_STACK_DEPTH ) {
639650 ctx -> call_stack [ctx -> call_stack_ptr ] = tokenizer_num (ctx , NUMBER );
640651 basic_debug ("PROC from %lu returning line %lu, PROC %s on line %lu\n" , ctx -> current_linenum , ctx -> call_stack [ctx -> call_stack_ptr ], procname , def -> line );
641- ctx -> call_stack_ptr ++ ;
652+ if (!new_stack_frame (ctx )) {
653+ return ;
654+ }
642655 jump_linenum (def -> line , ctx );
643656 } else {
644657 tokenizer_error_print (ctx , "PROC: stack exhausted" );
@@ -699,7 +712,7 @@ void endproc_statement(struct basic_ctx* ctx)
699712
700713 if (ctx -> call_stack_ptr > 0 ) {
701714 free_local_heap (ctx );
702- ctx -> call_stack_ptr -- ;
715+ pop_stack_frame ( ctx ) ;
703716
704717 /* Now restore the *caller*'s return type. */
705718 ctx -> fn_type = ctx -> fn_type_stack [ctx -> call_stack_ptr ];
0 commit comments