Skip to content

Commit

Permalink
less warnings with GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Sep 12, 2018
1 parent 1f89cb7 commit eb73a12
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/AsyncDownloader.c
Expand Up @@ -11,17 +11,17 @@ void ASyncRequest_Free(struct AsyncRequest* request) {
request->ResultSize = 0;
}

#define ASYNCREQUESTLIST_DEFELEMS 10
#define ASYNC_DEF_ELEMS 10
struct AsyncRequestList {
Int32 MaxElems, Count;
struct AsyncRequest* Requests;
struct AsyncRequest DefaultRequests[ASYNCREQUESTLIST_DEFELEMS];
struct AsyncRequest DefaultRequests[ASYNC_DEF_ELEMS];
};

static void AsyncRequestList_EnsureSpace(struct AsyncRequestList* list) {
if (list->Count < list->MaxElems) return;
Utils_Resize(&list->Requests, &list->MaxElems, sizeof(struct AsyncRequest),
ASYNCREQUESTLIST_DEFELEMS, 10);
list->Requests = Utils_Resize(list->Requests, &list->MaxElems,
sizeof(struct AsyncRequest), ASYNC_DEF_ELEMS, 10);
}

static void AsyncRequestList_Append(struct AsyncRequestList* list, struct AsyncRequest* item) {
Expand Down Expand Up @@ -49,8 +49,8 @@ static void AsyncRequestList_RemoveAt(struct AsyncRequestList* list, Int32 i) {
}

static void AsyncRequestList_Init(struct AsyncRequestList* list) {
list->MaxElems = ASYNCREQUESTLIST_DEFELEMS;
list->Count = 0;
list->MaxElems = ASYNC_DEF_ELEMS;
list->Count = 0;
list->Requests = list->DefaultRequests;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Audio.c
Expand Up @@ -186,6 +186,7 @@ struct Sound* Soundboard_PickRandom(struct Soundboard* board, UInt8 type) {
*#########################################################################################################################*/
struct SoundOutput { AudioHandle Handle; void* Buffer; UInt32 BufferSize; };
#define AUDIO_MAX_HANDLES 6
#define AUDIO_DEF_ELEMS 0
#define HANDLE_INV -1
#define SOUND_INV { HANDLE_INV, NULL, 0 }

Expand All @@ -201,7 +202,8 @@ static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct
if (volume < 100) {
if (output->BufferSize < snd->DataSize) {
UInt32 expandBy = snd->DataSize - output->BufferSize;
Utils_Resize(&output->Buffer, &output->BufferSize, 1, 0, expandBy);
output->Buffer = Utils_Resize(output->Buffer, &output->BufferSize,
sizeof(UInt8), AUDIO_DEF_ELEMS, expandBy);
}
buffer = output->Buffer;

Expand Down
5 changes: 2 additions & 3 deletions src/Chat.c
Expand Up @@ -17,7 +17,6 @@
#include "GameStructs.h"

#define CHAT_LOGTIMES_DEF_ELEMS 256
#define CHAT_LOGTIMES_EXPAND_ELEMS 512
UInt64 Chat_DefaultLogTimes[CHAT_LOGTIMES_DEF_ELEMS];
UInt64* Chat_LogTimes = Chat_DefaultLogTimes;
Int32 Chat_LogTimesMax = CHAT_LOGTIMES_DEF_ELEMS, Chat_LogTimesCount;
Expand All @@ -29,8 +28,8 @@ UInt64 Chat_GetLogTime(Int32 i) {

static void Chat_AppendLogTime(void) {
if (Chat_LogTimesCount == Chat_LogTimesMax) {
Utils_Resize(&Chat_LogTimes, &Chat_LogTimesMax, sizeof(UInt64),
CHAT_LOGTIMES_DEF_ELEMS, CHAT_LOGTIMES_EXPAND_ELEMS);
Chat_LogTimes = Utils_Resize(Chat_LogTimes, &Chat_LogTimesMax,
sizeof(UInt64), CHAT_LOGTIMES_DEF_ELEMS, 512);
}

UInt64 now = DateTime_CurrentUTC_MS();
Expand Down
6 changes: 3 additions & 3 deletions src/Platform.c
Expand Up @@ -1478,16 +1478,16 @@ void Platform_Free(void) {
}

void Platform_SetWorkingDir(void) {
WCHAR dirName[FILENAME_SIZE + 1] = { 0 };
WCHAR dirName[FILENAME_SIZE + 1];
DWORD len = GetModuleFileNameW(NULL, dirName, FILENAME_SIZE);
if (!len) return;

/* get rid of filename at end of directory*/
/* get rid of filename at end of directory */
for (; len > 0; len--) {
if (dirName[len] == '/' || dirName[len] == '\\') break;
dirName[len] = '\0';
}

dirName[len] = '\0';
SetCurrentDirectoryW(dirName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ServerConnection.c
Expand Up @@ -51,7 +51,7 @@ void ServerConnection_RetrieveTexturePack(STRING_PURE String* url) {

void ServerConnection_DownloadTexturePack(STRING_PURE String* url) {
if (TextureCache_HasDenied(url)) return;
UInt8 etagBuffer[STRING_SIZE] = { 0 };
char etagBuffer[STRING_SIZE];
String etag = String_FromArray(etagBuffer);
UInt64 lastModified = 0;

Expand Down
9 changes: 4 additions & 5 deletions src/String.c
Expand Up @@ -674,7 +674,6 @@ bool Convert_TryParseBool(STRING_PURE String* str, bool* value) {
#define STRINGSBUFFER_LEN_SHIFT 9
#define STRINGSBUFFER_LEN_MASK 0x1FFUL
#define STRINGSBUFFER_BUFFER_EXPAND_SIZE 8192
#define STRINGSBUFFER_FLAGS_EXPAND_ELEMS 512

void StringsBuffer_Init(StringsBuffer* buffer) {
buffer->Count = 0;
Expand Down Expand Up @@ -717,8 +716,8 @@ void StringsBuffer_Add(StringsBuffer* buffer, STRING_PURE String* text) {
if (!buffer->_FlagsBufferSize) { StringsBuffer_Init(buffer); }

if (buffer->Count == buffer->_FlagsBufferSize) {
Utils_Resize(&buffer->FlagsBuffer, &buffer->_FlagsBufferSize, sizeof(UInt32),
STRINGSBUFFER_FLAGS_DEF_ELEMS, STRINGSBUFFER_FLAGS_EXPAND_ELEMS);
buffer->FlagsBuffer = Utils_Resize(buffer->FlagsBuffer, &buffer->_FlagsBufferSize,
sizeof(UInt32), STRINGSBUFFER_FLAGS_DEF_ELEMS, 512);
}

if (text->length > STRINGSBUFFER_LEN_MASK) {
Expand All @@ -727,8 +726,8 @@ void StringsBuffer_Add(StringsBuffer* buffer, STRING_PURE String* text) {

Int32 textOffset = buffer->TotalLength;
if (textOffset + text->length >= buffer->_TextBufferSize) {
Utils_Resize(&buffer->TextBuffer, &buffer->_TextBufferSize, sizeof(char),
STRINGSBUFFER_BUFFER_DEF_SIZE, STRINGSBUFFER_BUFFER_EXPAND_SIZE);
buffer->TextBuffer = Utils_Resize(buffer->TextBuffer, &buffer->_TextBufferSize,
sizeof(char), STRINGSBUFFER_BUFFER_DEF_SIZE, 8192);
}

if (text->length) {
Expand Down
17 changes: 7 additions & 10 deletions src/Utils.c
Expand Up @@ -184,21 +184,18 @@ UInt32 Utils_Crc32Table[256] = {
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
};

void Utils_Resize(void** buffer, UInt32* maxElems, UInt32 elemSize, UInt32 defElems, UInt32 expandElems) {
void* Utils_Resize(void* buffer, UInt32* maxElems, UInt32 elemSize, UInt32 defElems, UInt32 expandElems) {
/* We use a statically allocated buffer initally, so can't realloc first time */
void* dst;
void* cur = *buffer;
UInt32 curElems = *maxElems;
UInt32 curElems = *maxElems, elems = curElems + expandElems;
*maxElems = elems;

if (curElems <= defElems) {
dst = Mem_Alloc(curElems + expandElems, elemSize, "initing array");
Mem_Copy(dst, cur, curElems * elemSize);
void* resized = Mem_Alloc(elems, elemSize, "initing array");
Mem_Copy(resized, buffer, curElems * elemSize);
return resized;
} else {
dst = Mem_Realloc(cur, curElems + expandElems, elemSize, "resizing array");
return Mem_Realloc(buffer, elems, elemSize, "resizing array");
}

*buffer = dst;
*maxElems = curElems + expandElems;
}

bool Utils_ParseIP(STRING_PURE String* ip, UInt8* data) {
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.h
Expand Up @@ -33,6 +33,6 @@ Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta);
UInt8 Utils_GetSkinType(Bitmap* bmp);
UInt32 Utils_CRC32(UInt8* data, UInt32 length);
extern UInt32 Utils_Crc32Table[256];
void Utils_Resize(void** buffer, UInt32* maxElems, UInt32 elemSize, UInt32 defElems, UInt32 expandElems);
bool Utils_ParseIP(STRING_PURE String* ip, UInt8* data);
NOINLINE_ void* Utils_Resize(void* buffer, UInt32* maxElems, UInt32 elemSize, UInt32 defElems, UInt32 expandElems);
NOINLINE_ bool Utils_ParseIP(STRING_PURE String* ip, UInt8* data);
#endif

0 comments on commit eb73a12

Please sign in to comment.