diff options
| author | frithrah <[email protected]> | 2020-06-05 18:13:31 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-06-05 19:13:31 +0200 |
| commit | e07512e213a498a2987cf2347997d17a46433956 (patch) | |
| tree | db14b1d549a44018d17c802f68d6f6e0450d6e09 /src/models.c | |
| parent | 00af1c0607d8daa3db67e640759a3fee74eb38d6 (diff) | |
| download | raylib-e07512e213a498a2987cf2347997d17a46433956.tar.gz raylib-e07512e213a498a2987cf2347997d17a46433956.zip | |
Fixed buffer overflow in GenMeshPoly (#1269)
Co-authored-by: frithrah <[email protected]>
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/models.c b/src/models.c index 22809f89..d5a67c08 100644 --- a/src/models.c +++ b/src/models.c @@ -1273,15 +1273,21 @@ Mesh GenMeshPoly(int sides, float radius) { Mesh mesh = { 0 }; mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int)); + + if (sides < 3) return mesh; + int vertexCount = sides*3; // Vertices definition Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3)); - for (int i = 0, v = 0; i < 360; i += 360/sides, v += 3) + + float d = 0.0f, dStep = 360.0f/sides; + for (int v = 0; v < vertexCount; v += 3) { vertices[v] = (Vector3){ 0.0f, 0.0f, 0.0f }; - vertices[v + 1] = (Vector3){ sinf(DEG2RAD*i)*radius, 0.0f, cosf(DEG2RAD*i)*radius }; - vertices[v + 2] = (Vector3){ sinf(DEG2RAD*(i + 360/sides))*radius, 0.0f, cosf(DEG2RAD*(i + 360/sides))*radius }; + vertices[v + 1] = (Vector3){ sinf(DEG2RAD*d)*radius, 0.0f, cosf(DEG2RAD*d)*radius }; + vertices[v + 2] = (Vector3){sinf(DEG2RAD*(d+dStep)) * radius, 0.0f, cosf(DEG2RAD * (d+dStep)) * radius }; + d += dStep; } // Normals definition |
