summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2007-04-21 12:46:49 +0000
committerKristján Valur Jónsson <kristjan@ccpgames.com>2007-04-21 12:46:49 +0000
commit5e4e31f76a18e45d88a24ce7b6efc07e420d805b (patch)
tree211ba4a724778fd6fa44d8e092ad6c34bb37de5f /Modules
parent8ff1f6a69e967951fb4de3049fbb847aacc901c8 (diff)
downloadcpython-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')
-rw-r--r--Modules/_ctypes/callproc.c5
-rw-r--r--Modules/binascii.c6
-rw-r--r--Modules/cPickle.c19
-rw-r--r--Modules/cStringIO.c16
-rw-r--r--Modules/posixmodule.c7
5 files changed, 35 insertions, 18 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index e0765e917c..738ed2f79d 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -64,6 +64,7 @@
#ifdef MS_WIN32
#include <windows.h>
+#include <tchar.h>
#else
#include "ctypes_dlfcn.h"
#endif
@@ -97,9 +98,9 @@ static TCHAR *FormatError(DWORD code)
0,
NULL);
if (n) {
- while (isspace(lpMsgBuf[n-1]))
+ while (_istspace(lpMsgBuf[n-1]))
--n;
- lpMsgBuf[n] = '\0'; /* rstrip() */
+ lpMsgBuf[n] = _T('\0'); /* rstrip() */
}
return lpMsgBuf;
}
diff --git a/Modules/binascii.c b/Modules/binascii.c
index 4dee45198e..5e0f86dc13 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -1165,7 +1165,8 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
((data[in] < 33) &&
(data[in] != '\r') && (data[in] != '\n') &&
- (quotetabs && ((data[in] != '\t') || (data[in] != ' ')))))
+ (!quotetabs ||
+ (quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
{
if ((linelen + 3) >= MAXLINESIZE) {
linelen = 0;
@@ -1235,7 +1236,8 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
((data[in] < 33) &&
(data[in] != '\r') && (data[in] != '\n') &&
- (quotetabs && ((data[in] != '\t') || (data[in] != ' ')))))
+ (!quotetabs ||
+ (quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
{
if ((linelen + 3 )>= MAXLINESIZE) {
odata[out++] = '=';
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 4f7d1f198a..dd9887b525 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -533,11 +533,12 @@ read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
self->buf_size = size;
}
else if (n > self->buf_size) {
- self->buf = (char *)realloc(self->buf, n);
- if (!self->buf) {
+ char *newbuf = (char *)realloc(self->buf, n);
+ if (!newbuf) {
PyErr_NoMemory();
return -1;
}
+ self->buf = newbuf;
self->buf_size = n;
}
@@ -576,6 +577,7 @@ readline_file(Unpicklerobject *self, char **s)
i = 0;
while (1) {
int bigger;
+ char *newbuf;
for (; i < (self->buf_size - 1); i++) {
if (feof(self->fp) ||
(self->buf[i] = getc(self->fp)) == '\n') {
@@ -589,11 +591,12 @@ readline_file(Unpicklerobject *self, char **s)
PyErr_NoMemory();
return -1;
}
- self->buf = (char *)realloc(self->buf, bigger);
- if (!self->buf) {
+ newbuf = (char *)realloc(self->buf, bigger);
+ if (!newbuf) {
PyErr_NoMemory();
return -1;
}
+ self->buf = newbuf;
self->buf_size = bigger;
}
}
@@ -4365,17 +4368,19 @@ load_mark(Unpicklerobject *self)
*/
if ((self->num_marks + 1) >= self->marks_size) {
+ int *marks;
s=self->marks_size+20;
if (s <= self->num_marks) s=self->num_marks + 1;
if (self->marks == NULL)
- self->marks=(int *)malloc(s * sizeof(int));
+ marks=(int *)malloc(s * sizeof(int));
else
- self->marks=(int *)realloc(self->marks,
+ marks=(int *)realloc(self->marks,
s * sizeof(int));
- if (! self->marks) {
+ if (!marks) {
PyErr_NoMemory();
return -1;
}
+ self->marks = marks;
self->marks_size = s;
}
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);
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 958fb63d31..158b12e2ee 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4788,18 +4788,19 @@ _PyPopenCreateProcess(char *cmdstring,
(sizeof(modulepath)/sizeof(modulepath[0]))
-strlen(modulepath));
if (stat(modulepath, &statinfo) != 0) {
+ size_t mplen = sizeof(modulepath)/sizeof(modulepath[0]);
/* Eeek - file-not-found - possibly an embedding
situation - see if we can locate it in sys.prefix
*/
strncpy(modulepath,
Py_GetExecPrefix(),
- sizeof(modulepath)/sizeof(modulepath[0]));
+ mplen);
+ modulepath[mplen-1] = '\0';
if (modulepath[strlen(modulepath)-1] != '\\')
strcat(modulepath, "\\");
strncat(modulepath,
szConsoleSpawn,
- (sizeof(modulepath)/sizeof(modulepath[0]))
- -strlen(modulepath));
+ mplen-strlen(modulepath));
/* No where else to look - raise an easily identifiable
error, rather than leaving Windows to report
"file not found" - as the user is probably blissfully