Gawain: Add assert for maximum attribute name.

This commit is contained in:
Clément Foucault 2017-05-15 16:08:58 +02:00
parent 1ff97bbfff
commit ae9da3786a
2 changed files with 5 additions and 0 deletions

View File

@ -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

View File

@ -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);
}