From ae9da3786a3ea2e62b1ece7e28628c2dbadf0605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 15 May 2017 16:08:58 +0200 Subject: [PATCH] Gawain: Add assert for maximum attribute name. --- intern/gawain/gawain/vertex_format.h | 1 + intern/gawain/src/vertex_format.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/intern/gawain/gawain/vertex_format.h b/intern/gawain/gawain/vertex_format.h index fd210852dce..f5749a366cf 100644 --- a/intern/gawain/gawain/vertex_format.h +++ b/intern/gawain/gawain/vertex_format.h @@ -61,6 +61,7 @@ typedef struct { typedef struct { unsigned attrib_ct; // 0 to 16 (MAX_VERTEX_ATTRIBS) + unsigned name_ct; // total count of active vertex attrib unsigned stride; // stride in bytes, 1 to 256 bool packed; Attrib attribs[MAX_VERTEX_ATTRIBS]; // TODO: variable-size attribs array diff --git a/intern/gawain/src/vertex_format.c b/intern/gawain/src/vertex_format.c index 35c4054ee4b..d103d7a98a6 100644 --- a/intern/gawain/src/vertex_format.c +++ b/intern/gawain/src/vertex_format.c @@ -141,6 +141,7 @@ static const char* copy_attrib_name(VertexFormat* format, const char* name) unsigned VertexFormat_add_attrib(VertexFormat* format, const char* name, VertexCompType comp_type, unsigned comp_ct, VertexFetchMode fetch_mode) { #if TRUST_NO_ONE + assert(format->name_ct < MAX_VERTEX_ATTRIBS); // there's room for more assert(format->attrib_ct < MAX_VERTEX_ATTRIBS); // there's room for more assert(!format->packed); // packed means frozen/locked assert(comp_ct >= 1 && comp_ct <= 4); @@ -163,6 +164,7 @@ unsigned VertexFormat_add_attrib(VertexFormat* format, const char* name, VertexC assert(fetch_mode != KEEP_FLOAT); } #endif + format->name_ct++; // multiname support const unsigned attrib_id = format->attrib_ct++; Attrib* attrib = format->attribs + attrib_id; @@ -186,8 +188,10 @@ void VertexFormat_add_alias(VertexFormat* format, const char* alias) { Attrib* attrib = format->attribs + (format->attrib_ct - 1); #if TRUST_NO_ONE + assert(format->name_ct < MAX_VERTEX_ATTRIBS); // there's room for more assert(attrib->name_ct < MAX_ATTRIB_NAMES); #endif + format->name_ct++; // multiname support attrib->name[attrib->name_ct++] = copy_attrib_name(format, alias); }