diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-05-10 00:05:33 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-05-10 00:05:33 (GMT) |
commit | 4cd44ef4bfc5803c842df14fe9caacf765dd84ca (patch) | |
tree | 777b646c7412a09beff5c4399a80617871ce2051 /Modules/stropmodule.c | |
parent | 1a7b3eee946183c75eddecafe76c60e87c6f5e7d (diff) | |
download | cpython-4cd44ef4bfc5803c842df14fe9caacf765dd84ca.zip cpython-4cd44ef4bfc5803c842df14fe9caacf765dd84ca.tar.gz cpython-4cd44ef4bfc5803c842df14fe9caacf765dd84ca.tar.bz2 |
Fudge. stropmodule and stringobject both had copies of the buggy
mymemXXX stuff, and they were already out of synch. Fix the remaining
bugs in both and get them back in synch.
Bugfix release candidate.
Diffstat (limited to 'Modules/stropmodule.c')
-rw-r--r-- | Modules/stropmodule.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index b92cb01..253c4ec 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -982,7 +982,7 @@ strop_translate(PyObject *self, PyObject *args) MEM, the function returns -1. */ static int -mymemfind(char *mem, int len, char *pat, int pat_len) +mymemfind(const char *mem, int len, const char *pat, int pat_len) { register int ii; @@ -1007,7 +1007,7 @@ mymemfind(char *mem, int len, char *pat, int pat_len) mem=11111 and pat==11 also return 2. */ static int -mymemcnt(char *mem, int len, char *pat, int pat_len) +mymemcnt(const char *mem, int len, const char *pat, int pat_len) { register int offset = 0; int nfound = 0; @@ -1043,10 +1043,11 @@ mymemcnt(char *mem, int len, char *pat, int pat_len) NULL if an error occurred. */ static char * -mymemreplace(char *str, int len, - char *pat, int pat_len, - char *sub, int sub_len, - int count, int *out_len) +mymemreplace(const char *str, int len, /* input string */ + const char *pat, int pat_len, /* pattern string to find */ + const char *sub, int sub_len, /* substitution string */ + int count, /* number of replacements */ + int *out_len) { char *out_s; char *new_s; @@ -1064,7 +1065,11 @@ mymemreplace(char *str, int len, new_len = len + nfound*(sub_len - pat_len); if (new_len == 0) { - out_s = ""; + /* Have to allocate something for the caller to free(). */ + out_s = (char *)PyMem_MALLOC(1); + if (out_s = NULL) + return NULL; + out_s[0] = '\0'; } else { assert(new_len > 0); @@ -1102,7 +1107,7 @@ mymemreplace(char *str, int len, return_same: *out_len = -1; - return str; + return (char *)str; /* cast away const */ } |