[Python-checkins] python/dist/src/Objects structseq.c,1.10,1.11

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Wed, 18 Dec 2002 15:20:41 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv11997/Objects

Modified Files:
	structseq.c 
Log Message:
SF # 654974, fix unchecked return values in structseq

Check return values after memory allocation.
Also use Py_True instead of PyInt_FromLong(1) for bool value.

Backport candidate.


Index: structseq.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/structseq.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** structseq.c	16 Oct 2002 19:10:03 -0000	1.10
--- structseq.c	18 Dec 2002 23:20:39 -0000	1.11
***************
*** 151,154 ****
--- 151,157 ----
  
  	res = (PyStructSequence*) PyStructSequence_New(type);
+ 	if (res == NULL) {
+ 		return NULL;
+ 	}
  	for (i = 0; i < len; ++i) {
  		PyObject *v = PySequence_Fast_GET_ITEM(arg, i);
***************
*** 361,364 ****
--- 364,369 ----
  
  	members = PyMem_NEW(PyMemberDef, n_members-n_unnamed_members+1);
+ 	if (members == NULL)
+ 		return;
  	
  	for (i = k = 0; i < n_members; ++i) {
***************
*** 388,392 ****
  	PyDict_SetItemString(dict, unnamed_fields_key, 
  		       PyInt_FromLong((long) n_unnamed_members));
! 	PyDict_SetItemString(dict, "__safe_for_unpickling__", 
! 		       PyInt_FromLong(1));
  }
--- 393,396 ----
  	PyDict_SetItemString(dict, unnamed_fields_key, 
  		       PyInt_FromLong((long) n_unnamed_members));
! 	PyDict_SetItemString(dict, "__safe_for_unpickling__", Py_True);
  }