Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: "CodeQL"

on:
push:
branches: [main, v*.x]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: '45 19 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ['cpp', 'javascript', 'python']

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
if: matrix.language != 'javascript'
with:
python-version: '3.x'
- name: Install dependencies
if: matrix.language != 'javascript'
run: |
python -m pip install --upgrade pip setuptools wheel
# TODO: Use pip-tools instead when it supports build-system
# dependencies so we don't need another copy here.
# https://github.com/jazzband/pip-tools/pull/1681
python -m pip install --upgrade \
certifi contourpy cycler fonttools kiwisolver importlib_resources \
numpy packaging pillow pyparsing python-dateutil setuptools-scm
echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
setup-python-dependencies: false

- name: Build compiled code
if: matrix.language == 'cpp'
run: |
mkdir ~/.cache/matplotlib
$CODEQL_PYTHON setup.py build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
7 changes: 7 additions & 0 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def get_and_extract_tarball(urls, sha, dirname):
"""
toplevel = Path("build", dirname)
if not toplevel.exists(): # Download it or load it from cache.
try:
import certifi # noqa
except ImportError as e:
raise ImportError(
f"`certifi` is unavailable ({e}) so unable to download any of "
f"the following: {urls}.") from None

Path("build").mkdir(exist_ok=True)
for url in urls:
try:
Expand Down
2 changes: 1 addition & 1 deletion src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void BufferRegion::to_string_argb(uint8_t *buf)
unsigned char tmp;
size_t i, j;

memcpy(buf, data, height * stride);
memcpy(buf, data, (size_t) height * stride);

for (i = 0; i < (size_t)height; ++i) {
pix = buf + i * stride;
Expand Down
2 changes: 1 addition & 1 deletion src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ class QuadMeshGenerator

inline size_t num_paths() const
{
return m_meshWidth * m_meshHeight;
return (size_t) m_meshWidth * m_meshHeight;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py_adaptors.h defines num_paths as Py_ssize_t, perhaps better for consistency, though anything will work, of course.

}

inline path_iterator operator()(size_t i) const
Expand Down
8 changes: 5 additions & 3 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static PyObject *PyBufferRegion_to_string(PyBufferRegion *self, PyObject *args)
return NULL;
}
return PyBytes_FromStringAndSize((const char *)self->x->get_data(),
self->x->get_height() * self->x->get_stride());
(Py_ssize_t) self->x->get_height() * self->x->get_stride());
}

/* TODO: This doesn't seem to be used internally. Remove? */
Expand Down Expand Up @@ -98,8 +98,10 @@ static PyObject *PyBufferRegion_to_string_argb(PyBufferRegion *self, PyObject *a
}
PyObject *bufobj;
uint8_t *buf;

bufobj = PyBytes_FromStringAndSize(NULL, self->x->get_height() * self->x->get_stride());
Py_ssize_t height, stride;
height = self->x->get_height();
stride = self->x->get_stride();
bufobj = PyBytes_FromStringAndSize(NULL, height * stride);
buf = (uint8_t *)PyBytes_AS_STRING(bufobj);

CALL_CPP_CLEANUP("to_string_argb", (self->x->to_string_argb(buf)), Py_DECREF(bufobj));
Expand Down
2 changes: 1 addition & 1 deletion src/_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ bool convert_to_string(PathIterator &path,
clipped_t clipped(nan_removed, do_clip, clip_rect);
simplify_t simplified(clipped, simplify, path.simplify_threshold());

buffersize = path.total_vertices() * (precision + 5) * 4;
buffersize = (size_t) path.total_vertices() * (precision + 5) * 4;
if (buffersize == 0) {
return true;
}
Expand Down