Jelajahi Sumber

fix(core): resolve dangling reference in buffer loading

Fixed a dangling reference error in BufferManager::load_file where a reference was bound to a temporary optional returned by buf->file_path(). Now properly storing the optional before access.
Bernardo Magri 1 bulan lalu
induk
melakukan
62709d8621
1 mengubah file dengan 3 tambahan dan 2 penghapusan
  1. 3 2
      src/buffer_manager.cpp

+ 3 - 2
src/buffer_manager.cpp

@@ -50,8 +50,9 @@ bool BufferManager::load_file(const std::filesystem::path& path) {
 
     // Check if already open
     for (const auto& buf : buffers_) {
-        if (!buf->file_path()) continue;
-        const auto& buf_path = *buf->file_path();
+        auto path_opt = buf->file_path();
+        if (!path_opt) continue;
+        const auto& buf_path = *path_opt;
         
         bool is_same = false;
         // Only use equivalent if BOTH exist on disk to avoid exceptions/errors