Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis (MSVC) fixes for device_buffer_utils.h #7904

Merged
merged 3 commits into from
Oct 20, 2023

Conversation

slomp
Copy link
Contributor

@slomp slomp commented Oct 17, 2023

Preventing things like:

Warning	C26451	Arithmetic overflow: Using operator '*' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '*' to avoid overflow (io.2).

@@ -89,7 +93,7 @@ WEAK device_copy make_buffer_copy(const halide_buffer_t *src, bool src_host,
// Offset the src base pointer to the right point in its buffer.
c.src_begin = 0;
for (int i = 0; i < src->dimensions; i++) {
c.src_begin += (uint64_t)src->dim[i].stride * (dst->dim[i].min - src->dim[i].min);
c.src_begin += (uint64_t)src->dim[i].stride * (uint64_t)(dst->dim[i].min - src->dim[i].min);
Copy link
Member

Choose a reason for hiding this comment

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

Should this be uint or int?

Copy link
Contributor Author

@slomp slomp Oct 19, 2023

Choose a reason for hiding this comment

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

Good point... Are strides allowed to be negative too (to move "backward", in order to represent bottom-left origin images and such)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed both casts to (int64_t) to be consistent with the other similar casts in the same file.

@slomp
Copy link
Contributor Author

slomp commented Oct 20, 2023

Build-bot failures appear to be unrelated.

@abadams abadams merged commit 872264c into main Oct 20, 2023
3 checks passed
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
* Static analysis (MSVC) fixes for device_buffer_utils.h

* clang-format happiness

* signed integer cast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants