From 3e77dd0c42dbc990e7d2e9b431846ff4ce9b4018 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Wed, 11 Dec 2013 19:51:57 -0800 Subject: [PATCH] fix(kernel/context): make context remove more robust Signed-off-by: Leonardo de Moura --- src/kernel/context.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kernel/context.cpp b/src/kernel/context.cpp index 13a2d2544..c8d7fe2f3 100644 --- a/src/kernel/context.cpp +++ b/src/kernel/context.cpp @@ -43,14 +43,18 @@ optional context::find(unsigned i) const { } static list remove_core(list const & l, unsigned s, unsigned n) { - if (s == 0) { - if (n > 0) { - return remove_core(tail(l), 0, n-1); + if (l) { + if (s == 0) { + if (n > 0) { + return remove_core(tail(l), 0, n-1); + } else { + return l; + } } else { - return l; + return cons(head(l), remove_core(tail(l), s-1, n)); } } else { - return cons(head(l), remove_core(tail(l), s-1, n)); + return l; } }