The following issues were found

doc/postprocess.py
8 issues
Unused argument 'fn'
Error

Line: 27 Column: 18

                      with io.open(fn, 'w', encoding="utf-8") as f:
            f.write("".join(lines))

def process_html(fn, lines):
    return lines

def process_tex(lines):
    """
    Remove unnecessary section titles from the LaTeX file.

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              """
import io

def main():
    import argparse

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('mode', help='file mode', choices=('html', 'tex'))
    parser.add_argument('file', nargs='+', help='input file(s)')

            

Reported by Pylint.

Import outside toplevel (argparse)
Error

Line: 8 Column: 5

              import io

def main():
    import argparse

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('mode', help='file mode', choices=('html', 'tex'))
    parser.add_argument('file', nargs='+', help='input file(s)')
    args = parser.parse_args()

            

Reported by Pylint.

Variable name "fn" doesn't conform to snake_case naming style
Error

Line: 17 Column: 9

              
    mode = args.mode

    for fn in args.file:
        with io.open(fn, 'r', encoding="utf-8") as f:
            if mode == 'html':
                lines = process_html(fn, f.readlines())
            elif mode == 'tex':
                lines = process_tex(f.readlines())

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 18 Column: 52

                  mode = args.mode

    for fn in args.file:
        with io.open(fn, 'r', encoding="utf-8") as f:
            if mode == 'html':
                lines = process_html(fn, f.readlines())
            elif mode == 'tex':
                lines = process_tex(f.readlines())


            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 24 Column: 52

                          elif mode == 'tex':
                lines = process_tex(f.readlines())

        with io.open(fn, 'w', encoding="utf-8") as f:
            f.write("".join(lines))

def process_html(fn, lines):
    return lines


            

Reported by Pylint.

Argument name "fn" doesn't conform to snake_case naming style
Error

Line: 27 Column: 1

                      with io.open(fn, 'w', encoding="utf-8") as f:
            f.write("".join(lines))

def process_html(fn, lines):
    return lines

def process_tex(lines):
    """
    Remove unnecessary section titles from the LaTeX file.

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                      with io.open(fn, 'w', encoding="utf-8") as f:
            f.write("".join(lines))

def process_html(fn, lines):
    return lines

def process_tex(lines):
    """
    Remove unnecessary section titles from the LaTeX file.

            

Reported by Pylint.

numpy/core/src/common/npy_cpuinfo_parser.h
8 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 65 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

              get_file_size(const char* pathname)
{
    int fd, result = 0;
    char buffer[256];

    fd = open(pathname, O_RDONLY);
    if (fd < 0) {
        return -1;
    }

            

Reported by FlawFinder.

open - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 67 Column: 10 CWE codes: 362

                  int fd, result = 0;
    char buffer[256];

    fd = open(pathname, O_RDONLY);
    if (fd < 0) {
        return -1;
    }

    for (;;) {

            

Reported by FlawFinder.

open - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 100 Column: 10 CWE codes: 362

              {
    int  fd, count;

    fd = open(pathname, O_RDONLY);
    if (fd < 0) {
        return -1;
    }
    count = 0;
    while (count < (int)buffsize) {

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 177 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                      goto EXIT;
    }

    memcpy(result, p, len);
    result[len] = '\0';

EXIT:
    return result;
}

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 73 Column: 19 CWE codes: 120 20

                  }

    for (;;) {
        int ret = read(fd, buffer, sizeof buffer);
        if (ret < 0) {
            if (errno == EINTR) {
                continue;
            }
            break;

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 106 Column: 19 CWE codes: 120 20

                  }
    count = 0;
    while (count < (int)buffsize) {
        int ret = read(fd, buffer + count, buffsize - count);
        if (ret < 0) {
            if (errno == EINTR) {
                continue;
            }
            if (count == 0) {

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 135 Column: 20 CWE codes: 126

              static char*
extract_cpuinfo_field(const char* buffer, int buflen, const char* field)
{
    int fieldlen = strlen(field);
    const char* bufend = buffer + buflen;
    char* result = NULL;
    int len;
    const char *p, *q;


            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 192 Column: 19 CWE codes: 126

              has_list_item(const char* list, const char* item)
{
    const char* p = list;
    int itemlen = strlen(item);

    if (list == NULL) {
        return 0;
    }


            

Reported by FlawFinder.

numpy/core/src/multiarray/item_selection.c
8 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 760 Column: 17 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                      for (j = 0; j < n; j++) {
            npy_intp tmp = broadcast ? counts[0] : counts[j];
            for (k = 0; k < tmp; k++) {
                memcpy(new_data, old_data, chunk);
                new_data += chunk;
            }
            old_data += chunk;
        }
    }

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1897 Column: 26 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

                  if (ap3 == NULL) {
        /* do regular binsearch */
        NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
        binsearch((const char *)PyArray_DATA(ap1),
                  (const char *)PyArray_DATA(ap2),
                  (char *)PyArray_DATA(ret),
                  PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                  PyArray_STRIDES(ap1)[0], PyArray_DESCR(ap2)->elsize,
                  NPY_SIZEOF_INTP, ap2);

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1898 Column: 26 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

                      /* do regular binsearch */
        NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
        binsearch((const char *)PyArray_DATA(ap1),
                  (const char *)PyArray_DATA(ap2),
                  (char *)PyArray_DATA(ret),
                  PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                  PyArray_STRIDES(ap1)[0], PyArray_DESCR(ap2)->elsize,
                  NPY_SIZEOF_INTP, ap2);
        NPY_END_THREADS_DESCR(PyArray_DESCR(ap2));

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1899 Column: 20 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

                      NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
        binsearch((const char *)PyArray_DATA(ap1),
                  (const char *)PyArray_DATA(ap2),
                  (char *)PyArray_DATA(ret),
                  PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                  PyArray_STRIDES(ap1)[0], PyArray_DESCR(ap2)->elsize,
                  NPY_SIZEOF_INTP, ap2);
        NPY_END_THREADS_DESCR(PyArray_DESCR(ap2));
    }

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1909 Column: 37 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

                      /* do binsearch with a sorter array */
        int error = 0;
        NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
        error = argbinsearch((const char *)PyArray_DATA(ap1),
                             (const char *)PyArray_DATA(ap2),
                             (const char *)PyArray_DATA(sorter),
                             (char *)PyArray_DATA(ret),
                             PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                             PyArray_STRIDES(ap1)[0],

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1910 Column: 37 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 error = 0;
        NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
        error = argbinsearch((const char *)PyArray_DATA(ap1),
                             (const char *)PyArray_DATA(ap2),
                             (const char *)PyArray_DATA(sorter),
                             (char *)PyArray_DATA(ret),
                             PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                             PyArray_STRIDES(ap1)[0],
                             PyArray_DESCR(ap2)->elsize,

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1911 Column: 37 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

                      NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
        error = argbinsearch((const char *)PyArray_DATA(ap1),
                             (const char *)PyArray_DATA(ap2),
                             (const char *)PyArray_DATA(sorter),
                             (char *)PyArray_DATA(ret),
                             PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                             PyArray_STRIDES(ap1)[0],
                             PyArray_DESCR(ap2)->elsize,
                             PyArray_STRIDES(sorter)[0], NPY_SIZEOF_INTP, ap2);

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1912 Column: 31 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

                      error = argbinsearch((const char *)PyArray_DATA(ap1),
                             (const char *)PyArray_DATA(ap2),
                             (const char *)PyArray_DATA(sorter),
                             (char *)PyArray_DATA(ret),
                             PyArray_SIZE(ap1), PyArray_SIZE(ap2),
                             PyArray_STRIDES(ap1)[0],
                             PyArray_DESCR(ap2)->elsize,
                             PyArray_STRIDES(sorter)[0], NPY_SIZEOF_INTP, ap2);
        NPY_END_THREADS_DESCR(PyArray_DESCR(ap2));

            

Reported by FlawFinder.

numpy/typing/tests/data/fail/flatiter.py
7 issues
No value for argument 'value' in constructor call
Error

Line: 23 Column: 3

              # NOTE: Contrary to `ndarray.__getitem__` its counterpart in `flatiter`
# does not accept objects with the `__array__` or `__index__` protocols;
# boolean indexing is just plain broken (gh-17175)
a[np.bool_()]  # E: No overload variant of "__getitem__"
a[Index()]  # E: No overload variant of "__getitem__"
a[supports_array]  # E: No overload variant of "__getitem__"

            

Reported by Pylint.

Expression "a[np.bool_()]" is assigned to nothing
Error

Line: 23 Column: 1

              # NOTE: Contrary to `ndarray.__getitem__` its counterpart in `flatiter`
# does not accept objects with the `__array__` or `__index__` protocols;
# boolean indexing is just plain broken (gh-17175)
a[np.bool_()]  # E: No overload variant of "__getitem__"
a[Index()]  # E: No overload variant of "__getitem__"
a[supports_array]  # E: No overload variant of "__getitem__"

            

Reported by Pylint.

Expression "a[Index()]" is assigned to nothing
Error

Line: 24 Column: 1

              # does not accept objects with the `__array__` or `__index__` protocols;
# boolean indexing is just plain broken (gh-17175)
a[np.bool_()]  # E: No overload variant of "__getitem__"
a[Index()]  # E: No overload variant of "__getitem__"
a[supports_array]  # E: No overload variant of "__getitem__"

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 25 Column: 1

              # boolean indexing is just plain broken (gh-17175)
a[np.bool_()]  # E: No overload variant of "__getitem__"
a[Index()]  # E: No overload variant of "__getitem__"
a[supports_array]  # E: No overload variant of "__getitem__"

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Any

import numpy as np
from numpy.typing import _SupportsArray


class Index:
    def __index__(self) -> int:
        ...

            

Reported by Pylint.

Missing class docstring
Error

Line: 7 Column: 1

              from numpy.typing import _SupportsArray


class Index:
    def __index__(self) -> int:
        ...


a: "np.flatiter[np.ndarray]"

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 7 Column: 1

              from numpy.typing import _SupportsArray


class Index:
    def __index__(self) -> int:
        ...


a: "np.flatiter[np.ndarray]"

            

Reported by Pylint.

numpy/distutils/command/build_scripts.py
7 issues
Expression "[log.info(" adding '%s' to scripts" % (s, )) for s in script]" is assigned to nothing
Error

Line: 31 Column: 17

                              log.info("  adding '%s' to scripts" % (script,))
                new_scripts.append(script)
            else:
                [log.info("  adding '%s' to scripts" % (s,)) for s in script]
                new_scripts.extend(list(script))
        return new_scripts

    def run (self):
        if not self.scripts:

            

Reported by Pylint.

Attribute 'scripts' defined outside __init__
Error

Line: 39 Column: 9

                      if not self.scripts:
            return

        self.scripts = self.generate_scripts(self.scripts)
        # Now make sure that the distribution object has this list of scripts.
        # setuptools' develop command requires that this be a list of filenames,
        # not functions.
        self.distribution.scripts = self.scripts


            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from numpy.distutils import log
from numpy.distutils.misc_util import is_string

class build_scripts(old_build_scripts):

    def generate_scripts(self, scripts):
        new_scripts = []
        func_scripts = []
        for script in scripts:

            

Reported by Pylint.

Class name "build_scripts" doesn't conform to PascalCase naming style
Error

Line: 8 Column: 1

              from numpy.distutils import log
from numpy.distutils.misc_util import is_string

class build_scripts(old_build_scripts):

    def generate_scripts(self, scripts):
        new_scripts = []
        func_scripts = []
        for script in scripts:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 5

              
class build_scripts(old_build_scripts):

    def generate_scripts(self, scripts):
        new_scripts = []
        func_scripts = []
        for script in scripts:
            if is_string(script):
                new_scripts.append(script)

            

Reported by Pylint.

Either all return statements in a function should return an expression, or none of them should.
Error

Line: 35 Column: 5

                              new_scripts.extend(list(script))
        return new_scripts

    def run (self):
        if not self.scripts:
            return

        self.scripts = self.generate_scripts(self.scripts)
        # Now make sure that the distribution object has this list of scripts.

            

Reported by Pylint.

Import outside toplevel (numpy.distutils.misc_util.get_script_files)
Error

Line: 48 Column: 9

                      return old_build_scripts.run(self)

    def get_source_files(self):
        from numpy.distutils.misc_util import get_script_files
        return get_script_files(self.scripts)

            

Reported by Pylint.

numpy/core/code_generators/ufunc_docstrings.py
7 issues
Too many lines in module (4234/1000)
Error

Line: 1 Column: 1

              """
Docstrings for generated ufuncs

The syntax is designed to look like the function add_newdoc is being
called from numpy.lib, but in this file  add_newdoc puts the docstrings
in a dictionary. This dictionary is used in
numpy/core/code_generators/generate_umath.py to generate the docstrings
for the ufuncs in numpy.core at the C level when the ufuncs are created
at compile time.

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              
docdict = {}

def get(name):
    return docdict.get(name)

# common parameter text to all ufuncs
subst = {
    'PARAMS': textwrap.dedent("""

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 45 Column: 1

                  'OUT_SCALAR_2': "This is a scalar if both `x1` and `x2` are scalars.",
}

def add_newdoc(place, name, doc):
    doc = textwrap.dedent(doc).strip()

    skip = (
        # gufuncs do not use the OUT_SCALAR replacement strings
        'matmul',

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 56
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  )
    if name[0] != '_' and name not in skip:
        if '\nx :' in doc:
            assert '$OUT_SCALAR_1' in doc, "in {}".format(name)
        elif '\nx2 :' in doc or '\nx1, x2 :' in doc:
            assert '$OUT_SCALAR_2' in doc, "in {}".format(name)
        else:
            assert False, "Could not detect number of inputs in {}".format(name)


            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 58
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      if '\nx :' in doc:
            assert '$OUT_SCALAR_1' in doc, "in {}".format(name)
        elif '\nx2 :' in doc or '\nx1, x2 :' in doc:
            assert '$OUT_SCALAR_2' in doc, "in {}".format(name)
        else:
            assert False, "Could not detect number of inputs in {}".format(name)

    for k, v in subst.items():
        doc = doc.replace('$' + k, v)

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 60
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      elif '\nx2 :' in doc or '\nx1, x2 :' in doc:
            assert '$OUT_SCALAR_2' in doc, "in {}".format(name)
        else:
            assert False, "Could not detect number of inputs in {}".format(name)

    for k, v in subst.items():
        doc = doc.replace('$' + k, v)

    docdict['.'.join((place, name))] = doc

            

Reported by Bandit.

Variable name "v" doesn't conform to snake_case naming style
Error

Line: 62 Column: 12

                      else:
            assert False, "Could not detect number of inputs in {}".format(name)

    for k, v in subst.items():
        doc = doc.replace('$' + k, v)

    docdict['.'.join((place, name))] = doc



            

Reported by Pylint.

numpy/distutils/extension.py
7 issues
Too many instance attributes (8/7)
Error

Line: 17 Column: 1

              fortran_pyf_ext_re = re.compile(r'.*\.(f90|f95|f77|for|ftn|f|pyf)\Z', re.I).match


class Extension(old_Extension):
    """
    Parameters
    ----------
    name : str
        Extension name.

            

Reported by Pylint.

Too many arguments (20/5)
Error

Line: 33 Column: 5

                  extra_f90_compile_args : list of str
        Extra command line arguments to pass to the fortran90 compiler.
    """
    def __init__(
            self, name, sources,
            include_dirs=None,
            define_macros=None,
            undef_macros=None,
            library_dirs=None,

            

Reported by Pylint.

Too many local variables (22/15)
Error

Line: 33 Column: 5

                  extra_f90_compile_args : list of str
        Extra command line arguments to pass to the fortran90 compiler.
    """
    def __init__(
            self, name, sources,
            include_dirs=None,
            define_macros=None,
            undef_macros=None,
            library_dirs=None,

            

Reported by Pylint.

Useless return at end of function or method
Error

Line: 33 Column: 5

                  extra_f90_compile_args : list of str
        Extra command line arguments to pass to the fortran90 compiler.
    """
    def __init__(
            self, name, sources,
            include_dirs=None,
            define_macros=None,
            undef_macros=None,
            library_dirs=None,

            

Reported by Pylint.

Import outside toplevel (warnings)
Error

Line: 74 Column: 13

                      # swig_opts is assumed to be a list. Here we handle the case where it
        # is specified as a string instead.
        if isinstance(self.swig_opts, str):
            import warnings
            msg = "swig_opts is specified as a string instead of a list"
            warnings.warn(msg, SyntaxWarning, stacklevel=2)
            self.swig_opts = self.swig_opts.split()

        # Python 2.3 distutils new features

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 91 Column: 5

              
        return

    def has_cxx_sources(self):
        for source in self.sources:
            if cxx_ext_re(str(source)):
                return True
        return False


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 97 Column: 5

                              return True
        return False

    def has_f2py_sources(self):
        for source in self.sources:
            if fortran_pyf_ext_re(source):
                return True
        return False


            

Reported by Pylint.

numpy/core/src/multiarray/nditer_api.c
7 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 1388 Column: 9 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                  }
    else {
        /* If there's no buffering, the strides are always fixed */
        memcpy(out_strides, NAD_STRIDES(axisdata0), nop*NPY_SIZEOF_INTP);
    }
}

/*NUMPY_API
 * Get a pointer to the size of the inner loop  (when HasExternalLoop is true)

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 1703 Column: 17 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                          NIT_ADVANCE_AXISDATA(axisdata, 1);
            NIT_ADVANCE_AXISDATA(ad_compress, 1);
            if (ad_compress != axisdata) {
                memcpy(ad_compress, axisdata, sizeof_axisdata);
            }
            ++new_ndim;
        }
    }


            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 2694 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

                  npy_bool nonzerocoord;

    npyiter_opitflags *op_itflags = NIT_OPITFLAGS(iter);
    char stride0op[NPY_MAXARGS];

    /* Default to no outer axis */
    *reduce_outerdim = 0;

    /* If there's only one dimension, no need to calculate anything */

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 1603 Column: 53 CWE codes: 120 20

                      }
        printf("|   ReadTransferFn: ");
        for (iop = 0; iop < nop; ++iop)
            printf("%p ", (void *)transferinfo[iop].read.func);
        printf("\n");
        printf("|   ReadTransferData: ");
        for (iop = 0; iop < nop; ++iop)
            printf("%p ", (void *)transferinfo[iop].read.auxdata);
        printf("\n");

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 1607 Column: 53 CWE codes: 120 20

                      printf("\n");
        printf("|   ReadTransferData: ");
        for (iop = 0; iop < nop; ++iop)
            printf("%p ", (void *)transferinfo[iop].read.auxdata);
        printf("\n");
        printf("|   WriteTransferFn: ");
        for (iop = 0; iop < nop; ++iop)
            printf("%p ", (void *)transferinfo[iop].write.func);
        printf("\n");

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 2439 Column: 35 CWE codes: 120 20

                       * the buffer needs to be read.
         */
        if (op_itflags[iop] & NPY_OP_ITFLAG_USINGBUFFER &&
                transferinfo[iop].read.func != NULL) {
            npy_intp src_itemsize;
            npy_intp op_transfersize;

            npy_intp dst_stride, *src_strides, *src_coords, *src_shape;
            int ndim_transfer;

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 2557 Column: 44 CWE codes: 120 20

                                      src_coords, axisdata_incr,
                        src_shape, axisdata_incr,
                        op_transfersize, src_itemsize,
                        &transferinfo[iop].read) < 0) {
                    return -1;
                }
            }
        }
    }

            

Reported by FlawFinder.

numpy/distutils/tests/test_build_ext.py
7 issues
Unable to import 'pytest'
Error

Line: 7 Column: 1

              import subprocess
import sys
from textwrap import indent, dedent
import pytest

@pytest.mark.slow
def test_multi_fortran_libs_link(tmp_path):
    '''
    Ensures multiple "fake" static libraries are correctly linked.

            

Reported by Pylint.

Consider possible security implications associated with subprocess module.
Security blacklist

Line: 4
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              '''Tests for numpy.distutils.build_ext.'''

import os
import subprocess
import sys
from textwrap import indent, dedent
import pytest

@pytest.mark.slow

            

Reported by Bandit.

Import outside toplevel (numpy.f2py.tests.util.has_f77_compiler)
Error

Line: 19 Column: 5

                  # We need to make sure we actually have an f77 compiler.
    # This is nontrivial, so we'll borrow the utilities
    # from f2py tests:
    from numpy.f2py.tests.util import has_f77_compiler
    if not has_f77_compiler():
        pytest.skip('No F77 compiler found')

    # make some dummy sources
    with open(tmp_path / '_dummy1.f', 'w') as fid:

            

Reported by Pylint.

subprocess call - check for execution of untrusted input.
Security injection

Line: 59
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

              
    # build the test extensino and "install" into a temporary directory
    build_dir = tmp_path
    subprocess.check_call([sys.executable, 'setup.py', 'build', 'install',
                           '--prefix', str(tmp_path / 'installdir'),
                           '--record', str(tmp_path / 'tmp_install_log.txt'),
                          ],
                          cwd=str(build_dir),
                      )

            

Reported by Bandit.

Variable name "so" doesn't conform to snake_case naming style
Error

Line: 66 Column: 5

                                        cwd=str(build_dir),
                      )
    # get the path to the so
    so = None
    with open(tmp_path /'tmp_install_log.txt') as fid:
        for line in fid:
            if 'dummyext' in line:
                so = line.strip()
                break

            

Reported by Pylint.

Variable name "so" doesn't conform to snake_case naming style
Error

Line: 70 Column: 17

                  with open(tmp_path /'tmp_install_log.txt') as fid:
        for line in fid:
            if 'dummyext' in line:
                so = line.strip()
                break
    assert so is not None

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 72
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                          if 'dummyext' in line:
                so = line.strip()
                break
    assert so is not None

            

Reported by Bandit.

numpy/distutils/tests/test_fcompiler.py
7 issues
Using deprecated method assert_()
Error

Line: 28 Column: 9

                      new_flags = getattr(flag_vars, opt)

        monkeypatch.delenv(envvar)
        assert_(new_flags == [new_flag])

    monkeypatch.setenv('NPY_DISTUTILS_APPEND_FLAGS', '1')

    for opt, envvar in customizable_flags:
        new_flag = '-dummy-{}-flag'.format(opt)

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 40 Column: 13

              
        monkeypatch.delenv(envvar)
        if prev_flags is None:
            assert_(new_flags == [new_flag])
        else:
            assert_(new_flags == prev_flags + [new_flag])


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 42 Column: 13

                      if prev_flags is None:
            assert_(new_flags == [new_flag])
        else:
            assert_(new_flags == prev_flags + [new_flag])


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from numpy.testing import assert_
import numpy.distutils.fcompiler

customizable_flags = [
    ('f77', 'F77FLAGS'),
    ('f90', 'F90FLAGS'),
    ('free', 'FREEFLAGS'),
    ('arch', 'FARCH'),
    ('debug', 'FDEBUG'),

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              ]


def test_fcompiler_flags(monkeypatch):
    monkeypatch.setenv('NPY_DISTUTILS_APPEND_FLAGS', '0')
    fc = numpy.distutils.fcompiler.new_fcompiler(compiler='none')
    flag_vars = fc.flag_vars.clone(lambda *args, **kwargs: None)

    for opt, envvar in customizable_flags:

            

Reported by Pylint.

Variable name "fc" doesn't conform to snake_case naming style
Error

Line: 17 Column: 5

              
def test_fcompiler_flags(monkeypatch):
    monkeypatch.setenv('NPY_DISTUTILS_APPEND_FLAGS', '0')
    fc = numpy.distutils.fcompiler.new_fcompiler(compiler='none')
    flag_vars = fc.flag_vars.clone(lambda *args, **kwargs: None)

    for opt, envvar in customizable_flags:
        new_flag = '-dummy-{}-flag'.format(opt)
        prev_flags = getattr(flag_vars, opt)

            

Reported by Pylint.

Trailing newlines
Error

Line: 43 Column: 1

                          assert_(new_flags == [new_flag])
        else:
            assert_(new_flags == prev_flags + [new_flag])


            

Reported by Pylint.