From 1f927262477346af88b3bca6606076af55387632 Mon Sep 17 00:00:00 2001 From: hexagonrecursion <52621858+hexagonrecursion@users.noreply.github.com> Date: Thu, 26 Dec 2019 19:55:00 +0000 Subject: [PATCH] Fix a crash when burning things (#36471) * 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 https://github.com/CleverRaven/Cataclysm-DDA/issues/36441 --- src/material.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/material.cpp b/src/material.cpp index d3d8309e6ba10..629c910fc8ad9 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -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 ) { @@ -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( intensity, fd_fire.obj().get_max_intensity() ) - 1 ]; + return _burn_data[ std::min( intensity, _burn_data.size() ) - 1 ]; } const mat_burn_products &material_type::burn_products() const