Fix several pointer access errors

master
Marrub 2017-09-22 11:37:31 -04:00
parent 69ee7700b4
commit aeb21bb438
8 changed files with 43 additions and 27 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
bin bin
doc doc
ir
src_crap src_crap
data/codedefs data/codedefs
data/fonts data/fonts

View File

@ -7,7 +7,9 @@ SRC=src
INC=inc INC=inc
CODEDEFS=data/codedefs CODEDEFS=data/codedefs
BIN=bin BIN=bin
IR=bin/ir IR=ir
CFLAGS += -O2 -g
GDCC_TARGET=--bc-target=Doominati GDCC_TARGET=--bc-target=Doominati
GDCC_LFLAGS += $(GDCC_TARGET) GDCC_LFLAGS += $(GDCC_TARGET)

View File

@ -337,7 +337,7 @@ static M_texid G_ObjDef_getFrameSprite(char const *fmt, char frame, int i)
if(!bufV) return 0; if(!bufV) return 0;
M_texid id = DGE_Texture_Get(DGE_String_Create(bufV, bufC)); M_texid id = DGE_Texture_Get(DGE_String_Create(bufV, bufC));
free(bufV); M_Vec_clear(buf);
return id; return id;
} }

View File

@ -22,4 +22,7 @@
#define M_Vec_next(vec) ((vec##V)[(vec##C)++]) #define M_Vec_next(vec) ((vec##V)[(vec##C)++])
#define M_Vec_clear(vec) \
(free((vec##V)), (vec##V) = NULL, (vec##C) = (vec##S) = 0)
#endif #endif

View File

@ -19,6 +19,18 @@ static enum M_tkprc M_TokBuf_tokProcess(M_token *tok, void *udata)
} }
} }
//
// M_TokBuf_print
//
static void M_TokBuf_print(M_tkbuf *tb)
{
for(int i = 0; i < tb->tend; i++)
printf("[%i]%i: %p %s%s\n", i, tb->toks[i].type, tb->toks[i].textV,
tb->toks[i].textV, i == tb->tpos ? " <-- cursor is here" : "");
printf("---\n");
}
// Extern Functions ----------------------------------------------------------| // Extern Functions ----------------------------------------------------------|
// //
@ -35,32 +47,36 @@ void M_TokBuf_Ctor(M_tkbuf *tb)
// //
void M_TokBuf_Dtor(M_tkbuf *tb) void M_TokBuf_Dtor(M_tkbuf *tb)
{ {
/* TODO
if(tb->toks) if(tb->toks)
for(int i = 0; i < tb->bend; i++) for(int i = 0; i < tb->bend; i++)
free(tb->toks[i].textV); M_Vec_clear(tb->toks[i].text);
free(tb->toks); free(tb->toks);
*/
} }
// //
// M_TokBuf_Get // M_TokBuf_Get
// //
[[__optional_args(1)]]
M_token *M_TokBuf_Get(M_tkbuf *tb) M_token *M_TokBuf_Get(M_tkbuf *tb)
{ {
if(++tb->tpos < tb->tend) if(++tb->tpos < tb->tend)
return &tb->toks[tb->tpos]; return &tb->toks[tb->tpos];
/* TODO // Free beginning of buffer.
for(int i = 0; i < tb->tend - tb->bbeg; i++) for(int i = 0; i < tb->bbeg; i++) {
free(tb->toks[i].textV); M_Vec_clear(tb->toks[i].text);
*/ tb->toks[i] = (M_token){0};
}
memmove(&tb->toks[0], &tb->toks[tb->tend - tb->bbeg], // Move end of buffer to beginning.
sizeof(M_token) * tb->bbeg); if(tb->tend)
for(int i = tb->tend - tb->bbeg, j = 0; i < tb->tend; i++, j++)
{
tb->toks[j] = tb->toks[i];
tb->toks[i] = (M_token){0};
}
// Get new tokens.
for(tb->tpos = tb->tend = tb->bbeg; tb->tend < tb->bend; tb->tend++) for(tb->tpos = tb->tend = tb->bbeg; tb->tend < tb->bend; tb->tend++)
{ {
skip: skip:
@ -74,11 +90,6 @@ M_token *M_TokBuf_Get(M_tkbuf *tb)
} }
done: done:
/*
for(int i = 0; i < tb->tend; i++)
printf("%i: %s%s\n", tb->toks[i].type, tb->toks[i].text, i == tb->tpos ? " <-- cursor is here" : "");
*/
return &tb->toks[tb->tpos]; return &tb->toks[tb->tpos];
} }
@ -103,12 +114,10 @@ M_token *M_TokBuf_ReGet(M_tkbuf *tb)
// //
bool M_TokBuf_Drop(M_tkbuf *tb, M_tokty t) bool M_TokBuf_Drop(M_tkbuf *tb, M_tokty t)
{ {
if(M_TokBuf_Get(tb)->type != t) { if(M_TokBuf_Get(tb)->type != t)
M_TokBuf_UnGet(tb); {M_TokBuf_UnGet(tb); return false;}
return false; else
} else {
return true; return true;
}
} }
// EOF // EOF

View File

@ -6,6 +6,7 @@
// Extern Functions ----------------------------------------------------------| // Extern Functions ----------------------------------------------------------|
struct M_tkbuf;
void M_TokBuf_Ctor(struct M_tkbuf *tb); void M_TokBuf_Ctor(struct M_tkbuf *tb);
void M_TokBuf_Dtor(struct M_tkbuf *tb); void M_TokBuf_Dtor(struct M_tkbuf *tb);
M_token *M_TokBuf_Get(struct M_tkbuf *tb); M_token *M_TokBuf_Get(struct M_tkbuf *tb);

View File

@ -28,11 +28,7 @@ void M_Tk_Parse(FILE *fp, M_token *tok)
{ {
if(!tok) return; if(!tok) return;
if(tok->textV) { M_Vec_clear(tok->text);
free(tok->textV);
tok->textV = NULL;
tok->textC = tok->textS = 0;
}
if(!fp || feof(fp)) { if(!fp || feof(fp)) {
tok->type = tok_eof; tok->type = tok_eof;

View File

@ -26,12 +26,16 @@ typedef uint8_t mbyte; // Machine Byte
typedef uint16_t hword; // Half Word typedef uint16_t hword; // Half Word
typedef uint32_t mword; // Machine Word typedef uint32_t mword; // Machine Word
typedef uint64_t dword; // Double Word typedef uint64_t dword; // Double Word
#if __GDCC__
typedef uint96_t tword; // Triple Word typedef uint96_t tword; // Triple Word
#endif
typedef int8_t chara; // Character typedef int8_t chara; // Character
typedef int16_t int16; // Integer (16 bits) typedef int16_t int16; // Integer (16 bits)
typedef int32_t integ; // Integer (Machine) typedef int32_t integ; // Integer (Machine)
typedef int64_t int64; // Integer (64 bits) typedef int64_t int64; // Integer (64 bits)
#if __GDCC__
typedef int96_t int96; // Integer (96 bits) typedef int96_t int96; // Integer (96 bits)
#endif
typedef unsigned M_texid; // Texture ID typedef unsigned M_texid; // Texture ID
#endif #endif