From 4b3e9b356758e133028eea278d7cb4d06c0e4d11 Mon Sep 17 00:00:00 2001
From: Aryadev Chavali <aryadev@aryadevchavali.com>
Date: Tue, 16 Apr 2024 15:39:20 +0630
Subject: Clear vector after deleting all tokens

Ensures that iteration over vec_out by caller doesn't occur (such as
in a loop to free the memory).
---
 asm/preprocesser.cpp | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'asm')

diff --git a/asm/preprocesser.cpp b/asm/preprocesser.cpp
index d68992c..6ea6d45 100644
--- a/asm/preprocesser.cpp
+++ b/asm/preprocesser.cpp
@@ -37,6 +37,7 @@ pp_err_t preprocess_use_blocks(const vector<token_t *> &tokens,
           tokens[i + 1]->type != token_type_t::LITERAL_STRING)
       {
         VCLEAR(vec_out);
+        vec_out.clear();
         return pp_err_t(pp_err_type_t::EXPECTED_STRING, t);
       }
 
@@ -45,6 +46,7 @@ pp_err_t preprocess_use_blocks(const vector<token_t *> &tokens,
       if (!source)
       {
         VCLEAR(vec_out);
+        vec_out.clear();
         return pp_err_t(pp_err_type_t::FILE_NONEXISTENT, name);
       }
 
@@ -53,6 +55,7 @@ pp_err_t preprocess_use_blocks(const vector<token_t *> &tokens,
       if (lerr.type != lerr_type_t::OK)
       {
         VCLEAR(vec_out);
+        vec_out.clear();
         return pp_err_t(pp_err_type_t::FILE_PARSE_ERROR, name, lerr);
       }
 
@@ -120,6 +123,7 @@ pp_err_t preprocess_const_blocks(const vector<token_t *> &tokens,
         if (it == blocks.end())
         {
           VCLEAR(vec_out);
+          vec_out.clear();
           return pp_err_t(pp_err_type_t::UNKNOWN_NAME, token);
         }
 
-- 
cgit v1.2.3-13-gbd6f