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

Fix warning sign compare #80

Merged
merged 6 commits into from
Sep 12, 2023

Conversation

Bogumil-Sapinski-Mobica
Copy link
Contributor

No description provided.

@@ -10,7 +10,7 @@ namespace cl {
namespace sdk {
struct Image
{
int width = 0, height = 0, pixel_size = 1;
size_t width = 0, height = 0, pixel_size = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Given there are changes below to reinterpret_cast these back to int in one location below is this the correct change? Should the other side of whatever was triggering the warning be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reinterpret_cast was enforced by stb_image library which seams to be an old C-style code which uses signed int where unsigned int will suffice. As it is external library I could not change it. However Image class is a good place to set a boundary between new/old code.
Reinterpret cast is done while loading the image from file so there is no danger of loosing the data.
I would concern about writing image with stb as it is doing implicit cast from size_t to int.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a superficial problem to me. While on an academic level I agree with "don't use signed types where values can't be negative", as ill fate, 3rd parties and legacy C compatibility may have it, sometimes a cleanup is just too much hassle.

Yes, the SDK lib chose int to interface nicely with stb. Should we change the choice of lib in the future, because the SDK utilities don't leak to users, we are always free to reevaluate that choice. Your proposed changes while seem fine at first, it is an extreme level of "running with scissors". int and size_t aren't even the same size, so casting their pointers and expecting to get the right value ventures into endianness and two's complement territory and/or knowing how much our languages (and their particular versions) shield us from them. I really don't think this part of the code, which is otherwise warning-free without turning width into a size_t is worth the hassle to reason about such matters.

Minimally, it ought to be unsigned int to make sure that stb's choice of int is always matched at least in size on every arch. Yet again, while almost every other day I'd air on the side of choosing the most restrictive yet adequate number representation, I don't think this is the case where we should practice that.

Copy link
Collaborator

@MathiasMagnus MathiasMagnus left a comment

Choose a reason for hiding this comment

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

Mostly good, but the sdk::Image changes I'd need convincing about.

@@ -10,7 +10,7 @@ namespace cl {
namespace sdk {
struct Image
{
int width = 0, height = 0, pixel_size = 1;
size_t width = 0, height = 0, pixel_size = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a superficial problem to me. While on an academic level I agree with "don't use signed types where values can't be negative", as ill fate, 3rd parties and legacy C compatibility may have it, sometimes a cleanup is just too much hassle.

Yes, the SDK lib chose int to interface nicely with stb. Should we change the choice of lib in the future, because the SDK utilities don't leak to users, we are always free to reevaluate that choice. Your proposed changes while seem fine at first, it is an extreme level of "running with scissors". int and size_t aren't even the same size, so casting their pointers and expecting to get the right value ventures into endianness and two's complement territory and/or knowing how much our languages (and their particular versions) shield us from them. I really don't think this part of the code, which is otherwise warning-free without turning width into a size_t is worth the hassle to reason about such matters.

Minimally, it ought to be unsigned int to make sure that stb's choice of int is always matched at least in size on every arch. Yet again, while almost every other day I'd air on the side of choosing the most restrictive yet adequate number representation, I don't think this is the case where we should practice that.

@Bogumil-Sapinski-Mobica
Copy link
Contributor Author

Hi @MathiasMagnus,
I have changed solution for warnings caused by comparing signed and unsigned ints. Please verify if this is ok for you.

@bashbaug
Copy link
Contributor

Merging as discussed in the September 12th teleconference. The CI failures are unrelated to these changes.

@bashbaug bashbaug merged commit 93cf3cd into KhronosGroup:main Sep 12, 2023
11 of 19 checks passed
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.

4 participants