summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-12-08 01:16:31 (GMT)
committerGuido van Rossum <guido@python.org>1995-12-08 01:16:31 (GMT)
commit992ded8f12bbf8fdbb2bdc59f85b44657bd74629 (patch)
tree061abb1796b764a0bc338b41f84bac13c7c3aaa9 /Objects
parente5fe4af070bb5251304f30f1381f521de3c655bf (diff)
downloadcpython-992ded8f12bbf8fdbb2bdc59f85b44657bd74629.zip
cpython-992ded8f12bbf8fdbb2bdc59f85b44657bd74629.tar.gz
cpython-992ded8f12bbf8fdbb2bdc59f85b44657bd74629.tar.bz2
fix free memory reads in dictlookup et al
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c17
-rw-r--r--Objects/mappingobject.c17
2 files changed, 14 insertions, 20 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 11d344a..42e68d8 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -761,7 +761,7 @@ typeobject Mappingtype = {
/* For backward compatibility with old dictionary interface */
static object *last_name_object;
-static char *last_name_char;
+static char *last_name_char; /* NULL or == getstringvalue(last_name_object) */
object *
getattro(v, name)
@@ -797,15 +797,14 @@ dictlookup(v, key)
object *v;
char *key;
{
- if (key != last_name_char ||
- strcmp(key, getstringvalue(last_name_object)) != 0) {
+ if (key != last_name_char) {
XDECREF(last_name_object);
last_name_object = newstringobject(key);
if (last_name_object == NULL) {
last_name_char = NULL;
return NULL;
}
- last_name_char = key;
+ last_name_char = getstringvalue(last_name_object);
}
return mappinglookup(v, last_name_object);
}
@@ -816,15 +815,14 @@ dictinsert(v, key, item)
char *key;
object *item;
{
- if (key != last_name_char ||
- strcmp(key, getstringvalue(last_name_object)) != 0) {
+ if (key != last_name_char) {
XDECREF(last_name_object);
last_name_object = newstringobject(key);
if (last_name_object == NULL) {
last_name_char = NULL;
return -1;
}
- last_name_char = key;
+ last_name_char = getstringvalue(last_name_object);
}
return mappinginsert(v, last_name_object, item);
}
@@ -834,15 +832,14 @@ dictremove(v, key)
object *v;
char *key;
{
- if (key != last_name_char ||
- strcmp(key, getstringvalue(last_name_object)) != 0) {
+ if (key != last_name_char) {
XDECREF(last_name_object);
last_name_object = newstringobject(key);
if (last_name_object == NULL) {
last_name_char = NULL;
return -1;
}
- last_name_char = key;
+ last_name_char = getstringvalue(last_name_object);
}
return mappingremove(v, last_name_object);
}
diff --git a/Objects/mappingobject.c b/Objects/mappingobject.c
index 11d344a..42e68d8 100644
--- a/Objects/mappingobject.c
+++ b/Objects/mappingobject.c
@@ -761,7 +761,7 @@ typeobject Mappingtype = {
/* For backward compatibility with old dictionary interface */
static object *last_name_object;
-static char *last_name_char;
+static char *last_name_char; /* NULL or == getstringvalue(last_name_object) */
object *
getattro(v, name)
@@ -797,15 +797,14 @@ dictlookup(v, key)
object *v;
char *key;
{
- if (key != last_name_char ||
- strcmp(key, getstringvalue(last_name_object)) != 0) {
+ if (key != last_name_char) {
XDECREF(last_name_object);
last_name_object = newstringobject(key);
if (last_name_object == NULL) {
last_name_char = NULL;
return NULL;
}
- last_name_char = key;
+ last_name_char = getstringvalue(last_name_object);
}
return mappinglookup(v, last_name_object);
}
@@ -816,15 +815,14 @@ dictinsert(v, key, item)
char *key;
object *item;
{
- if (key != last_name_char ||
- strcmp(key, getstringvalue(last_name_object)) != 0) {
+ if (key != last_name_char) {
XDECREF(last_name_object);
last_name_object = newstringobject(key);
if (last_name_object == NULL) {
last_name_char = NULL;
return -1;
}
- last_name_char = key;
+ last_name_char = getstringvalue(last_name_object);
}
return mappinginsert(v, last_name_object, item);
}
@@ -834,15 +832,14 @@ dictremove(v, key)
object *v;
char *key;
{
- if (key != last_name_char ||
- strcmp(key, getstringvalue(last_name_object)) != 0) {
+ if (key != last_name_char) {
XDECREF(last_name_object);
last_name_object = newstringobject(key);
if (last_name_object == NULL) {
last_name_char = NULL;
return -1;
}
- last_name_char = key;
+ last_name_char = getstringvalue(last_name_object);
}
return mappingremove(v, last_name_object);
}