[Patches] Patches for bug report 258 - mmapmodule.c compile problem

Greg Stein gstein@lyra.org
Mon, 3 Apr 2000 03:12:58 -0700 (PDT)


On Mon, 3 Apr 2000, Mark Favas wrote:
>...
> *** mmapmodule.c.orig   Mon Apr  3 10:23:19 2000
> --- mmapmodule.c        Mon Apr  3 14:57:23 2000
> ***************
> *** 118,124 ****
>         char value;
>         char * where = (self->data+self->pos);
>         CHECK_VALID(NULL);
> !       if ((where >= 0) && (where < (self->data+self->size))) {
>                 value = (char) *(where);
>                 self->pos += 1;
>                 return Py_BuildValue("c", (char) *(where));
> --- 118,124 ----
>         char value;
>         char * where = (self->data+self->pos);
>         CHECK_VALID(NULL);
> !       if ((where >= (char *) 0) && (where < (self->data+self->size)))
> {
>                 value = (char) *(where);
>                 self->pos += 1;
>                 return Py_BuildValue("c", (char) *(where));

Nope... that should be (where >= self->data).

The more obvious test would be something like:

  if (self->pos >= 0 && self->pos < self->size)

and throw the error before ever worrying about setting up "where".

> ***************
> *** 617,623 ****
>                                 "mmap slice assignment is wrong size");
>                 return -1;
>         }
> !       buf = PyString_AsString(v);
>         memcpy(self->data + ilow, buf, ihigh-ilow);
>         return 0;
>   }
> --- 617,623 ----
>                                 "mmap slice assignment is wrong size");
>                 return -1;
>         }
> !       buf = (unsigned char *) PyString_AsString(v);
>         memcpy(self->data + ilow, buf, ihigh-ilow);
>         return 0;
>   }

Rather than casting, the definition of "buf" should change to
"const char *buf".

> ***************
> *** 640,646 ****
>                         "mmap assignment must be single-character
> string");
>                 return -1;
>         }
> !       buf = PyString_AsString(v);
>         self->data[i] = buf[0];
>         return 0;
>   }
> --- 640,646 ----
>                         "mmap assignment must be single-character
> string");
>                 return -1;
>         }
> !       buf = (unsigned char *) PyString_AsString(v);
>         self->data[i] = buf[0];
>         return 0;
>   }

Same here.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/