[Python-checkins] r54945 - in python/trunk: Modules/_ctypes/callproc.c Modules/cPickle.c Modules/cStringIO.c Modules/posixmodule.c PC/_winreg.c Python/thread_nt.h

kristjan.jonsson python-checkins at python.org
Wed Apr 25 02:11:02 CEST 2007


Author: kristjan.jonsson
Date: Wed Apr 25 02:10:50 2007
New Revision: 54945

Modified:
   python/trunk/Modules/_ctypes/callproc.c
   python/trunk/Modules/cPickle.c
   python/trunk/Modules/cStringIO.c
   python/trunk/Modules/posixmodule.c
   python/trunk/PC/_winreg.c
   python/trunk/Python/thread_nt.h
Log:
Merge change 54909 from release25-maint:  Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition

Modified: python/trunk/Modules/_ctypes/callproc.c
==============================================================================
--- python/trunk/Modules/_ctypes/callproc.c	(original)
+++ python/trunk/Modules/_ctypes/callproc.c	Wed Apr 25 02:10:50 2007
@@ -64,6 +64,7 @@
 
 #ifdef MS_WIN32
 #include <windows.h>
+#include <tchar.h>
 #else
 #include "ctypes_dlfcn.h"
 #endif
@@ -97,9 +98,9 @@
 			  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;
 }

Modified: python/trunk/Modules/cPickle.c
==============================================================================
--- python/trunk/Modules/cPickle.c	(original)
+++ python/trunk/Modules/cPickle.c	Wed Apr 25 02:10:50 2007
@@ -533,11 +533,12 @@
 		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 @@
 	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 @@
 			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 @@
 	*/
 
 	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;
 	}
 

Modified: python/trunk/Modules/cStringIO.c
==============================================================================
--- python/trunk/Modules/cStringIO.c	(original)
+++ python/trunk/Modules/cStringIO.c	Wed Apr 25 02:10:50 2007
@@ -349,13 +349,17 @@
         }
 
         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;
 
@@ -376,6 +380,7 @@
 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;
@@ -387,12 +392,15 @@
 		    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);

Modified: python/trunk/Modules/posixmodule.c
==============================================================================
--- python/trunk/Modules/posixmodule.c	(original)
+++ python/trunk/Modules/posixmodule.c	Wed Apr 25 02:10:50 2007
@@ -4841,18 +4841,19 @@
 			        (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

Modified: python/trunk/PC/_winreg.c
==============================================================================
--- python/trunk/PC/_winreg.c	(original)
+++ python/trunk/PC/_winreg.c	Wed Apr 25 02:10:50 2007
@@ -699,7 +699,7 @@
 		case REG_DWORD:
 			if (value != Py_None && !PyInt_Check(value))
 				return FALSE;
-			*retDataBuf = (BYTE *)PyMem_NEW(DWORD, sizeof(DWORD));
+			*retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
 			if (*retDataBuf==NULL){
 				PyErr_NoMemory();
 				return FALSE;

Modified: python/trunk/Python/thread_nt.h
==============================================================================
--- python/trunk/Python/thread_nt.h	(original)
+++ python/trunk/Python/thread_nt.h	Wed Apr 25 02:10:50 2007
@@ -202,12 +202,12 @@
 		 * too many threads".
 		 */
 		dprintf(("%ld: PyThread_start_new_thread failed: %p errno %d\n",
-		         PyThread_get_thread_ident(), rv, errno));
+		         PyThread_get_thread_ident(), (void*)rv, errno));
 		obj.id = -1;
 	}
 	else {
 		dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n",
-		         PyThread_get_thread_ident(), rv));
+		         PyThread_get_thread_ident(), (void*)rv));
 		/* wait for thread to initialize, so we can get its id */
 		WaitForSingleObject(obj.done, INFINITE);
 		assert(obj.id != -1);
@@ -333,7 +333,7 @@
 	dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
 
 	if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock)))
-		dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError()));
+		dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError()));
 }
 
 /* minimum/maximum thread stack sizes supported */


More information about the Python-checkins mailing list