Skip to content

Commit

Permalink
Show a warning instead of crashing with 'String too big into StringsB…
Browse files Browse the repository at this point in the history
…uffer' when loading options.txt/fontscache.txt

Also fix makefile again
  • Loading branch information
UnknownShadow200 committed Apr 7, 2019
1 parent 303f951 commit 5495faa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 54 deletions.
94 changes: 43 additions & 51 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ COMMITSHA=$(shell git rev-parse --short HEAD)
ENAME=ClassiCube
DEL=rm
JOBS=1
CC=gcc
CFLAGS=-w -g -pipe -rdynamic
LDFLAGS=-g -rdynamic

ifndef $(PLAT)
ifeq ($(OS),Windows_NT)
Expand All @@ -13,48 +16,51 @@ ifndef $(PLAT)
endif
endif

CC_web=emcc
OEXT_web=.html
CFLAGS_web=-w -g
LDFLAGS_web=-s WASM=1 -s NO_EXIT_RUNTIME=1 -s FETCH=1 --preload-file texpacks/default.zip@texpacks/default.zip

CC_mingw=gcc
LIBS_mingw=-mwindows -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9
OEXT_mingw=.exe
CFLAGS_mingw=-w -g -pipe
ifeq ($(PLAT),web)
CC=emcc
OEXT=.html
CFLAGS=-w -g
LDFLAGS=-s WASM=1 -s NO_EXIT_RUNTIME=1 -s FETCH=1 --preload-file texpacks/default.zip@texpacks/default.zip
endif

CC_linux=gcc
LIBS_linux=-lX11 -lpthread -lGL -lm -lopenal -ldl -lcurl
CFLAGS_linux=-w -g -pipe -rdynamic
ifeq ($(PLAT),mingw)
OEXT=.exe
CFLAGS=-w -g -pipe
LDFLAGS=-g
LIBS=-mwindows -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9
endif

CC_sunos=gcc
LIBS_sunos=-lm -lsocket -lX11 -lGL -lcurl -lopenal
CFLAGS_sunos=-w -g -pipe -rdynamic
ifeq ($(PLAT),linux)
LIBS=-lX11 -lpthread -lGL -lm -lopenal -ldl -lcurl
endif

CC_darwin=gcc
LIBS_darwin=-lcurl
LDFLAGS_darwin=-framework Carbon -framework AGL -framework OpenAL -framework OpenGL
CFLAGS_darwin=-w -g -pipe -rdynamic
ifeq ($(PLAT),sunos)
LIBS=-lm -lsocket -lX11 -lGL -lcurl -lopenal
endif

BSDLIBS=-lcurl -lexecinfo -lopenal -lGL -lX11
ifeq ($(PLAT),darwin)
LIBS=-lcurl
LDFLAGS=-rdynamic -framework Carbon -framework AGL -framework OpenAL -framework OpenGL
endif

CC_freebsd=clang
LIBS_freebsd=$(BSDLIBS) -lm -lpthread
INCDIRS_freebsd=-I /usr/local/include
LDFLAGS_freebsd=-L /usr/local/lib
CFLAGS_freebsd=-w -g -pipe -rdynamic
ifeq ($(PLAT),freebsd)
CC=clang
CFLAGS=-w -g -pipe -rdynamic -I /usr/local/include
LDFLAGS=-L /usr/local/lib
LIBS=-lcurl -lexecinfo -lopenal -lGL -lX11 -lm -lpthread
endif

CC_openbsd=gcc
LIBS_openbsd=$(BSDLIBS)
INCDIRS_openbsd=-isystem /usr/X11R6/include -isystem /usr/local/include
LDFLAGS_openbsd=-L /usr/X11R6/lib -L /usr/local/lib
CFLAGS_openbsd=-w -g -pipe -rdynamic
ifeq ($(PLAT),openbsd)
CFLAGS=-w -g -pipe -rdynamic -I /usr/X11R6/include -I /usr/local/include
LDFLAGS=-L /usr/X11R6/lib -L /usr/local/lib
LIBS=-lcurl -lexecinfo -lopenal -lGL -lX11
endif

CC_netbsd=gcc
LIBS_netbsd=$(BSDLIBS)
INCDIRS_netbsd=-I /usr/X11R7/include -I /usr/pkg/include
LDFLAGS_netbsd=-L /usr/X11R7/lib -L /usr/pkg/lib
CFLAGS_netbsd=-w -g -pipe -rdynamic
ifeq ($(PLAT),netbsd)
CFLAGS=-w -g -pipe -rdynamic -I /usr/X11R7/include -I /usr/pkg/include
LDFLAGS=-L /usr/X11R7/lib -L /usr/pkg/lib
LIBS=-lcurl -lexecinfo -lopenal -lGL -lX11
endif

ifeq ($(OS),Windows_NT)
DEL=del
Expand All @@ -64,40 +70,26 @@ default: $(PLAT)

web:
$(MAKE) $(ENAME) PLAT=web -j$(JOBS)

linux:
$(MAKE) $(ENAME) PLAT=linux -j$(JOBS)

mingw:
$(MAKE) $(ENAME) PLAT=mingw -j$(JOBS)

solaris:
$(MAKE) $(ENAME) PLAT=sunos -j$(JOBS)

osx:
$(MAKE) $(ENAME) PLAT=darwin -j$(JOBS)

freebsd:
$(MAKE) $(ENAME) PLAT=freebsd -j$(JOBS)

openbsd:
$(MAKE) $(ENAME) PLAT=openbsd -j$(JOBS)

netbsd:
$(MAKE) $(ENAME) PLAT=netbsd -j$(JOBS)

clean:
$(DEL) $(OBJECTS)

CC=$(CC_$(PLAT))
LIBS=$(LIBS_$(PLAT))
OEXT=$(OEXT_$(PLAT))
CFLAGS=$(CFLAGS_$(PLAT))
LDFLAGS=$(LDFLAGS_$(PLAT))
INCDIRS=$(INCDIRS_$(PLAT))

$(ENAME): $(OBJECTS)
$(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(LIBS)

$(OBJECTS): %.o : %.c
$(CC) $(CFLAGS) $(INCDIRS) -DCC_COMMIT_SHA=\"$(COMMITSHA)\" -c $< -o $@
$(CC) $(CFLAGS) -DCC_COMMIT_SHA=\"$(COMMITSHA)\" -c $< -o $@
4 changes: 1 addition & 3 deletions src/String.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,6 @@ bool Convert_ParseBool(const String* str, bool* value) {
/*########################################################################################################################*
*------------------------------------------------------StringsBuffer------------------------------------------------------*
*#########################################################################################################################*/
#define STRINGSBUFFER_LEN_SHIFT 9
#define STRINGSBUFFER_LEN_MASK 0x1FFUL
#define STRINGSBUFFER_BUFFER_EXPAND_SIZE 8192

CC_NOINLINE static void StringsBuffer_Init(StringsBuffer* buffer) {
Expand Down Expand Up @@ -791,7 +789,7 @@ String StringsBuffer_UNSAFE_Get(StringsBuffer* buffer, int i) {
void StringsBuffer_Add(StringsBuffer* buffer, const String* str) {
int textOffset;
/* StringsBuffer hasn't been initalised yet, do it here */
if (!buffer->_FlagsBufferSize) { StringsBuffer_Init(buffer); }
if (!buffer->_FlagsBufferSize) StringsBuffer_Init(buffer);

if (buffer->Count == buffer->_FlagsBufferSize) {
buffer->FlagsBuffer = Utils_Resize(buffer->FlagsBuffer, &buffer->_FlagsBufferSize,
Expand Down
3 changes: 3 additions & 0 deletions src/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ CC_API bool Convert_ParseBool(const String* str, bool* value);

#define STRINGSBUFFER_BUFFER_DEF_SIZE 4096
#define STRINGSBUFFER_FLAGS_DEF_ELEMS 256
#define STRINGSBUFFER_LEN_SHIFT 9
#define STRINGSBUFFER_LEN_MASK 0x1FFUL

typedef struct StringsBuffer_ {
char* TextBuffer; /* Raw characters of all entries */
uint32_t* FlagsBuffer; /* Private flags for each entry */
Expand Down
8 changes: 8 additions & 0 deletions src/Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ void EntryList_Load(struct EntryList* list, EntryList_Filter filter) {
if (!entry.length) continue;
if (filter && !filter(&entry)) continue;

/* Sometimes file becomes corrupted and replaced with NULL */
/* If don't prevent this here, client aborts in StringsBuffer_Add */
if (entry.length > STRINGSBUFFER_LEN_MASK) {
entry.length = 0;
String_Format1(&entry, "Skipping extremely long line in %c, file may have been corrupted", list->Filename);
Logger_WarnFunc(&entry); continue;
}

String_UNSAFE_Separate(&entry, list->Separator, &key, &value);
EntryList_Set(list, &key, &value);
}
Expand Down

0 comments on commit 5495faa

Please sign in to comment.