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

type conversion to new types to avoid unsigned int rollover and signed int overflow #7216

Merged
merged 3 commits into from
Aug 8, 2024

Conversation

gulafaran
Copy link
Contributor

@gulafaran gulafaran commented Aug 7, 2024

unsigned int = -1 rolls over to unsigned int max, avoid rolling over by using the new typedefs WORKSPACEID/MONITORID/WINDOWID where this occured and also since we were rolling over getmonitorid() was passed a unsigned int max value and overflowed causing UB.

as a consequence of this turning on -Wshorten-64-to-32 revealed a few other mismatches related or close to same place where i changed the type to the correct one when refactoring. still remains a few in other places but thats for a future PR.

the opengl changes im not sure about if they are correct, requires a keen eye what the intention behind the stencil calls were but same deal there, -1 to gluint rolls over to uint max.

GLuint was being initialized to -1 and rolling over to unsigned int max,
its defined behaviour but very unnecessery. add a bool and use it for
checking if allocated or not.
-1 rolls over to unsigned int max, use 0xFF instead.
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

please do what I said with the typedefs just for the sake of having it done

@gulafaran
Copy link
Contributor Author

please do what I said with the typedefs just for the sake of having it done

any particular file you want those typedefs in

@vaxerski
Copy link
Member

vaxerski commented Aug 7, 2024

sharedDefs?

@gulafaran
Copy link
Contributor Author

sharedDefs?

onto it!

@gulafaran
Copy link
Contributor Author

also does this mean you want all of the various getworkspace* getmonitor* etc refactored for these typedefs?

@vaxerski
Copy link
Member

vaxerski commented Aug 7, 2024

si

@gulafaran
Copy link
Contributor Author

si

unless i typoed something, something like this?

@vaxerski
Copy link
Member

vaxerski commented Aug 7, 2024

yeah

lmk when done

@gulafaran
Copy link
Contributor Author

yeah

lmk when done

ok this went rather overboard, changed a few types and more and more and more until WORKSPACEID/MONITORID/WINDOWID was done. turned on -Wshorten-64-to-32 and fixed the related warnings and while i was there the other ones not related.

@gulafaran
Copy link
Contributor Author

yeah
lmk when done

ok this went rather overboard, changed a few types and more and more and more until WORKSPACEID/MONITORID/WINDOWID was done. turned on -Wshorten-64-to-32 and fixed the related warnings and while i was there the other ones not related.

there is still a few warnings remaining around -Wshorten-64-to-32 but thats for another PR cant catch it all in one sweep heh

@gulafaran
Copy link
Contributor Author

yeah id call it ready for review

@gulafaran gulafaran changed the title uint64_t type conversion to int instead to avoid unsigned int rollover type conversion to new types to avoid unsigned int rollover and signed int overflow Aug 8, 2024
@vaxerski
Copy link
Member

vaxerski commented Aug 8, 2024

or would you?

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

could we also get MONITOR_INVALID macros (like WORKSPACE_INVALID) for -1?

@gulafaran
Copy link
Contributor Author

could we also get MONITOR_INVALID macros (like WORKSPACE_INVALID) for -1?

When there's a will, there's a way — that way is code.

sure

there were a few uint64_t to int implicit conversions overflowing int
and causing UB, make all monitor/workspaces/windows use the new
typedefs. also fix the various related 64 to 32 implicit conversions
going around found with -Wshorten-64-to-32
@gulafaran
Copy link
Contributor Author

could we also get MONITOR_INVALID macros (like WORKSPACE_INVALID) for -1?

done

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

cheers, love ya (nohomo)

@vaxerski vaxerski merged commit 4b4971c into hyprwm:main Aug 8, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants