[Python-checkins] CVS: python/dist/src/Modules shamodule.c,2.9,2.10

Barry Warsaw python-dev@python.org
Mon, 14 Aug 2000 23:03:38 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv31519

Modified Files:
	shamodule.c 
Log Message:
SHA_hexdigest(): A couple of small patches to this function, added
after a brief conversation with TP.  First, the return values of the
PyString_* function calls should be checked for errors.  Second,
bit-manipulations should be used instead of division for spliting the
byte up into its 4 bit digits.


Index: shamodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/shamodule.c,v
retrieving revision 2.9
retrieving revision 2.10
diff -C2 -r2.9 -r2.10
*** shamodule.c	2000/08/01 01:26:02	2.9
--- shamodule.c	2000/08/15 06:03:35	2.10
***************
*** 423,434 ****
      /* Create a new string */
      retval = PyString_FromStringAndSize(NULL, sizeof(digest) * 2);
      hex_digest = PyString_AsString(retval);
  
      /* Make hex version of the digest */
      for(i=j=0; i<sizeof(digest); i++) {
          char c;
!         c = digest[i] / 16; c = (c>9) ? c+'a'-10 : c + '0';
          hex_digest[j++] = c;
!         c = digest[i] % 16; c = (c>9) ? c+'a'-10 : c + '0';
          hex_digest[j++] = c;
      }
--- 423,442 ----
      /* Create a new string */
      retval = PyString_FromStringAndSize(NULL, sizeof(digest) * 2);
+     if (!retval)
+ 	    return NULL;
      hex_digest = PyString_AsString(retval);
+     if (!hex_digest) {
+ 	    Py_DECREF(retval);
+ 	    return NULL;
+     }
  
      /* Make hex version of the digest */
      for(i=j=0; i<sizeof(digest); i++) {
          char c;
!         c = (digest[i] >> 4) & 0xf;
! 	c = (c>9) ? c+'a'-10 : c + '0';
          hex_digest[j++] = c;
!         c = (digest[i] & 0xf);
! 	c = (c>9) ? c+'a'-10 : c + '0';
          hex_digest[j++] = c;
      }