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 out of bounds access in get_bar and improve satiety_bar #44572

Merged
merged 1 commit into from
Oct 4, 2020

Conversation

Qrox
Copy link
Contributor

@Qrox Qrox commented Oct 3, 2020

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 improve satiety_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 of string::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.

@Qrox Qrox changed the title Fix out of bounds access in get_bar Fix out of bounds access in get_bar and improve satiety_bar Oct 3, 2020
@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Info / User Interface Game - player communication, menus, etc. labels Oct 3, 2020
@gkarfakis19
Copy link
Contributor

gkarfakis19 commented Oct 3, 2020

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.

@Qrox
Copy link
Contributor Author

Qrox commented Oct 4, 2020

Sure, I'll make a PR to your branch.

@kevingranade kevingranade merged commit 18524b9 into CleverRaven:master Oct 4, 2020
@ZhilkinSerg
Copy link
Contributor

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 );
Copy link
Contributor

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.

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'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.

@Qrox Qrox deleted the get-bar branch October 5, 2020 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Info / User Interface Game - player communication, menus, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants