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

Undefined behavior #211

Open
Code7R opened this issue Dec 24, 2017 · 5 comments
Open

Undefined behavior #211

Code7R opened this issue Dec 24, 2017 · 5 comments

Comments

@Code7R
Copy link
Collaborator

Code7R commented Dec 24, 2017

Should be fixed by somebody who is sober enough and has time to deal with math...

Repro steps: build with -fsanitize=integer , run, move windows around, let the tool tips appear on the edges of the screen, open menus on the edges.

Bonus points: I think I have seen one of them with icewmbg too.

src/ypopup.cc:156:27: runtime error: unsigned integer overflow: 333 + 4294967295 cannot be represented in type 'unsigned int'
src/ypopup.cc:156:15: runtime error: unsigned integer overflow: 242 - 332 cannot be represented in type 'unsigned int'
src/ypopup.cc:168:22: runtime error: unsigned integer overflow: 4294967206 + 333 cannot be represented in type 'unsigned int'
src/ypopup.cc:183:16: runtime error: unsigned integer overflow: 4294967206 + 333 cannot be represented in type 'unsigned int'
src/ypopup.cc:147:26: runtime error: unsigned integer overflow: 183 + 4294967295 cannot be represented in type 'unsigned int'
src/ypopup.cc:147:15: runtime error: unsigned integer overflow: 408 - 411 cannot be represented in type 'unsigned int'
src/ypopup.cc:161:22: runtime error: unsigned integer overflow: 4294967293 + 233 cannot be represented in type 'unsigned int'
src/ypopup.cc:164:15: runtime error: unsigned integer overflow: 4294967293 + 411 cannot be represented in type 'unsigned int'

@Code7R
Copy link
Collaborator Author

Code7R commented Dec 24, 2017

More, open window list:

src/wmwinlist.cc:467:20: runtime error: unsigned integer overflow: 102 - 165 cannot be represented in type 'unsigned int'
src/wmwinlist.cc:468:20: runtime error: unsigned integer overflow: 51 - 133 cannot be represented in type 'unsigned int'
src/wmwinlist.cc:469:20: runtime error: unsigned integer overflow: 4294967233 + 330 cannot be represented in type 'unsigned int'
src/wmwinlist.cc:471:20: runtime error: unsigned integer overflow: 4294967214 + 266 cannot be represented in type 'unsigned int'

@gijsbers
Copy link
Collaborator

gijsbers commented Dec 24, 2017

The messages point out that it is not about math but about types.
Just stop using unsigned for width and height if you frequently need to combine
them with signed integers in the same calculation. Simple.

@Code7R
Copy link
Collaborator Author

Code7R commented Dec 25, 2017

Dealing with signedness is not a problem. The problem is that some of those variables are unsigned because they used directly or indirectly in X11 API calls. And there it's hard to tell whether there are reserved ranges or special values, unless you know the APIs by heart.

In some cases it might be possible to go with int64_t but it's IMHO ultima ratio and not applicable everywhere and still needs to be considered properly.

@bbidulock bbidulock reopened this Dec 28, 2017
@bbidulock
Copy link
Owner

I changed a lot of heights and widths to unsigned to expose this very issue. Many calculation seem to be ignorant of the fact that their results cannot be less than or equal to zero.

@gijsbers
Copy link
Collaborator

It caused a number of bugs, some of which are still not solved...
There was enough work to be done already...

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

No branches or pull requests

3 participants