The following issues were found
numpy/core/src/multiarray/flagsobject.c
4 issues
Line: 535
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)
{
char *key = NULL;
char buf[16];
int n;
if (PyUnicode_Check(ind)) {
PyObject *tmp_str;
tmp_str = PyUnicode_AsASCIIString(ind);
if (tmp_str == NULL) {
Reported by FlawFinder.
Line: 549
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
Py_DECREF(tmp_str);
goto fail;
}
memcpy(buf, key, n);
Py_DECREF(tmp_str);
key = buf;
}
else if (PyBytes_Check(ind)) {
key = PyBytes_AS_STRING(ind);
Reported by FlawFinder.
Line: 660
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)
{
char *key;
char buf[16];
int n;
if (PyUnicode_Check(ind)) {
PyObject *tmp_str;
tmp_str = PyUnicode_AsASCIIString(ind);
key = PyBytes_AS_STRING(tmp_str);
Reported by FlawFinder.
Line: 668
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
key = PyBytes_AS_STRING(tmp_str);
n = PyBytes_GET_SIZE(tmp_str);
if (n > 16) n = 16;
memcpy(buf, key, n);
Py_DECREF(tmp_str);
key = buf;
}
else if (PyBytes_Check(ind)) {
key = PyBytes_AS_STRING(ind);
Reported by FlawFinder.
numpy/typing/tests/data/fail/fromnumeric.py
4 issues
Line: 19
Column: 1
np.reshape(A, 1, order="bob") # E: Argument "order" to "reshape" has incompatible type
np.choose(a, None) # E: incompatible type
np.choose(a, out=1.0) # E: incompatible type
np.choose(A, mode="bob") # E: incompatible type
np.repeat(a, None) # E: Argument 2 to "repeat" has incompatible type
np.repeat(A, 1, axis=1.0) # E: Argument "axis" to "repeat" has incompatible type
Reported by Pylint.
Line: 20
Column: 1
np.choose(a, None) # E: incompatible type
np.choose(a, out=1.0) # E: incompatible type
np.choose(A, mode="bob") # E: incompatible type
np.repeat(a, None) # E: Argument 2 to "repeat" has incompatible type
np.repeat(A, 1, axis=1.0) # E: Argument "axis" to "repeat" has incompatible type
np.swapaxes(A, None, 1) # E: Argument 2 to "swapaxes" has incompatible type
Reported by Pylint.
Line: 63
Column: 1
np.argsort(A, order=range(5)) # E: Argument "order" to "argsort" has incompatible type
np.argmax(A, axis="bob") # E: No overload variant of "argmax" matches argument type
np.argmax(A, kind="bob") # E: No overload variant of "argmax" matches argument type
np.argmin(A, axis="bob") # E: No overload variant of "argmin" matches argument type
np.argmin(A, kind="bob") # E: No overload variant of "argmin" matches argument type
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
Reported by Pylint.
Line: 66
Column: 1
np.argmax(A, kind="bob") # E: No overload variant of "argmax" matches argument type
np.argmin(A, axis="bob") # E: No overload variant of "argmin" matches argument type
np.argmin(A, kind="bob") # E: No overload variant of "argmin" matches argument type
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
A[0], 0, side="bob"
)
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
Reported by Pylint.
numpy/compat/__init__.py
4 issues
Line: 13
Column: 1
"""
from . import _inspect
from . import py3k
from ._inspect import getargspec, formatargspec
from .py3k import *
__all__ = []
__all__.extend(_inspect.__all__)
__all__.extend(py3k.__all__)
Reported by Pylint.
Line: 14
Column: 1
from . import _inspect
from . import py3k
from ._inspect import getargspec, formatargspec
from .py3k import *
__all__ = []
__all__.extend(_inspect.__all__)
__all__.extend(py3k.__all__)
Reported by Pylint.
Line: 11
Column: 1
* we may only need a small subset of the copied library/module
"""
from . import _inspect
from . import py3k
from ._inspect import getargspec, formatargspec
from .py3k import *
__all__ = []
Reported by Pylint.
Line: 12
Column: 1
"""
from . import _inspect
from . import py3k
from ._inspect import getargspec, formatargspec
from .py3k import *
__all__ = []
__all__.extend(_inspect.__all__)
Reported by Pylint.
numpy/core/src/multiarray/mapping.c
4 issues
Line: 800
Column: 21
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
for (i = 0; i < curr_idx; i++) {
if ((indices[i].type == HAS_FANCY) && indices[i].value > 0) {
if (indices[i].value != PyArray_DIM(self, used_ndim)) {
char err_msg[174];
PyOS_snprintf(err_msg, sizeof(err_msg),
"boolean index did not match indexed array along "
"dimension %d; dimension is %" NPY_INTP_FMT
" but corresponding boolean dimension is %" NPY_INTP_FMT,
Reported by FlawFinder.
Line: 1120
Column: 17
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
/* Process unmasked values */
bmask_data = npy_memchr(bmask_data, 0, bmask_stride, innersize,
&subloopsize, 0);
char *args[2] = {self_data, ret_data};
res = cast_info.func(&cast_info.context,
args, &subloopsize, strides, cast_info.auxdata);
if (res < 0) {
break;
}
Reported by FlawFinder.
Line: 1310
Column: 17
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
bmask_data = npy_memchr(bmask_data, 0, bmask_stride, innersize,
&subloopsize, 0);
char *args[2] = {v_data, self_data};
res = cast_info.func(&cast_info.context,
args, &subloopsize, strides, cast_info.auxdata);
if (res < 0) {
break;
}
Reported by FlawFinder.
Line: 2206
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
PyArray_MapIterReset(PyArrayMapIterObject *mit)
{
npy_intp indval;
char *baseptrs[2];
int i;
if (mit->size == 0) {
return;
}
Reported by FlawFinder.
numpy/distutils/numpy_distribution.py
4 issues
Line: 1
Column: 3
# XXX: Handle setuptools ?
from distutils.core import Distribution
# This class is used because we add new files (sconscripts, and so on) with the
# scons command
class NumpyDistribution(Distribution):
def __init__(self, attrs = None):
# A list of (sconscripts, pre_hook, post_hook, src, parent_names)
self.scons_data = []
Reported by Pylint.
Line: 1
Column: 1
# XXX: Handle setuptools ?
from distutils.core import Distribution
# This class is used because we add new files (sconscripts, and so on) with the
# scons command
class NumpyDistribution(Distribution):
def __init__(self, attrs = None):
# A list of (sconscripts, pre_hook, post_hook, src, parent_names)
self.scons_data = []
Reported by Pylint.
Line: 6
Column: 1
# This class is used because we add new files (sconscripts, and so on) with the
# scons command
class NumpyDistribution(Distribution):
def __init__(self, attrs = None):
# A list of (sconscripts, pre_hook, post_hook, src, parent_names)
self.scons_data = []
# A list of installable libraries
self.installed_libraries = []
Reported by Pylint.
Line: 16
Column: 5
self.installed_pkg_config = {}
Distribution.__init__(self, attrs)
def has_scons_scripts(self):
return bool(self.scons_data)
Reported by Pylint.
numpy/typing/tests/data/pass/einsumfunc.py
4 issues
Line: 14
Column: 8
AR_LIKE_c = [1j, 2j, 3j]
AR_LIKE_U = ["1", "2", "3"]
OUT_f: np.ndarray[Any, np.dtype[np.float64]] = np.empty(3, dtype=np.float64)
OUT_c: np.ndarray[Any, np.dtype[np.complex128]] = np.empty(3, dtype=np.complex128)
np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b)
np.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u)
np.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i)
Reported by Pylint.
Line: 15
Column: 8
AR_LIKE_U = ["1", "2", "3"]
OUT_f: np.ndarray[Any, np.dtype[np.float64]] = np.empty(3, dtype=np.float64)
OUT_c: np.ndarray[Any, np.dtype[np.complex128]] = np.empty(3, dtype=np.complex128)
np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b)
np.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u)
np.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i)
np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f)
Reported by Pylint.
Line: 3
Column: 1
from __future__ import annotations
from typing import List, Any
import numpy as np
AR_LIKE_b = [True, True, True]
AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)]
AR_LIKE_i = [1, 2, 3]
Reported by Pylint.
Line: 1
Column: 1
from __future__ import annotations
from typing import List, Any
import numpy as np
AR_LIKE_b = [True, True, True]
AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)]
AR_LIKE_i = [1, 2, 3]
Reported by Pylint.
numpy/core/src/multiarray/einsum_debug.h
3 issues
Line: 18
Column: 38
CWE codes:
134
Suggestion:
Use a constant for the format specification
#if NPY_EINSUM_DBG_TRACING
#include <cstdio>
#define NPY_EINSUM_DBG_PRINT(s) printf("%s", s);
#define NPY_EINSUM_DBG_PRINT1(s, p1) printf(s, p1);
#define NPY_EINSUM_DBG_PRINT2(s, p1, p2) printf(s, p1, p2);
#define NPY_EINSUM_DBG_PRINT3(s, p1, p2, p3) printf(s);
#else
#define NPY_EINSUM_DBG_PRINT(s)
#define NPY_EINSUM_DBG_PRINT1(s, p1)
Reported by FlawFinder.
Line: 19
Column: 42
CWE codes:
134
Suggestion:
Use a constant for the format specification
#include <cstdio>
#define NPY_EINSUM_DBG_PRINT(s) printf("%s", s);
#define NPY_EINSUM_DBG_PRINT1(s, p1) printf(s, p1);
#define NPY_EINSUM_DBG_PRINT2(s, p1, p2) printf(s, p1, p2);
#define NPY_EINSUM_DBG_PRINT3(s, p1, p2, p3) printf(s);
#else
#define NPY_EINSUM_DBG_PRINT(s)
#define NPY_EINSUM_DBG_PRINT1(s, p1)
#define NPY_EINSUM_DBG_PRINT2(s, p1, p2)
Reported by FlawFinder.
Line: 20
Column: 46
CWE codes:
134
Suggestion:
Use a constant for the format specification
#define NPY_EINSUM_DBG_PRINT(s) printf("%s", s);
#define NPY_EINSUM_DBG_PRINT1(s, p1) printf(s, p1);
#define NPY_EINSUM_DBG_PRINT2(s, p1, p2) printf(s, p1, p2);
#define NPY_EINSUM_DBG_PRINT3(s, p1, p2, p3) printf(s);
#else
#define NPY_EINSUM_DBG_PRINT(s)
#define NPY_EINSUM_DBG_PRINT1(s, p1)
#define NPY_EINSUM_DBG_PRINT2(s, p1, p2)
#define NPY_EINSUM_DBG_PRINT3(s, p1, p2, p3)
Reported by FlawFinder.
numpy/core/src/multiarray/nditer_pywrap.c
3 issues
Line: 44
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
PyArray_Descr **dtypes;
PyArrayObject **operands;
npy_intp *innerstrides, *innerloopsizeptr;
char readflags[NPY_MAXARGS];
char writeflags[NPY_MAXARGS];
};
static int npyiter_cache_values(NewNpyArrayIterObject *self)
{
Reported by FlawFinder.
Line: 45
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
PyArrayObject **operands;
npy_intp *innerstrides, *innerloopsizeptr;
char readflags[NPY_MAXARGS];
char writeflags[NPY_MAXARGS];
};
static int npyiter_cache_values(NewNpyArrayIterObject *self)
{
NpyIter *iter = self->iter;
Reported by FlawFinder.
Line: 840
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
int *nested_op_axes[NPY_MAXDIMS];
int nested_naxes[NPY_MAXDIMS], iaxes, naxes;
int negones[NPY_MAXDIMS];
char used_axes[NPY_MAXDIMS];
int buffersize = 0;
PyObject *ret = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&OOO&O&i", kwlist,
Reported by FlawFinder.
numpy/distutils/msvccompiler.py
3 issues
Line: 4
Column: 1
import os
from distutils.msvccompiler import MSVCCompiler as _MSVCCompiler
from .system_info import platform_bits
def _merge(old, new):
"""Concatenate two environment paths avoiding repeats.
Reported by Pylint.
Line: 1
Column: 1
import os
from distutils.msvccompiler import MSVCCompiler as _MSVCCompiler
from .system_info import platform_bits
def _merge(old, new):
"""Concatenate two environment paths avoiding repeats.
Reported by Pylint.
Line: 39
Column: 1
return ';'.join([old, new])
class MSVCCompiler(_MSVCCompiler):
def __init__(self, verbose=0, dry_run=0, force=0):
_MSVCCompiler.__init__(self, verbose, dry_run, force)
def initialize(self):
# The 'lib' and 'include' variables may be overwritten
Reported by Pylint.
numpy/core/src/multiarray/methods.c
3 issues
Line: 1580
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
res = PyObject_CallFunctionObjArgs(deepcopy, itemp, visit, NULL);
Py_XDECREF(itemp);
Py_XDECREF(otemp);
memcpy(optr, &res, sizeof(res));
}
}
Reported by FlawFinder.
Line: 2067
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
fa->strides = PyArray_DIMS(self) + nd;
if (nd) {
memcpy(PyArray_DIMS(self), dimensions, sizeof(npy_intp)*nd);
}
_array_fill_strides(PyArray_STRIDES(self), dimensions, nd,
PyArray_DESCR(self)->elsize,
(is_f_order ? NPY_ARRAY_F_CONTIGUOUS :
NPY_ARRAY_C_CONTIGUOUS),
Reported by FlawFinder.
Line: 2117
Column: 17
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
Py_DECREF(typecode);
}
else {
memcpy(PyArray_DATA(self), datastr, num);
}
PyArray_ENABLEFLAGS(self, NPY_ARRAY_OWNDATA);
fa->base = NULL;
Py_DECREF(rawdata);
}
Reported by FlawFinder.