From 7cc5ff7c73ef1c4d39cd962b281c86ae0ebdecfe Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 17 Aug 2012 18:52:04 +0200 Subject: [PATCH] fix create_buffer_from_file when file does not exists --- src/file.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/file.cc b/src/file.cc index fcba92c2..33c543a3 100644 --- a/src/file.cc +++ b/src/file.cc @@ -75,11 +75,6 @@ String read_file(const String& filename) Buffer* create_buffer_from_file(const String& filename) { - if (Buffer* buffer = BufferManager::instance().get_buffer(filename)) - delete buffer; - - Buffer* buffer = new Buffer(filename, Buffer::Type::File, ""); - int fd = open(filename.c_str(), O_RDONLY); if (fd == -1) { @@ -89,6 +84,12 @@ Buffer* create_buffer_from_file(const String& filename) throw file_access_error(filename, strerror(errno)); } + if (Buffer* buffer = BufferManager::instance().get_buffer(filename)) + delete buffer; + + Buffer* buffer = new Buffer(filename, Buffer::Type::File, ""); + + String content; char buf[256]; bool crlf = false;