Skip to content

Commit

Permalink
Merged pull request "Sync with Q2PRO: Assertive things": #379
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Mar 18, 2024
2 parents c40863b + 12ae28e commit f0eae8d
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/client/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ void CL_SetLightStyle(int index, const char *s)

ls = &cl_lightstyles[index];
ls->length = strlen(s);
if (ls->length > MAX_QPATH) {
Com_Error(ERR_DROP, "%s: oversize style", __func__);
}
Q_assert(ls->length < MAX_QPATH);

for (i = 0; i < ls->length; i++)
ls->map[i] = (float)(s[i] - 'a') / (float)('m' - 'a');
Expand Down
5 changes: 1 addition & 4 deletions src/client/entities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,10 +1368,7 @@ void CL_GetEntitySoundOrigin(int entnum, vec3_t org)
mmodel_t *cm;
vec3_t mid;

if (entnum < 0 || entnum >= MAX_EDICTS) {
Com_Error(ERR_DROP, "%s: bad entnum: %d", __func__, entnum);
}

Q_assert(entnum >= 0 && entnum < MAX_EDICTS);
if (!entnum || entnum == listener_entnum) {
// should this ever happen?
VectorCopy(listener_origin, org);
Expand Down
6 changes: 1 addition & 5 deletions src/client/precache.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ void CL_ParsePlayerSkin(char *name, char *model, char *skin, const char *s)
size_t len;
char *t;

// configstring parsing guarantees that playerskins can never
// overflow, but still check the length to be entirely fool-proof
len = strlen(s);
if (len >= MAX_QPATH) {
Com_Error(ERR_DROP, "%s: oversize playerskin", __func__);
}
Q_assert(len < MAX_QPATH);

// isolate the player's name
t = strchr(s, '\\');
Expand Down
4 changes: 1 addition & 3 deletions src/client/sound/al.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ static void AL_StreamStop(void)
{
qalSourceStop(s_stream);
AL_StreamUpdate();

if (s_stream_buffers)
Com_Error(ERR_FATAL, "Unbalanced number of AL buffers");
Q_assert(!s_stream_buffers);
}

static bool AL_RawSamples(int samples, int rate, int width, int channels, const byte *data, float volume)
Expand Down
7 changes: 3 additions & 4 deletions src/client/sound/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ sfx_t *S_SfxForHandle(qhandle_t hSfx)
return NULL;
}

if (hSfx < 1 || hSfx > num_sfx) {
Com_Error(ERR_DROP, "S_SfxForHandle: %d out of range", hSfx);
}

Q_assert(hSfx > 0 && hSfx <= num_sfx);
return &known_sfx[hSfx - 1];
}

Expand Down Expand Up @@ -374,6 +371,8 @@ qhandle_t S_RegisterSound(const char *name)
if (!s_started)
return 0;

Q_assert(name);

// empty names are legal, silently ignore them
if (!*name)
return 0;
Expand Down
3 changes: 1 addition & 2 deletions src/client/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ void V_AddLightStyle(int style, float value)
{
lightstyle_t *ls;

if (style < 0 || style >= MAX_LIGHTSTYLES)
Com_Error(ERR_DROP, "Bad light style %i", style);
Q_assert(style >= 0 && style < MAX_LIGHTSTYLES);
ls = &r_lightstyles[style];
ls->white = value;
}
Expand Down
3 changes: 1 addition & 2 deletions src/common/cmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,7 @@ byte *CM_FatPVS(cm_t *cm, byte *mask, const vec3_t org, int vis)
}

count = CM_BoxLeafs(cm, mins, maxs, leafs, q_countof(leafs), NULL);
if (count < 1)
Com_Error(ERR_DROP, "CM_FatPVS: leaf count < 1");
Q_assert(count > 0);

// convert leafs to clusters
for (i = 0; i < count; i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/refresh/images.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,8 @@ static image_t *find_or_load_image(const char *name, size_t len,
unsigned hash;
int ret = Q_ERR(ENOENT);

Q_assert(len < MAX_QPATH);

// must have an extension and at least 1 char of base name
if (len <= 4) {
ret = Q_ERR_NAMETOOSHORT;
Expand Down Expand Up @@ -1527,14 +1529,10 @@ static image_t *find_or_load_image(const char *name, size_t len,
image_t *IMG_Find(const char *name, imagetype_t type, imageflags_t flags)
{
image_t *image;
size_t len;

Q_assert(name);

len = strlen(name);
Q_assert(len < MAX_QPATH);

if ((image = find_or_load_image(name, len, type, flags))) {
if ((image = find_or_load_image(name, strlen(name), type, flags))) {
return image;
}
return R_NOTEXTURE;
Expand Down Expand Up @@ -1642,6 +1640,8 @@ qhandle_t R_RegisterImage(const char *name, imagetype_t type, imageflags_t flags
char fullname[MAX_QPATH];
size_t len;

Q_assert(name);

// empty names are legal, silently ignore them
if (!*name) {
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/refresh/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ qhandle_t R_RegisterModel(const char *name)
mod_load_t load;
int ret;

Q_assert(name);

// empty names are legal, silently ignore them
if (!*name)
return 0;
Expand Down

0 comments on commit f0eae8d

Please sign in to comment.