From 79d4b0f5a2e8da753312aa0a48cbf96e85a754e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 6 Jan 2019 13:50:23 +0100 Subject: [PATCH] Check that allocations in SplineCommon succeed. Attempt at #11660 but not optimistic. --- GPU/Common/SplineCommon.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index 0e10a4e8ec..436e7d87c2 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -517,7 +517,16 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic // Simplify away bones and morph before proceeding // There are normally not a lot of control points so just splitting decoded should be reasonably safe, although not great. SimpleVertex *simplified_control_points = (SimpleVertex *)managedBuf.Allocate(sizeof(SimpleVertex) * (index_upper_bound + 1)); + if (!simplified_control_points) { + ERROR_LOG(G3D, "Failed to allocate space for simplified control points, skipping curve draw"); + return; + } + u8 *temp_buffer = managedBuf.Allocate(sizeof(SimpleVertex) * num_points); + if (!temp_buffer) { + ERROR_LOG(G3D, "Failed to allocate space for temp buffer, skipping curve draw"); + return; + } u32 origVertType = vertType; vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType); @@ -531,6 +540,10 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic // Make an array of pointers to the control points, to get rid of indices. const SimpleVertex **points = (const SimpleVertex **)managedBuf.Allocate(sizeof(SimpleVertex *) * num_points); + if (!points) { + ERROR_LOG(G3D, "Failed to allocate space for control point pointers, skipping curve draw"); + return; + } for (int idx = 0; idx < num_points; idx++) points[idx] = simplified_control_points + (indices ? ConvertIndex(idx) : idx);