diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2007-04-21 12:46:49 +0000 |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2007-04-21 12:46:49 +0000 |
commit | 5e4e31f76a18e45d88a24ce7b6efc07e420d805b (patch) | |
tree | 211ba4a724778fd6fa44d8e092ad6c34bb37de5f /Modules/cStringIO.c | |
parent | 8ff1f6a69e967951fb4de3049fbb847aacc901c8 (diff) | |
download | cpython-git-5e4e31f76a18e45d88a24ce7b6efc07e420d805b.tar.gz |
Fix various minor issues discovered with static analysis using Visual Studio 2005 Team System.
Removed obsolete comment, since .dll modules are no longer supported on windows, only .pyd.
Diffstat (limited to 'Modules/cStringIO.c')
-rw-r--r-- | Modules/cStringIO.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 100891ba4a..06bc6cbae3 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -339,13 +339,17 @@ O_seek(Oobject *self, PyObject *args) { } if (position > self->buf_size) { + char *newbuf; self->buf_size*=2; if (self->buf_size <= position) self->buf_size=position+1; - self->buf = (char*) realloc(self->buf,self->buf_size); - if (!self->buf) { + newbuf = (char*) realloc(self->buf,self->buf_size); + if (!newbuf) { + free(self->buf); + self->buf = 0; self->buf_size=self->pos=0; return PyErr_NoMemory(); } + self->buf = newbuf; } else if (position < 0) position=0; @@ -366,6 +370,7 @@ static int O_cwrite(PyObject *self, const char *c, Py_ssize_t l) { Py_ssize_t newl; Oobject *oself; + char *newbuf; if (!IO__opencheck(IOOOBJECT(self))) return -1; oself = (Oobject *)self; @@ -377,12 +382,15 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) { assert(newl + 1 < INT_MAX); oself->buf_size = (int)(newl+1); } - oself->buf = (char*)realloc(oself->buf, oself->buf_size); - if (!oself->buf) { + newbuf = (char*)realloc(oself->buf, oself->buf_size); + if (!newbuf) { PyErr_SetString(PyExc_MemoryError,"out of memory"); + free(oself->buf); + oself->buf = 0; oself->buf_size = oself->pos = 0; return -1; } + oself->buf = newbuf; } memcpy(oself->buf+oself->pos,c,l); |