summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2007-02-28 23:52:12 +0000
committerTravis Oliphant <oliphant@enthought.com>2007-02-28 23:52:12 +0000
commit2288ef64c313e4de8c95b171fd235f0da9e159ec (patch)
tree14baaa973ae2dffa282959b994824669d90e6d4d /numpy/core/src/arrayobject.c
parent9f71c0fca2da061bb371b7f5a8a23ac40d6b28fb (diff)
downloadnumpy-2288ef64c313e4de8c95b171fd235f0da9e159ec.tar.gz
Fix string comparison so it is not fooled by NULLs in the string.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index eaed75f14..95547ac7d 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -4254,6 +4254,7 @@ _myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)
PyArray_UCS4 *s1t=s1, *s2t=s2;
int val;
intp size;
+ int diff;
if ((intp)s1 % sizeof(PyArray_UCS4) != 0) {
size = len1*sizeof(PyArray_UCS4);
@@ -4267,9 +4268,12 @@ _myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)
}
val = PyArray_CompareUCS4(s1t, s2t, MIN(len1,len2));
if ((val != 0) || (len1 == len2)) goto finish;
- if (len2 > len1) {sptr = s2t+len1; val = -1;}
- else {sptr = s1t+len2; val = 1;}
- if (*sptr != 0) goto finish;
+ if (len2 > len1) {sptr = s2t+len1; val = -1; diff=len2-len1;}
+ else {sptr = s1t+len2; val = 1; diff=len1-len2;}
+ while (diff--) {
+ if (*sptr != 0) goto finish;
+ sptr++;
+ }
val = 0;
finish:
@@ -4291,13 +4295,17 @@ _mystrncmp(char *s1, char *s2, int len1, int len2)
{
char *sptr;
int val;
+ int diff;
val = strncmp(s1, s2, MIN(len1, len2));
if ((val != 0) || (len1 == len2)) return val;
- if (len2 > len1) {sptr = s2+len1; val = -1;}
- else {sptr = s1+len2; val = 1;}
- if (*sptr != 0) return val;
- return 0;
+ if (len2 > len1) {sptr = s2+len1; val = -1; diff=len2-len1;}
+ else {sptr = s1+len2; val = 1; diff=len1-len2;}
+ while (diff--) {
+ if (*sptr != 0) return val;
+ sptr++;
+ }
+ return 0; /* Only happens if NULLs are everywhere */
}
/* Borrowed from Numarray */