Skip to content

Commit 5e4e31f

Browse files
author
Kristján Valur Jónsson
committed
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.
1 parent 8ff1f6a commit 5e4e31f

8 files changed

Lines changed: 39 additions & 30 deletions

File tree

‎Modules/_ctypes/callproc.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
#ifdef MS_WIN32
6666
#include <windows.h>
67+
#include <tchar.h>
6768
#else
6869
#include "ctypes_dlfcn.h"
6970
#endif
@@ -97,9 +98,9 @@ static TCHAR *FormatError(DWORD code)
9798
0,
9899
NULL);
99100
if (n) {
100-
while (isspace(lpMsgBuf[n-1]))
101+
while (_istspace(lpMsgBuf[n-1]))
101102
--n;
102-
lpMsgBuf[n] = '\0'; /* rstrip() */
103+
lpMsgBuf[n] = _T('\0'); /* rstrip() */
103104
}
104105
return lpMsgBuf;
105106
}

‎Modules/binascii.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,8 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
11651165
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
11661166
((data[in] < 33) &&
11671167
(data[in] != '\r') && (data[in] != '\n') &&
1168-
(quotetabs && ((data[in] != '\t') || (data[in] != ' ')))))
1168+
(!quotetabs ||
1169+
(quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
11691170
{
11701171
if ((linelen + 3) >= MAXLINESIZE) {
11711172
linelen = 0;
@@ -1235,7 +1236,8 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs)
12351236
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
12361237
((data[in] < 33) &&
12371238
(data[in] != '\r') && (data[in] != '\n') &&
1238-
(quotetabs && ((data[in] != '\t') || (data[in] != ' ')))))
1239+
(!quotetabs ||
1240+
(quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
12391241
{
12401242
if ((linelen + 3 )>= MAXLINESIZE) {
12411243
odata[out++] = '=';

‎Modules/cPickle.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,12 @@ read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
533533
self->buf_size = size;
534534
}
535535
else if (n > self->buf_size) {
536-
self->buf = (char *)realloc(self->buf, n);
537-
if (!self->buf) {
536+
char *newbuf = (char *)realloc(self->buf, n);
537+
if (!newbuf) {
538538
PyErr_NoMemory();
539539
return -1;
540540
}
541+
self->buf = newbuf;
541542
self->buf_size = n;
542543
}
543544

@@ -576,6 +577,7 @@ readline_file(Unpicklerobject *self, char **s)
576577
i = 0;
577578
while (1) {
578579
int bigger;
580+
char *newbuf;
579581
for (; i < (self->buf_size - 1); i++) {
580582
if (feof(self->fp) ||
581583
(self->buf[i] = getc(self->fp)) == '\n') {
@@ -589,11 +591,12 @@ readline_file(Unpicklerobject *self, char **s)
589591
PyErr_NoMemory();
590592
return -1;
591593
}
592-
self->buf = (char *)realloc(self->buf, bigger);
593-
if (!self->buf) {
594+
newbuf = (char *)realloc(self->buf, bigger);
595+
if (!newbuf) {
594596
PyErr_NoMemory();
595597
return -1;
596598
}
599+
self->buf = newbuf;
597600
self->buf_size = bigger;
598601
}
599602
}
@@ -4365,17 +4368,19 @@ load_mark(Unpicklerobject *self)
43654368
*/
43664369

43674370
if ((self->num_marks + 1) >= self->marks_size) {
4371+
int *marks;
43684372
s=self->marks_size+20;
43694373
if (s <= self->num_marks) s=self->num_marks + 1;
43704374
if (self->marks == NULL)
4371-
self->marks=(int *)malloc(s * sizeof(int));
4375+
marks=(int *)malloc(s * sizeof(int));
43724376
else
4373-
self->marks=(int *)realloc(self->marks,
4377+
marks=(int *)realloc(self->marks,
43744378
s * sizeof(int));
4375-
if (! self->marks) {
4379+
if (!marks) {
43764380
PyErr_NoMemory();
43774381
return -1;
43784382
}
4383+
self->marks = marks;
43794384
self->marks_size = s;
43804385
}
43814386

‎Modules/cStringIO.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,17 @@ O_seek(Oobject *self, PyObject *args) {
339339
}
340340

341341
if (position > self->buf_size) {
342+
char *newbuf;
342343
self->buf_size*=2;
343344
if (self->buf_size <= position) self->buf_size=position+1;
344-
self->buf = (char*) realloc(self->buf,self->buf_size);
345-
if (!self->buf) {
345+
newbuf = (char*) realloc(self->buf,self->buf_size);
346+
if (!newbuf) {
347+
free(self->buf);
348+
self->buf = 0;
346349
self->buf_size=self->pos=0;
347350
return PyErr_NoMemory();
348351
}
352+
self->buf = newbuf;
349353
}
350354
else if (position < 0) position=0;
351355

@@ -366,6 +370,7 @@ static int
366370
O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
367371
Py_ssize_t newl;
368372
Oobject *oself;
373+
char *newbuf;
369374

370375
if (!IO__opencheck(IOOOBJECT(self))) return -1;
371376
oself = (Oobject *)self;
@@ -377,12 +382,15 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
377382
assert(newl + 1 < INT_MAX);
378383
oself->buf_size = (int)(newl+1);
379384
}
380-
oself->buf = (char*)realloc(oself->buf, oself->buf_size);
381-
if (!oself->buf) {
385+
newbuf = (char*)realloc(oself->buf, oself->buf_size);
386+
if (!newbuf) {
382387
PyErr_SetString(PyExc_MemoryError,"out of memory");
388+
free(oself->buf);
389+
oself->buf = 0;
383390
oself->buf_size = oself->pos = 0;
384391
return -1;
385392
}
393+
oself->buf = newbuf;
386394
}
387395

388396
memcpy(oself->buf+oself->pos,c,l);

‎Modules/posixmodule.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,18 +4788,19 @@ _PyPopenCreateProcess(char *cmdstring,
47884788
(sizeof(modulepath)/sizeof(modulepath[0]))
47894789
-strlen(modulepath));
47904790
if (stat(modulepath, &statinfo) != 0) {
4791+
size_t mplen = sizeof(modulepath)/sizeof(modulepath[0]);
47914792
/* Eeek - file-not-found - possibly an embedding
47924793
situation - see if we can locate it in sys.prefix
47934794
*/
47944795
strncpy(modulepath,
47954796
Py_GetExecPrefix(),
4796-
sizeof(modulepath)/sizeof(modulepath[0]));
4797+
mplen);
4798+
modulepath[mplen-1] = '\0';
47974799
if (modulepath[strlen(modulepath)-1] != '\\')
47984800
strcat(modulepath, "\\");
47994801
strncat(modulepath,
48004802
szConsoleSpawn,
4801-
(sizeof(modulepath)/sizeof(modulepath[0]))
4802-
-strlen(modulepath));
4803+
mplen-strlen(modulepath));
48034804
/* No where else to look - raise an easily identifiable
48044805
error, rather than leaving Windows to report
48054806
"file not found" - as the user is probably blissfully

‎PC/_winreg.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
699699
case REG_DWORD:
700700
if (value != Py_None && !PyInt_Check(value))
701701
return FALSE;
702-
*retDataBuf = (BYTE *)PyMem_NEW(DWORD, sizeof(DWORD));
702+
*retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
703703
if (*retDataBuf==NULL){
704704
PyErr_NoMemory();
705705
return FALSE;

‎Python/dynload_win.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,8 @@
1313
const struct filedescr _PyImport_DynLoadFiletab[] = {
1414
#ifdef _DEBUG
1515
{"_d.pyd", "rb", C_EXTENSION},
16-
/* Temporarily disable .dll, to avoid conflicts between sqlite3.dll
17-
and the sqlite3 package. If this needs to be reverted for 2.5,
18-
some other solution for the naming conflict must be found.
19-
{"_d.dll", "rb", C_EXTENSION},
20-
*/
2116
#else
2217
{".pyd", "rb", C_EXTENSION},
23-
/* Likewise
24-
{".dll", "rb", C_EXTENSION},
25-
*/
2618
#endif
2719
{0, 0}
2820
};

‎Python/thread_nt.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
202202
* too many threads".
203203
*/
204204
dprintf(("%ld: PyThread_start_new_thread failed: %p errno %d\n",
205-
PyThread_get_thread_ident(), rv, errno));
205+
PyThread_get_thread_ident(), (void*)rv, errno));
206206
obj.id = -1;
207207
}
208208
else {
209209
dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n",
210-
PyThread_get_thread_ident(), rv));
210+
PyThread_get_thread_ident(), (void*)rv));
211211
/* wait for thread to initialize, so we can get its id */
212212
WaitForSingleObject(obj.done, INFINITE);
213213
assert(obj.id != -1);
@@ -333,7 +333,7 @@ PyThread_release_lock(PyThread_type_lock aLock)
333333
dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
334334

335335
if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock)))
336-
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError()));
336+
dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError()));
337337
}
338338

339339
/* minimum/maximum thread stack sizes supported */

0 commit comments

Comments
 (0)