Fixed possible crash.

STK could crash when invalid graphics restriction name was set in graphics_restrictions.xml file.
It's because of wrong while (m_names_of_restrictions[i] != NULL) condition.
This commit is contained in:
Deve 2017-01-05 00:28:16 +01:00
parent 23acade026
commit fb0a54278a
2 changed files with 3 additions and 8 deletions

View File

@ -26,6 +26,7 @@
#include "utils/types.hpp" #include "utils/types.hpp"
#include <algorithm> #include <algorithm>
#include <array>
namespace GraphicsRestrictions namespace GraphicsRestrictions
{ {
@ -39,7 +40,7 @@ namespace GraphicsRestrictions
/** The list of names used in the XML file for the graphics /** The list of names used in the XML file for the graphics
* restriction types. They must be in the same order as the types. */ * restriction types. They must be in the same order as the types. */
const char *m_names_of_restrictions[] = { std::array<std::string, 27> m_names_of_restrictions = {
"UniformBufferObject", "UniformBufferObject",
"GeometryShader", "GeometryShader",
"DrawIndirect", "DrawIndirect",
@ -58,10 +59,8 @@ namespace GraphicsRestrictions
"AMDVertexShaderLayer", "AMDVertexShaderLayer",
"ExplicitAttribLocation", "ExplicitAttribLocation",
"TextureFilterAnisotropic", "TextureFilterAnisotropic",
#if defined(USE_GLES2)
"TextureFormatBGRA8888", "TextureFormatBGRA8888",
"ColorBufferFloat", "ColorBufferFloat",
#endif
"DriverRecentEnough", "DriverRecentEnough",
"HighDefinitionTextures", "HighDefinitionTextures",
"AdvancedPipeline", "AdvancedPipeline",
@ -77,12 +76,10 @@ namespace GraphicsRestrictions
* GR_COUNT if the name is not found. */ * GR_COUNT if the name is not found. */
GraphicsRestrictionsType getTypeForName(const std::string &name) GraphicsRestrictionsType getTypeForName(const std::string &name)
{ {
unsigned int i = 0; for (unsigned int i = 0; i < m_names_of_restrictions.size(); i++)
while (m_names_of_restrictions[i] != NULL)
{ {
if (name == m_names_of_restrictions[i]) if (name == m_names_of_restrictions[i])
return (GraphicsRestrictionsType)i; return (GraphicsRestrictionsType)i;
i++;
} }
return GR_COUNT; return GR_COUNT;
} // getTypeForName } // getTypeForName

View File

@ -52,10 +52,8 @@ namespace GraphicsRestrictions
GR_AMD_VERTEX_SHADER_LAYER, GR_AMD_VERTEX_SHADER_LAYER,
GR_EXPLICIT_ATTRIB_LOCATION, GR_EXPLICIT_ATTRIB_LOCATION,
GR_TEXTURE_FILTER_ANISOTROPIC, GR_TEXTURE_FILTER_ANISOTROPIC,
#if defined(USE_GLES2)
GR_TEXTURE_FORMAT_BGRA8888, GR_TEXTURE_FORMAT_BGRA8888,
GR_COLOR_BUFFER_FLOAT, GR_COLOR_BUFFER_FLOAT,
#endif
GR_DRIVER_RECENT_ENOUGH, GR_DRIVER_RECENT_ENOUGH,
GR_HIGHDEFINITION_TEXTURES, GR_HIGHDEFINITION_TEXTURES,
GR_ADVANCED_PIPELINE, GR_ADVANCED_PIPELINE,