[lldb] Assert index is valid in DWARFDeclContext
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 28 Jun 2023 00:01:53 +0000 (17:01 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 28 Jun 2023 01:23:35 +0000 (18:23 -0700)
Replace the comment with an assert to enforce the correct index is used.

Differential revision: https://reviews.llvm.org/D153921

lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h

index fa776f2..13e3dfb 100644 (file)
@@ -9,11 +9,13 @@
 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
 
-#include <string>
-#include <vector>
 #include "lldb/Utility/ConstString.h"
 #include "DWARFDefines.h"
 
+#include <cassert>
+#include <string>
+#include <vector>
+
 // DWARFDeclContext
 //
 // A class that represents a declaration context all the way down to a
@@ -53,12 +55,12 @@ public:
   uint32_t GetSize() const { return m_entries.size(); }
 
   Entry &operator[](uint32_t idx) {
-    // "idx" must be valid
+    assert(idx < m_entries.size() && "invalid index");
     return m_entries[idx];
   }
 
   const Entry &operator[](uint32_t idx) const {
-    // "idx" must be valid
+    assert(idx < m_entries.size() && "invalid index");
     return m_entries[idx];
   }