aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/search.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-17 20:18:18 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-17 20:18:18 +0100
commit14ebd5d58be3fcb5d2208f890498dd8c57f4d165 (patch)
tree6651efb91ac88095049dbabf0b150ceecf7b1f0d /src/search.cpp
parent910a5913bf94793eee603f2ab397b52142b99295 (diff)
downloadsciteco-14ebd5d58be3fcb5d2208f890498dd8c57f4d165.tar.gz
fixed invalid memory accesses in the expression stack and reworked expression stack
this was probably a regression from d94b18819ad4ee3237c46ad43a962d0121f0c3fe and should not be in v0.5. The return value of Expressions::find_op() must always be checked since it might not find the operator, returning 0 (it used to be 0). A zero index pointed to uninitialized memory - in the worst case it pointed to invalid memory resulting in segfaults. Too large indices were also not handled. This was probably responsible for recent PPA build issues. Valgrind/memcheck reports this error but I misread it as a bogus warning. I took the opportunity to clean up the ValueStack implementation and made it more robust by adding a few assertions. ValueStacks now grow from large to small addresses (like stack data structures usually do). This means, there is no need to work with negative indices into the stack pointer. To reduce the potential for invalid stack accesses, stack indices are now unsigned and have origin 0. Previously, all indices < 1 were faulty but weren't checked. Also, I added some minor optimizations.
Diffstat (limited to 'src/search.cpp')
-rw-r--r--src/search.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/search.cpp b/src/search.cpp
index 370dbfc..8013385 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -527,7 +527,7 @@ StateSearch::done(const gchar *str)
if (eval_colon())
expressions.push(search_reg->get_integer());
else if (IS_FAILURE(search_reg->get_integer()) &&
- !expressions.find_op(Expressions::OP_LOOP) /* not in loop */)
+ expressions.find_op(Expressions::OP_LOOP) < 0 /* not in loop */)
interface.msg(InterfaceCurrent::MSG_ERROR, "Search string not found!");
return &States::start;