make AAS_LoadAASFile work with zero-sized lumps
AAS_LoadAASLump will return 0/NULL in an error case. However it will also return the input buffer pointer if length is 0, and the input buffer pointer may be 0/NULL in the case where AAS_LoadAASLump is meant to allocate memory. This means that it can return 0/NULL in a perfectly legal case where the lump length is 0. Since AAS_LoadAASFile inteprets this as a fatal error, that's bad. I'm not sure how to best disambiguate this, but a low-touch fix is for the caller of AAS_LoadAASLump to be OK with a returned NULL pointer if the lump length is 0. Also: added a missing break statement to avoid a spurious "don't know what to do" message when using the aasinfo switch.
This commit is contained in:
parent
4443f667cf
commit
e8522ae2c9
|
|
@ -299,55 +299,55 @@ qboolean AAS_LoadAASFile(char *filename, int fpoffset, int fplength)
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_BBOXES].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_BBOXES].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_BBOXES].filelen);
|
length = LittleLong(header.lumps[AASLUMP_BBOXES].filelen);
|
||||||
aasworld.bboxes = (aas_bbox_t *) AAS_LoadAASLump(fp, offset, length, aasworld.bboxes);
|
aasworld.bboxes = (aas_bbox_t *) AAS_LoadAASLump(fp, offset, length, aasworld.bboxes);
|
||||||
if (!aasworld.bboxes) return false;
|
if (length && !aasworld.bboxes) return false;
|
||||||
aasworld.numbboxes = length / sizeof(aas_bbox_t);
|
aasworld.numbboxes = length / sizeof(aas_bbox_t);
|
||||||
//vertexes
|
//vertexes
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_VERTEXES].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_VERTEXES].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_VERTEXES].filelen);
|
length = LittleLong(header.lumps[AASLUMP_VERTEXES].filelen);
|
||||||
aasworld.vertexes = (aas_vertex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.vertexes);
|
aasworld.vertexes = (aas_vertex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.vertexes);
|
||||||
if (!aasworld.vertexes) return false;
|
if (length & !aasworld.vertexes) return false;
|
||||||
aasworld.numvertexes = length / sizeof(aas_vertex_t);
|
aasworld.numvertexes = length / sizeof(aas_vertex_t);
|
||||||
//planes
|
//planes
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_PLANES].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_PLANES].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_PLANES].filelen);
|
length = LittleLong(header.lumps[AASLUMP_PLANES].filelen);
|
||||||
aasworld.planes = (aas_plane_t *) AAS_LoadAASLump(fp, offset, length, aasworld.planes);
|
aasworld.planes = (aas_plane_t *) AAS_LoadAASLump(fp, offset, length, aasworld.planes);
|
||||||
if (!aasworld.planes) return false;
|
if (length && !aasworld.planes) return false;
|
||||||
aasworld.numplanes = length / sizeof(aas_plane_t);
|
aasworld.numplanes = length / sizeof(aas_plane_t);
|
||||||
//edges
|
//edges
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_EDGES].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_EDGES].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_EDGES].filelen);
|
length = LittleLong(header.lumps[AASLUMP_EDGES].filelen);
|
||||||
aasworld.edges = (aas_edge_t *) AAS_LoadAASLump(fp, offset, length, aasworld.edges);
|
aasworld.edges = (aas_edge_t *) AAS_LoadAASLump(fp, offset, length, aasworld.edges);
|
||||||
if (!aasworld.edges) return false;
|
if (length && !aasworld.edges) return false;
|
||||||
aasworld.numedges = length / sizeof(aas_edge_t);
|
aasworld.numedges = length / sizeof(aas_edge_t);
|
||||||
//edgeindex
|
//edgeindex
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_EDGEINDEX].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_EDGEINDEX].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_EDGEINDEX].filelen);
|
length = LittleLong(header.lumps[AASLUMP_EDGEINDEX].filelen);
|
||||||
aasworld.edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.edgeindex);
|
aasworld.edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.edgeindex);
|
||||||
if (!aasworld.edgeindex) return false;
|
if (length && !aasworld.edgeindex) return false;
|
||||||
aasworld.edgeindexsize = length / sizeof(aas_edgeindex_t);
|
aasworld.edgeindexsize = length / sizeof(aas_edgeindex_t);
|
||||||
//faces
|
//faces
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_FACES].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_FACES].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_FACES].filelen);
|
length = LittleLong(header.lumps[AASLUMP_FACES].filelen);
|
||||||
aasworld.faces = (aas_face_t *) AAS_LoadAASLump(fp, offset, length, aasworld.faces);
|
aasworld.faces = (aas_face_t *) AAS_LoadAASLump(fp, offset, length, aasworld.faces);
|
||||||
if (!aasworld.faces) return false;
|
if (length && !aasworld.faces) return false;
|
||||||
aasworld.numfaces = length / sizeof(aas_face_t);
|
aasworld.numfaces = length / sizeof(aas_face_t);
|
||||||
//faceindex
|
//faceindex
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_FACEINDEX].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_FACEINDEX].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_FACEINDEX].filelen);
|
length = LittleLong(header.lumps[AASLUMP_FACEINDEX].filelen);
|
||||||
aasworld.faceindex = (aas_faceindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.faceindex);
|
aasworld.faceindex = (aas_faceindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.faceindex);
|
||||||
if (!aasworld.faceindex) return false;
|
if (length && !aasworld.faceindex) return false;
|
||||||
aasworld.faceindexsize = length / sizeof(int);
|
aasworld.faceindexsize = length / sizeof(int);
|
||||||
//convex areas
|
//convex areas
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_AREAS].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_AREAS].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_AREAS].filelen);
|
length = LittleLong(header.lumps[AASLUMP_AREAS].filelen);
|
||||||
aasworld.areas = (aas_area_t *) AAS_LoadAASLump(fp, offset, length, aasworld.areas);
|
aasworld.areas = (aas_area_t *) AAS_LoadAASLump(fp, offset, length, aasworld.areas);
|
||||||
if (!aasworld.areas) return false;
|
if (length && !aasworld.areas) return false;
|
||||||
aasworld.numareas = length / sizeof(aas_area_t);
|
aasworld.numareas = length / sizeof(aas_area_t);
|
||||||
//area settings
|
//area settings
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_AREASETTINGS].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_AREASETTINGS].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_AREASETTINGS].filelen);
|
length = LittleLong(header.lumps[AASLUMP_AREASETTINGS].filelen);
|
||||||
aasworld.areasettings = (aas_areasettings_t *) AAS_LoadAASLump(fp, offset, length, aasworld.areasettings);
|
aasworld.areasettings = (aas_areasettings_t *) AAS_LoadAASLump(fp, offset, length, aasworld.areasettings);
|
||||||
if (!aasworld.areasettings) return false;
|
if (length && !aasworld.areasettings) return false;
|
||||||
aasworld.numareasettings = length / sizeof(aas_areasettings_t);
|
aasworld.numareasettings = length / sizeof(aas_areasettings_t);
|
||||||
//reachability list
|
//reachability list
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_REACHABILITY].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_REACHABILITY].fileofs);
|
||||||
|
|
@ -359,7 +359,7 @@ qboolean AAS_LoadAASFile(char *filename, int fpoffset, int fplength)
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_NODES].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_NODES].fileofs);
|
||||||
length = LittleLong(header.lumps[AASLUMP_NODES].filelen);
|
length = LittleLong(header.lumps[AASLUMP_NODES].filelen);
|
||||||
aasworld.nodes = (aas_node_t *) AAS_LoadAASLump(fp, offset, length, aasworld.nodes);
|
aasworld.nodes = (aas_node_t *) AAS_LoadAASLump(fp, offset, length, aasworld.nodes);
|
||||||
if (!aasworld.nodes) return false;
|
if (length && !aasworld.nodes) return false;
|
||||||
aasworld.numnodes = length / sizeof(aas_node_t);
|
aasworld.numnodes = length / sizeof(aas_node_t);
|
||||||
//cluster portals
|
//cluster portals
|
||||||
offset = fpoffset + LittleLong(header.lumps[AASLUMP_PORTALS].fileofs);
|
offset = fpoffset + LittleLong(header.lumps[AASLUMP_PORTALS].fileofs);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user