-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 out of bounds access in get_bar and improve satiety_bar #44572
Conversation
I appreciate your help in improving satiety_bar, but I've got lots of changes planned for it over at #44562 and I think it'd be better if your changes were handled after my PR gets merged, as satiety bar has been refactored. EDIT: If you prefer, you could commit your changes onto my PR and I would happily accept them, so this PR, which also improves the get_bar() functionality doesn't get blocked. |
Sure, I'll make a PR to your branch. |
You can rebase your branch on top of latest master to avoid conflicts. |
col = c_red_red; | ||
} else { | ||
int ind = static_cast<int>( ( 1 - status ) * colors.size() ); | ||
ind = clamp<int>( ind, 0, colors.size() - 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails to compile on gcc 5
:
11:15:51 In file included from src/ui_manager.h:7:0,
11:15:51 from src/output.cpp:37:
11:15:51 src/cuboid_rectangle.h: In instantiation of ‘struct rectangle<int>’:
11:15:51 src/output.cpp:1849:53: recursively required by substitution of ‘template<class Point> Point clamp(const Point&, const inclusive_rectangle<Point>&) [with Point = int]’
11:15:51 src/output.cpp:1849:53: required from here
11:15:51 src/cuboid_rectangle.h:9:37: error: ‘dimension’ is not a member of ‘int’
11:15:51 static_assert( Point::dimension == 2, "rectangle is for 2D points; use cuboid for 3D points" );
11:15:51 ^
11:15:51 cc1plus: error: unrecognized command line option ‘-Wno-unknown-warning-option’ [-Werror]
You probably should not use <int>
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm planning to address this in a different way at #44598. Disallowing using a valid syntax just to support an old compiler is too restrictive in my opinion.
Summary
SUMMARY: Bugfixes "Fix out of bounds access in get_bar and improve satiety_bar"
Purpose of change
Fix an out of bounds access in
get_bar
reported by AddressSanitizer, and improvesatiety_bar
.Describe the solution
Stricter checks on the float and integer values.
Improve granularity of
satiety_bar
by using float instead of int, and update the unit test to match changed results.Also use
utf8_width
instead ofstring::length
, just in case the bar may contain some non-ascii character in the future.Testing
Tested in game and hp bars / satiety bars were correctly displayed. Ran the satiety unit test and it passed.