qbsp: bounds check some array accesses

This commit is contained in:
Eric Wasylishen 2016-11-02 16:52:12 -06:00
parent 05447ee0b9
commit e5f5b99584
8 changed files with 16 additions and 17 deletions

View File

@ -762,7 +762,7 @@ Brush_GetContents(const mapbrush_t *mapbrush)
const char *texname;
const mapface_t &mapface = mapbrush->face(0);
const mtexinfo_t &texinfo = map.mtexinfos.at(mapface.texinfo);
texname = map.miptex[texinfo.miptex].c_str();
texname = map.miptex.at(texinfo.miptex).c_str();
if (!Q_strcasecmp(texname, "hint") || !Q_strcasecmp(texname, "hintskip"))
return CONTENTS_HINT;

View File

@ -139,7 +139,7 @@ AddLump(FILE *f, int Type)
lump->fileofs = ftell(f);
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities[i];
entity = &map.entities.at(i);
entities = &entity->lumps[Type];
if (entities->data) {
if (Type == LUMP_MODELS && !options.hexen2) {
@ -200,7 +200,7 @@ GenLump(const char *bspxlump, int Type, size_t sz)
char *out;
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities[i];
entity = &map.entities.at(i);
entities = &entity->lumps[Type];
cLen += entities->count*sz;
}
@ -209,7 +209,7 @@ GenLump(const char *bspxlump, int Type, size_t sz)
out = (char *)malloc(cLen);
cLen = 0;
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities[i];
entity = &map.entities.at(i);
entities = &entity->lumps[Type];
memcpy(out+cLen, entities->data, entities->count*sz);
cLen += entities->count*sz;

View File

@ -46,7 +46,7 @@ static void
ExportObjFace(FILE *f, const face_t *face, int *vertcount)
{
const mtexinfo_t &texinfo = map.mtexinfos.at(face->texinfo);
const char *texname = map.miptex[texinfo.miptex].c_str();
const char *texname = map.miptex.at(texinfo.miptex).c_str();
const texture_t *texture = WADList_GetTexture(texname);
const int width = texture ? texture->width : 64;

View File

@ -76,7 +76,7 @@ AddAnimTex(const char *name)
for (i = 0; i < frame; i++) {
framename[1] = basechar + i;
for (j = 0; j < map.nummiptex(); j++) {
if (!Q_strcasecmp(framename, map.miptex[j].c_str()))
if (!Q_strcasecmp(framename, map.miptex.at(j).c_str()))
break;
}
if (j < map.nummiptex())
@ -98,7 +98,7 @@ FindMiptex(const char *name)
name = pathsep + 1;
for (i = 0; i < map.nummiptex(); i++) {
if (!Q_strcasecmp(name, map.miptex[i].c_str()))
if (!Q_strcasecmp(name, map.miptex.at(i).c_str()))
return i;
}
@ -198,7 +198,7 @@ int
FindTexinfoEnt(mtexinfo_t *texinfo, const mapentity_t *entity)
{
uint64_t flags = 0;
const char *texname = map.miptex[texinfo->miptex].c_str();
const char *texname = map.miptex.at(texinfo->miptex).c_str();
if (IsSkipName(texname))
flags |= TEX_SKIP;
if (IsHintName(texname))

View File

@ -364,7 +364,7 @@ FindLeaks_r(leakstate_t *leak, const int fillmark, node_t *node)
return false;
if (node->occupied) {
leak->entity = &map.entities[node->occupied];
leak->entity = &map.entities.at(node->occupied);
leak->node = node;
leak->backdraw = 4000;
return true;

View File

@ -598,7 +598,7 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode)
cStartEdge = 0;
const int entnum = entity - &map.entities.at(0);
for (i = 0; i < entnum; i++)
cStartEdge += map.entities[i].lumps[LUMP_EDGES].count;
cStartEdge += map.entities.at(i).lumps[LUMP_EDGES].count;
CountData_r(entity, headnode);

View File

@ -190,7 +190,7 @@ WADList_Process(const wad_t *wadlist)
/* Count texture size. Slower, but saves memory. */
for (i = 0; i < map.nummiptex(); i++) {
texture = WADList_FindTexture(wadlist, map.miptex[i].c_str());
texture = WADList_FindTexture(wadlist, map.miptex.at(i).c_str());
if (texture) {
if (options.fNoTextures)
texdata->count += sizeof(dmiptex_t);
@ -210,7 +210,7 @@ WADList_Process(const wad_t *wadlist)
for (i = 0; i < map.nummiptex(); i++) {
if (miptexlump->dataofs[i] == 0) {
miptexlump->dataofs[i] = -1;
Message(msgWarning, warnTextureNotFound, map.miptex[i].c_str());
Message(msgWarning, warnTextureNotFound, map.miptex.at(i).c_str());
}
}
}
@ -230,7 +230,7 @@ WADList_LoadTextures(const wad_t *wadlist, dmiptexlump_t *lump)
continue;
size = 0;
for (wad = wadlist; wad; wad = wad->next) {
size = WAD_LoadLump(wad, map.miptex[i].c_str(), data);
size = WAD_LoadLump(wad, map.miptex.at(i).c_str(), data);
if (size)
break;
}
@ -276,14 +276,13 @@ static void
WADList_AddAnimationFrames(const wad_t *wadlist)
{
int oldcount, i, j;
miptex_t name;
oldcount = map.nummiptex();
for (i = 0; i < oldcount; i++) {
if (map.miptex[i][0] != '+')
if (map.miptex.at(i)[0] != '+')
continue;
name = map.miptex[i];
std::string name = map.miptex.at(i);
/* Search for all animations (0-9) and alt-animations (A-J) */
for (j = 0; j < 20; j++) {

View File

@ -224,7 +224,7 @@ ExportClipNodes(mapentity_t *entity, node_t *nodes, const int hullnum)
/* Count nodes before this one */
const int entnum = entity - &map.entities.at(0);
for (i = 0; i < entnum; i++)
clipcount += map.entities[i].lumps[LUMP_CLIPNODES].count;
clipcount += map.entities.at(i).lumps[LUMP_CLIPNODES].count;
model->headnode[hullnum] = clipcount + oldcount;
CountClipNodes_r(entity, nodes);