Fix several pointer access errors
parent
69ee7700b4
commit
aeb21bb438
|
@ -1,5 +1,6 @@
|
|||
bin
|
||||
doc
|
||||
ir
|
||||
src_crap
|
||||
data/codedefs
|
||||
data/fonts
|
||||
|
|
4
Makefile
4
Makefile
|
@ -7,7 +7,9 @@ SRC=src
|
|||
INC=inc
|
||||
CODEDEFS=data/codedefs
|
||||
BIN=bin
|
||||
IR=bin/ir
|
||||
IR=ir
|
||||
|
||||
CFLAGS += -O2 -g
|
||||
|
||||
GDCC_TARGET=--bc-target=Doominati
|
||||
GDCC_LFLAGS += $(GDCC_TARGET)
|
||||
|
|
|
@ -337,7 +337,7 @@ static M_texid G_ObjDef_getFrameSprite(char const *fmt, char frame, int i)
|
|||
if(!bufV) return 0;
|
||||
|
||||
M_texid id = DGE_Texture_Get(DGE_String_Create(bufV, bufC));
|
||||
free(bufV);
|
||||
M_Vec_clear(buf);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,4 +22,7 @@
|
|||
|
||||
#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
|
||||
|
|
|
@ -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 ----------------------------------------------------------|
|
||||
|
||||
//
|
||||
|
@ -35,32 +47,36 @@ void M_TokBuf_Ctor(M_tkbuf *tb)
|
|||
//
|
||||
void M_TokBuf_Dtor(M_tkbuf *tb)
|
||||
{
|
||||
/* TODO
|
||||
if(tb->toks)
|
||||
for(int i = 0; i < tb->bend; i++)
|
||||
free(tb->toks[i].textV);
|
||||
M_Vec_clear(tb->toks[i].text);
|
||||
|
||||
free(tb->toks);
|
||||
*/
|
||||
}
|
||||
|
||||
//
|
||||
// M_TokBuf_Get
|
||||
//
|
||||
[[__optional_args(1)]]
|
||||
M_token *M_TokBuf_Get(M_tkbuf *tb)
|
||||
{
|
||||
if(++tb->tpos < tb->tend)
|
||||
return &tb->toks[tb->tpos];
|
||||
|
||||
/* TODO
|
||||
for(int i = 0; i < tb->tend - tb->bbeg; i++)
|
||||
free(tb->toks[i].textV);
|
||||
*/
|
||||
// Free beginning of buffer.
|
||||
for(int i = 0; i < tb->bbeg; i++) {
|
||||
M_Vec_clear(tb->toks[i].text);
|
||||
tb->toks[i] = (M_token){0};
|
||||
}
|
||||
|
||||
memmove(&tb->toks[0], &tb->toks[tb->tend - tb->bbeg],
|
||||
sizeof(M_token) * tb->bbeg);
|
||||
// Move end of buffer to beginning.
|
||||
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++)
|
||||
{
|
||||
skip:
|
||||
|
@ -74,11 +90,6 @@ M_token *M_TokBuf_Get(M_tkbuf *tb)
|
|||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
|
@ -103,12 +114,10 @@ M_token *M_TokBuf_ReGet(M_tkbuf *tb)
|
|||
//
|
||||
bool M_TokBuf_Drop(M_tkbuf *tb, M_tokty t)
|
||||
{
|
||||
if(M_TokBuf_Get(tb)->type != t) {
|
||||
M_TokBuf_UnGet(tb);
|
||||
return false;
|
||||
} else {
|
||||
if(M_TokBuf_Get(tb)->type != t)
|
||||
{M_TokBuf_UnGet(tb); return false;}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
// Extern Functions ----------------------------------------------------------|
|
||||
|
||||
struct M_tkbuf;
|
||||
void M_TokBuf_Ctor(struct M_tkbuf *tb);
|
||||
void M_TokBuf_Dtor(struct M_tkbuf *tb);
|
||||
M_token *M_TokBuf_Get(struct M_tkbuf *tb);
|
||||
|
|
|
@ -28,11 +28,7 @@ void M_Tk_Parse(FILE *fp, M_token *tok)
|
|||
{
|
||||
if(!tok) return;
|
||||
|
||||
if(tok->textV) {
|
||||
free(tok->textV);
|
||||
tok->textV = NULL;
|
||||
tok->textC = tok->textS = 0;
|
||||
}
|
||||
M_Vec_clear(tok->text);
|
||||
|
||||
if(!fp || feof(fp)) {
|
||||
tok->type = tok_eof;
|
||||
|
|
|
@ -26,12 +26,16 @@ typedef uint8_t mbyte; // Machine Byte
|
|||
typedef uint16_t hword; // Half Word
|
||||
typedef uint32_t mword; // Machine Word
|
||||
typedef uint64_t dword; // Double Word
|
||||
#if __GDCC__
|
||||
typedef uint96_t tword; // Triple Word
|
||||
#endif
|
||||
typedef int8_t chara; // Character
|
||||
typedef int16_t int16; // Integer (16 bits)
|
||||
typedef int32_t integ; // Integer (Machine)
|
||||
typedef int64_t int64; // Integer (64 bits)
|
||||
#if __GDCC__
|
||||
typedef int96_t int96; // Integer (96 bits)
|
||||
#endif
|
||||
typedef unsigned M_texid; // Texture ID
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue