summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2008-02-10 05:11:58 +0000
committerCharles Harris <charlesr.harris@gmail.com>2008-02-10 05:11:58 +0000
commit382e6729df96fd97cdbcc350c98c5a8f98ba8630 (patch)
tree63e056acfced7411b72e5daa82a4adde19f8321c
parentec93d800236017db668e1b01db0ae7988782cdb1 (diff)
downloadnumpy-382e6729df96fd97cdbcc350c98c5a8f98ba8630.tar.gz
Fix STRING_compare function to work correctly with strings containing zeros.
-rw-r--r--numpy/core/src/arraytypes.inc.src12
1 files changed, 11 insertions, 1 deletions
diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src
index dbee57c33..fd43b4c58 100644
--- a/numpy/core/src/arraytypes.inc.src
+++ b/numpy/core/src/arraytypes.inc.src
@@ -1679,7 +1679,17 @@ OBJECT_compare(PyObject **ip1, PyObject **ip2, PyArrayObject *ap)
static int
STRING_compare(char *ip1, char *ip2, PyArrayObject *ap)
{
- return strncmp(ip1, ip2, ap->descr->elsize);
+ const unsigned char *c1 = (unsigned char *)ip1;
+ const unsigned char *c2 = (unsigned char *)ip2;
+ const size_t len = ap->descr->elsize;
+ size_t i;
+
+ for(i = 0; i < len; ++i) {
+ if (c1[i] != c2[i]) {
+ return (c1[i] > c2[i]) ? 1 : -1;
+ }
+ }
+ return 0;
}
/* taken from Python */