Explorar o código

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 hai 1 mes
pai
achega
62709d8621
Modificáronse 1 ficheiros con 3 adicións e 2 borrados
  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