10000 MAINT: Fix sign-compare warnings in mem_overlap.c. · eric-wieser/numpy@19c55b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19c55b9

Browse files
committed
MAINT: Fix sign-compare warnings in mem_overlap.c.
1 parent 7bb2d5a commit 19c55b9

File tree

1 file changed

+12
-10
lines changed

numpy/core/src/private/mem_overlap.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ diophantine_dfs(unsigned int n,
415415
x[0] = x1 + c1*t_l;
416416
x[1] = x2 - c2*t_l;
417417
if (require_ub_nontrivial) {
418-
int j, is_ub_trivial;
418+
unsigned int j;
419+
int is_ub_trivial;
419420

420421
is_ub_trivial = 1;
421422
for (j = 0; j < n; ++j) {
@@ -711,7 +712,7 @@ static int
711712
strides_to_terms(PyArrayObject *arr, diophantine_term_t *terms,
712713
unsigned int *nterms, int skip_empty)
713714
{
714-
unsigned int i;
715+
int i;
715716

716717
for (i = 0; i < PyArray_NDIM(arr); ++i) {
717718
if (skip_empty) {
@@ -756,9 +757,11 @@ solve_may_share_memory(PyArrayObject *a, PyArrayObject *b,
756757
Py_ssize_t max_work)
757758
{
758759
npy_int64 rhs;
759-
diophantine_term_t terms[2*NPY_MAXDIMS+2];
760-
npy_uintp start1 = 0, start2 = 0, end1 = 0, end2 = 0, size1 = 0, size2 = 0;
761-
npy_int64 x[2*NPY_MAXDIMS+2];
760+
diophantine_term_t terms[2*NPY_MAXDIMS + 2];
761+
npy_uintp start1 = 0, end1 = 0, size1 = 0;
762+
npy_uintp start2 = 0, end2 = 0, size2 = 0;
763+
npy_uintp uintp_rhs;
764+
npy_int64 x[2*NPY_MAXDIMS + 2];
762765
unsigned int nterms;
763766

764767
get_array_memory_extents(a, &start1, &end1, &size1);
@@ -797,12 +800,12 @@ solve_may_share_memory(PyArrayObject *a, PyArrayObject *b,
797800
the extent check above.)
798801
*/
799802

800-
rhs = MIN(end2 - 1 - start1, end1 - 1 - start2);
801-
802-
if (rhs != (npy_uintp)rhs) {
803+
uintp_rhs = MIN(end2 - 1 - start1, end1 - 1 - start2);
804+
if (uintp_rhs > NPY_MAX_INT64) {
803805
/* Integer overflow */
804806
return MEM_OVERLAP_OVERFLOW;
805807
}
808+
rhs = (npy_int64)uintp_rhs;
806809

807810
nterms = 0;
808811
if (strides_to_terms(a, terms, &nterms, 1)) {
@@ -845,8 +848,7 @@ solve_may_have_internal_overlap(PyArrayObject *a, Py_ssize_t max_work)
845848
{
846849
diophantine_term_t terms[NPY_MAXDIMS+1];
847850
npy_int64 x[NPY_MAXDIMS+1];
848-
unsigned int nterms;
849-
int i, j;
851+
unsigned int i, j, nterms;
850852

851853
if (PyArray_ISCONTIGUOUS(a)) {
852854
/* Quick case */

0 commit comments

Comments
 (0)
0