Skip to content

Commit

Permalink
Fix a crash when burning things (#36471)
Browse files Browse the repository at this point in the history
* Make sure material_type::_burn_data is never empty

Perhaps this is a purist in me talking, but a JSON array can be empty but _burn_data must not be empty because material_type::burn_data() returns a reference to one of its elements.

* Fix read past the end of vector in burn_data

#36441
  • Loading branch information
hexagonrecursion authored and ZhilkinSerg committed Dec 26, 2019
1 parent d18fc5d commit 1f92726
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void material_type::load( const JsonObject &jsobj, const std::string & )
for( JsonObject brn : jsobj.get_array( "burn_data" ) ) {
_burn_data.emplace_back( load_mat_burn_data( brn ) );
}
} else {
}
if( _burn_data.empty() ) {
// If not specified, supply default
mat_burn_data mbd;
if( _fire_resist <= 0 ) {
Expand Down Expand Up @@ -255,7 +256,7 @@ bool material_type::reinforces() const

const mat_burn_data &material_type::burn_data( size_t intensity ) const
{
return _burn_data[ std::min<size_t>( intensity, fd_fire.obj().get_max_intensity() ) - 1 ];
return _burn_data[ std::min<size_t>( intensity, _burn_data.size() ) - 1 ];
}

const mat_burn_products &material_type::burn_products() const
Expand Down

0 comments on commit 1f92726

Please sign in to comment.