Skip to content

Commit f22ebec

Browse files
authored
Fix return-by-reference vulnerability in QM_Vector3Reflect (#37)
#### Potential fix for alerts #### * [Returning stack-allocated memory](https://github.com/PolyhedronStudio/Q2RTXPerimental/security/code-scanning/5) ## Summary `QM_Vector3Reflect` was returning a reference to a stack-allocated local variable, creating a dangling reference vulnerability. ## Changes - **inc/shared/math/qm_vector3.h**: Changed return type from `Vector3 &` to `Vector3` (return by value) ```cpp // Before QM_API_CONSTEXPR Vector3 &QM_Vector3Reflect( const Vector3 &v, const Vector3 &normal ) { Vector3 result = { 0.f, 0.f, 0.f }; // ... computation ... return result; // Dangling reference } // After QM_API_CONSTEXPR Vector3 QM_Vector3Reflect( const Vector3 &v, const Vector3 &normal ) { Vector3 result = { 0.f, 0.f, 0.f }; // ... computation ... return result; // Safe return by value } ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
2 parents b863d18 + 5d8e49f commit f22ebec

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

inc/shared/math/qm_vector3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ QM_API Vector3 QM_Vector3Lerp( const Vector3 &v1, const Vector3 &v2, const float
466466
}
467467

468468
// Calculate reflected vector to normal
469-
QM_API_CONSTEXPR Vector3 &QM_Vector3Reflect( const Vector3 &v, const Vector3 &normal ) {
469+
QM_API_CONSTEXPR Vector3 QM_Vector3Reflect( const Vector3 &v, const Vector3 &normal ) {
470470
Vector3 result = { 0.f, 0.f, 0.f };
471471

472472
// I is the original vector

0 commit comments

Comments
 (0)