From 61c5b631f3d0050984c938e63525fe8e22fabff2 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 10 Sep 2013 21:13:47 -0700 Subject: [PATCH] Fix for infinite loop in cycle_competions, and potential issue in fish_pager when given an empty completion list --- fish_pager.cpp | 5 +++++ reader.cpp | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fish_pager.cpp b/fish_pager.cpp index 848eb0fc0..9cde933e2 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -1370,6 +1370,11 @@ int main(int argc, char **argv) // debug( 3, L"prefix is '%ls'", prefix ); + if (comp.empty()) + { + exit_without_destructors(EXIT_FAILURE); + } + init(mangle_descriptors, result_fd); mangle_descriptions(comp); diff --git a/reader.cpp b/reader.cpp index c3630d73c..a1074627d 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1702,18 +1702,17 @@ static const completion_t *cycle_competions(const std::vector &com if (size == 0) return NULL; + // note start_idx will be set to -1 initially, so that when it gets incremented we start at 0 const size_t start_idx = *inout_idx; size_t idx = start_idx; + const completion_t *result = NULL; - for (;;) + size_t remaining = comp.size(); + while (remaining--) { /* Bump the index */ idx = (idx + 1) % size; - /* Bail if we've looped */ - if (idx == start_idx) - break; - /* Get the completion */ const completion_t &c = comp.at(idx);