Possible memalloc corruption mititagions.
This commit is contained in:
parent
9e8c779c74
commit
142e6c9cf3
8 changed files with 69 additions and 19 deletions
|
@ -17,6 +17,7 @@
|
|||
void
|
||||
CSQC_Init(float apilevel, string enginename, float engineversion)
|
||||
{
|
||||
Sound_Init();
|
||||
pSeat = &g_seats[0];
|
||||
|
||||
registercommand("dev_sentence");
|
||||
|
|
|
@ -40,7 +40,8 @@ typedef struct
|
|||
sentences_t *g_sentences;
|
||||
int g_sentences_count;
|
||||
#else
|
||||
sentences_t g_sentences[1024];
|
||||
#define SENTENCES_LIMIT 1024
|
||||
sentences_t g_sentences[SENTENCES_LIMIT];
|
||||
int g_sentences_count;
|
||||
#endif
|
||||
|
||||
|
@ -51,15 +52,19 @@ Sentences_Init(void)
|
|||
string temp;
|
||||
int c, i;
|
||||
|
||||
if (g_sentences_count > 0) {
|
||||
g_sentences_count = 0;
|
||||
#ifndef DYNAMIC_SENTENCES
|
||||
if (g_sentences) {
|
||||
memfree(g_sentences);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
fs_sentences = fopen("sound/sentences.txt", FILE_READ);
|
||||
|
||||
if (fs_sentences < 0) {
|
||||
print("^1WARNING: ^7Could NOT load sound/sentences.txt");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_sentences_count > 0) {
|
||||
print("^1WARNING: ^7Attempted to load sentences twice!");
|
||||
print("^1WARNING: ^7Could NOT load sound/sentences.txt\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,6 +88,11 @@ Sentences_Init(void)
|
|||
g_sentences_count,
|
||||
++g_sentences_count);
|
||||
#else
|
||||
if (g_sentences_count + 1 >= SENTENCES_LIMIT) {
|
||||
print("^1WARNING: ^7Reached limit of max sentences!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
g_sentences_count++;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
*/
|
||||
|
||||
var int autocvar_r_drawdecals = TRUE;
|
||||
var int autocvar_sp_decals = 4096;
|
||||
var int autocvar_mp_decals = 300;
|
||||
var int autocvar_cl_decals = 512;
|
||||
var int autocvar_sp_decals = 32;
|
||||
var int autocvar_mp_decals = 32;
|
||||
var int autocvar_cl_decals = 32;
|
||||
|
||||
#ifdef CLIENT
|
||||
const string g_decal_shader = \
|
||||
|
|
|
@ -46,7 +46,7 @@ void lg_btncancel_start(void)
|
|||
header.SetExecute(lg_btncancel_end);
|
||||
}
|
||||
|
||||
void lg_lbsaves_changed(void)
|
||||
void lg_lbsaves_changed(int val)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -112,6 +112,8 @@ void SV_ParseClientCommand(string cmd)
|
|||
void init(float prevprogs)
|
||||
{
|
||||
string sTemp;
|
||||
|
||||
Sound_Init();
|
||||
|
||||
// Let's load materials.txt because someone thought this was the best idea
|
||||
filestream fileMaterial = fopen("sound/materials.txt", FILE_READ);
|
||||
|
|
|
@ -23,8 +23,16 @@
|
|||
* we'll just default to those whenever there's no custom value set.
|
||||
*/
|
||||
|
||||
string *g_sentences;
|
||||
int g_sentences_count;
|
||||
#define DYNAMIC_SENTENCES
|
||||
|
||||
#ifdef DYNAMIC_SENTENCES
|
||||
string *g_sentences;
|
||||
int g_sentences_count;
|
||||
#else
|
||||
#define SENTENCES_LIMIT 1024
|
||||
string g_sentences[SENTENCES_LIMIT];
|
||||
int g_sentences_count;
|
||||
#endif
|
||||
|
||||
void
|
||||
Sentences_Init(void)
|
||||
|
@ -33,15 +41,19 @@ Sentences_Init(void)
|
|||
string temp;
|
||||
int c;
|
||||
|
||||
if (g_sentences_count > 0) {
|
||||
g_sentences_count = 0;
|
||||
#ifndef DYNAMIC_SENTENCES
|
||||
if (g_sentences) {
|
||||
memfree(g_sentences);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
fs_sentences = fopen("sound/sentences.txt", FILE_READ);
|
||||
|
||||
if (fs_sentences < 0) {
|
||||
print("^1WARNING: ^7Could NOT load sound/sentences.txt");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_sentences_count > 0) {
|
||||
print("^1WARNING: ^7Attempted to load sentences twice!");
|
||||
print("^1WARNING: ^7Could NOT load sound/sentences.txt\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -59,10 +71,19 @@ Sentences_Init(void)
|
|||
int x = g_sentences_count;
|
||||
|
||||
/* allocate memory and increase count */
|
||||
#ifdef DYNAMIC_SENTENCES
|
||||
g_sentences = memrealloc(g_sentences,
|
||||
sizeof(string),
|
||||
g_sentences_count,
|
||||
++g_sentences_count);
|
||||
#else
|
||||
if (g_sentences_count + 1 >= SENTENCES_LIMIT) {
|
||||
print("^1WARNING: ^7Reached limit of max sentences!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
g_sentences_count++;
|
||||
#endif
|
||||
|
||||
g_sentences[x] = strcat("!", argv(0));
|
||||
}
|
||||
|
|
|
@ -62,6 +62,11 @@ void* memrealloc(__variant *oldptr, int elementsize, int oldelements, int newele
|
|||
return n;
|
||||
}
|
||||
|
||||
__wrap __variant* memalloc(int size)
|
||||
{
|
||||
return prior(size);
|
||||
}
|
||||
|
||||
void Empty(void)
|
||||
{
|
||||
|
||||
|
|
|
@ -54,6 +54,17 @@ typedef struct
|
|||
snd_t *g_sounds;
|
||||
static int g_sounds_count;
|
||||
|
||||
/* make sure it's all reset */
|
||||
void Sound_Init(void)
|
||||
{
|
||||
if (g_sounds) {
|
||||
memfree(g_sounds);
|
||||
}
|
||||
|
||||
g_sounds_count = 0;
|
||||
g_hashsounds = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Sound_ParseField(int i, int a)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue