[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[./src/input.cc:1268]: (error) Dangerous iterator usage.
From: |
John W. Eaton |
Subject: |
[./src/input.cc:1268]: (error) Dangerous iterator usage. |
Date: |
Thu, 27 Jan 2011 04:00:58 -0500 |
On 27-Jan-2011, CdeMills wrote:
|
| Consider the enclosed program. It reads data from a map and increase the
| iterator by one position. If the data just read is just before the last, the
| last is destroyed. Yet upon next read, the data returned is the one just
| destroyed!
|
| It seems that mixing map.erase() and iterators is unsafe. OTOH, I don't
| understand the logic around line 1268:
| if (is_valid_function (hook_fcn)) result is false, then we erase the next
| element ???
Right, I don't think the intent was to remove the next element. It
looks like a bug to me.
How about the following change?
jwe
# HG changeset patch
# User John W. Eaton <address@hidden>
# Date 1296118693 18000
# Node ID f747f66bda2f7dbb30dc41270cc5dc9d639b2381
# Parent 3592c57fa6a85a09adb16b6b14e341b908c2ab91
input.cc (input_event_hook): fix incorrect use of iterator
diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2011-01-27 John W. Eaton <address@hidden>
+
+ * input.cc (input_event_hook): Fix incorrect use of iterator.
+ Reported by Pascal Dupuis <address@hidden>.
+
2011-01-26 John W. Eaton <address@hidden>
* lex.ll, graphics.cc, gl-render.cc, ov-mex-fcn.h, graphics.h.in:
diff --git a/src/input.cc b/src/input.cc
--- a/src/input.cc
+++ b/src/input.cc
@@ -1255,7 +1255,7 @@
std::string hook_fcn = p->first;
octave_value user_data = p->second;
- p++;
+ hook_fcn_map_type::iterator q = p++;
if (is_valid_function (hook_fcn))
{
@@ -1265,7 +1265,7 @@
feval (hook_fcn, octave_value_list (), 0);
}
else
- hook_fcn_map.erase (p);
+ hook_fcn_map.erase (q);
}
if (hook_fcn_map.empty ())