[Patches] clean up warnings in Win32 build of mmapmodule.c

Trent Mick trentm@activestate.com
Thu, 22 Jun 2000 19:36:34 -0700


Discussion:

Fix a few warnings in the Win32 build of mmapmodule.c. The warnings were
about comparison of singed (int) and unsigned (size_t) values. This was
patched by casting every int to size_t for comparison. This is safe because
every cast is preceded with a check guaranteeing that the int is positive.


Patch:


Index: Modules/mmapmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mmapmodule.c,v
retrieving revision 2.15
diff -c -r2.15 mmapmodule.c
*** Modules/mmapmodule.c	2000/06/18 19:06:49	2.15
--- Modules/mmapmodule.c	2000/06/23 02:33:34
***************
*** 568,574 ****
  	int i;
  {
  	CHECK_VALID(NULL);
! 	if (i < 0 || i >= self->size) {
  		PyErr_SetString(PyExc_IndexError, "mmap index out of range");
  		return NULL;
  	}
--- 568,574 ----
  	int i;
  {
  	CHECK_VALID(NULL);
! 	if (i < 0 || (size_t)i >= self->size) {
  		PyErr_SetString(PyExc_IndexError, "mmap index out of range");
  		return NULL;
  	}
***************
*** 583,595 ****
  	CHECK_VALID(NULL);
  	if (ilow < 0)
  		ilow = 0;
! 	else if (ilow > self->size)
  		ilow = self->size;
  	if (ihigh < 0)
  		ihigh = 0;
  	if (ihigh < ilow)
  		ihigh = ilow;
! 	else if (ihigh > self->size)
  		ihigh = self->size;
      
  	return PyString_FromStringAndSize(self->data + ilow, ihigh-ilow);
--- 583,595 ----
  	CHECK_VALID(NULL);
  	if (ilow < 0)
  		ilow = 0;
! 	else if ((size_t)ilow > self->size)
  		ilow = self->size;
  	if (ihigh < 0)
  		ihigh = 0;
  	if (ihigh < ilow)
  		ihigh = ilow;
! 	else if ((size_t)ihigh > self->size)
  		ihigh = self->size;
      
  	return PyString_FromStringAndSize(self->data + ilow, ihigh-ilow);
***************
*** 628,640 ****
  	CHECK_VALID(-1);
  	if (ilow < 0)
  		ilow = 0;
! 	else if (ilow > self->size)
  		ilow = self->size;
  	if (ihigh < 0)
  		ihigh = 0;
  	if (ihigh < ilow)
  		ihigh = ilow;
! 	else if (ihigh > self->size)
  		ihigh = self->size;
      
  	if (! (PyString_Check(v)) ) {
--- 628,640 ----
  	CHECK_VALID(-1);
  	if (ilow < 0)
  		ilow = 0;
! 	else if ((size_t)ilow > self->size)
  		ilow = self->size;
  	if (ihigh < 0)
  		ihigh = 0;
  	if (ihigh < ilow)
  		ihigh = ilow;
! 	else if ((size_t)ihigh > self->size)
  		ihigh = self->size;
      
  	if (! (PyString_Check(v)) ) {
***************
*** 661,667 ****
  	const char *buf;
   
  	CHECK_VALID(-1);
! 	if (i < 0 || i >= self->size) {
  		PyErr_SetString(PyExc_IndexError, "mmap index out of range");
  		return -1;
  	}
--- 661,667 ----
  	const char *buf;
   
  	CHECK_VALID(-1);
! 	if (i < 0 || (size_t)i >= self->size) {
  		PyErr_SetString(PyExc_IndexError, "mmap index out of range");
  		return -1;
  	}

Legal:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.




-- 
Trent Mick
trentm@activestate.com