summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-10-14 16:21:24 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-10-14 16:21:24 (GMT)
commit992ec46acc1267729da141f683f2594f00ba9f57 (patch)
treee3a6ac322df5d1d565732dd4381845e535073312 /Objects
parentc1e98de7be2f6d1d34df36b37e45f97ed209c847 (diff)
downloadcpython-992ec46acc1267729da141f683f2594f00ba9f57.zip
cpython-992ec46acc1267729da141f683f2594f00ba9f57.tar.gz
cpython-992ec46acc1267729da141f683f2594f00ba9f57.tar.bz2
Issue #25406: Fixed a bug in C implementation of OrderedDict.move_to_end()
that caused segmentation fault or hang in iterating after moving several items to the start of ordered dict.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/odictobject.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 7df419e..8fe838a 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -618,37 +618,26 @@ _odict_find_node(PyODictObject *od, PyObject *key)
static void
_odict_add_head(PyODictObject *od, _ODictNode *node)
{
- if (_odict_FIRST(od) == NULL) {
- _odictnode_PREV(node) = NULL;
- _odictnode_NEXT(node) = NULL;
- _odict_FIRST(od) = node;
+ _odictnode_PREV(node) = NULL;
+ _odictnode_NEXT(node) = _odict_FIRST(od);
+ if (_odict_FIRST(od) == NULL)
_odict_LAST(od) = node;
- }
- else {
- _odictnode_PREV(node) = NULL;
- _odictnode_NEXT(node) = _odict_FIRST(od);
- _odict_FIRST(od) = node;
+ else
_odictnode_PREV(_odict_FIRST(od)) = node;
- }
+ _odict_FIRST(od) = node;
od->od_state++;
}
static void
_odict_add_tail(PyODictObject *od, _ODictNode *node)
{
- if (_odict_LAST(od) == NULL) {
- _odictnode_PREV(node) = NULL;
- _odictnode_NEXT(node) = NULL;
+ _odictnode_PREV(node) = _odict_LAST(od);
+ _odictnode_NEXT(node) = NULL;
+ if (_odict_LAST(od) == NULL)
_odict_FIRST(od) = node;
- _odict_LAST(od) = node;
- }
- else {
- _odictnode_PREV(node) = _odict_LAST(od);
- _odictnode_NEXT(node) = NULL;
+ else
_odictnode_NEXT(_odict_LAST(od)) = node;
- _odict_LAST(od) = node;
- }
-
+ _odict_LAST(od) = node;
od->od_state++;
}