From c98657a512ed3431d875620803c10bace2802a13 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 8 Mar 2012 20:49:10 +0000 Subject: [PATCH] fix some unitialized variable use (thanks valgrind) --- src/buffer.cc | 2 +- src/main.cc | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 175cffdd..d62d2e82 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -214,7 +214,7 @@ void Buffer::update_lines(const Modification& modification) std::vector new_lines; // if we inserted at the end of the buffer, we may have created a new // line without inserting a '\n' - if (endpos == m_content.size() and m_content[pos-1] == '\n') + if (endpos == m_content.size() and pos > 0 and m_content[pos-1] == '\n') new_lines.push_back(pos); // every \n inserted that was not the last buffer character created a diff --git a/src/main.cc b/src/main.cc index d9705d7c..0be62ce3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -516,7 +516,9 @@ void exec_commands_in_runtime_file(const CommandParameters& params, const std::string& filename = params[0]; char buffer[2048]; #if defined(__linux__) - readlink("/proc/self/exe", buffer, 2048 - filename.length()); + ssize_t res = readlink("/proc/self/exe", buffer, 2048 - filename.length()); + assert(res != -1); + buffer[res] = '\0'; #elif defined(__APPLE__) uint32_t bufsize = 2048 - filename.length(); _NSGetExecutablePath(buffer, &bufsize);