mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
less warnings compiling with clang
This commit is contained in:
parent
ceffe44e1b
commit
ab8a35f7c7
@ -69,7 +69,7 @@ static ReturnCode Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) {
|
||||
UInt8 tmp[WAV_FMT_SIZE];
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Stream_Read(stream, tmp, 12)) return res;
|
||||
if ((res = Stream_Read(stream, tmp, 12))) return res;
|
||||
fourCC = Stream_GetU32_BE(&tmp[0]);
|
||||
if (fourCC != WAV_FourCC('R','I','F','F')) return WAV_ERR_STREAM_HDR;
|
||||
/* tmp[4] (4) file size */
|
||||
@ -77,12 +77,12 @@ static ReturnCode Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) {
|
||||
if (fourCC != WAV_FourCC('W','A','V','E')) return WAV_ERR_STREAM_TYPE;
|
||||
|
||||
for (;;) {
|
||||
if (res = Stream_Read(stream, tmp, 8)) return res;
|
||||
if ((res = Stream_Read(stream, tmp, 8))) return res;
|
||||
fourCC = Stream_GetU32_BE(&tmp[0]);
|
||||
size = Stream_GetU32_LE(&tmp[4]);
|
||||
|
||||
if (fourCC == WAV_FourCC('f','m','t',' ')) {
|
||||
if (res = Stream_Read(stream, tmp, sizeof(tmp))) return res;
|
||||
if ((res = Stream_Read(stream, tmp, sizeof(tmp)))) return res;
|
||||
if (Stream_GetU16_LE(&tmp[0]) != 1) return WAV_ERR_DATA_TYPE;
|
||||
|
||||
snd->Format.Channels = Stream_GetU16_LE(&tmp[2]);
|
||||
|
22
src/Bitmap.c
22
src/Bitmap.c
@ -440,7 +440,7 @@ ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream) {
|
||||
|
||||
/* TODO: This assumes zlib header will be in 1 IDAT chunk */
|
||||
while (!zlibHeader.Done) {
|
||||
if (res = ZLibHeader_Read(&datStream, &zlibHeader)) return res;
|
||||
if ((res = ZLibHeader_Read(&datStream, &zlibHeader))) return res;
|
||||
}
|
||||
|
||||
UInt32 bufferLen = bufferRows * scanlineBytes, bufferMax = bufferLen - scanlineBytes;
|
||||
@ -484,11 +484,11 @@ ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream) {
|
||||
} break;
|
||||
|
||||
default:
|
||||
if (res = Stream_Skip(stream, dataSize)) return res;
|
||||
if ((res = Stream_Skip(stream, dataSize))) return res;
|
||||
break;
|
||||
}
|
||||
|
||||
if (res = Stream_Read(stream, tmp, 4)) return res; /* Skip CRC32 */
|
||||
if ((res = Stream_Read(stream, tmp, 4))) return res; /* Skip CRC32 */
|
||||
}
|
||||
|
||||
if (transparentCol <= PNG_RGB_MASK) {
|
||||
@ -610,7 +610,7 @@ static void Png_EncodeRow(UInt8* src, UInt8* cur, UInt8* prior, UInt8* best, Int
|
||||
ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream) {
|
||||
ReturnCode res;
|
||||
UInt8 tmp[32];
|
||||
if (res = Stream_Write(stream, png_sig, PNG_SIG_SIZE)) return res;
|
||||
if ((res = Stream_Write(stream, png_sig, PNG_SIG_SIZE))) return res;
|
||||
|
||||
struct Stream* underlying = stream;
|
||||
struct Stream crc32Stream;
|
||||
@ -637,9 +637,9 @@ ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream) {
|
||||
|
||||
/* Write PNG body */
|
||||
Stream_SetU32_BE(&tmp[25], 0); /* size of IDAT, filled in later */
|
||||
if (res = Stream_Write(stream, tmp, 29)) return res;
|
||||
if ((res = Stream_Write(stream, tmp, 29))) return res;
|
||||
Stream_SetU32_BE(&tmp[0], PNG_FourCC('I','D','A','T'));
|
||||
if (res = Stream_Write(&crc32Stream, tmp, 4)) return res;
|
||||
if ((res = Stream_Write(&crc32Stream, tmp, 4))) return res;
|
||||
|
||||
stream = &crc32Stream;
|
||||
{
|
||||
@ -654,9 +654,9 @@ ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream) {
|
||||
UInt8* cur = (y & 1) == 0 ? curLine : prevLine;
|
||||
Png_EncodeRow(src, cur, prev, bestLine, lineSize);
|
||||
/* +1 for filter byte */
|
||||
if (res = Stream_Write(&zlStream, bestLine, lineSize + 1)) return res;
|
||||
if ((res = Stream_Write(&zlStream, bestLine, lineSize + 1))) return res;
|
||||
}
|
||||
if (res = zlStream.Close(&zlStream)) return res;
|
||||
if ((res = zlStream.Close(&zlStream))) return res;
|
||||
}
|
||||
stream = underlying;
|
||||
Stream_SetU32_BE(&tmp[0], crc32Stream.Meta.CRC32.CRC32 ^ 0xFFFFFFFFUL);
|
||||
@ -665,12 +665,12 @@ ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream) {
|
||||
Stream_SetU32_BE(&tmp[4], 0);
|
||||
Stream_SetU32_BE(&tmp[8], PNG_FourCC('I','E','N','D'));
|
||||
Stream_SetU32_BE(&tmp[12], 0xAE426082UL); /* CRC32 of iend */
|
||||
if (res = Stream_Write(stream, tmp, 16)) return res;
|
||||
if ((res = Stream_Write(stream, tmp, 16))) return res;
|
||||
|
||||
/* Come back to write size of data chunk */
|
||||
UInt32 stream_len;
|
||||
if (res = stream->Length(stream, &stream_len)) return res;
|
||||
if (res = stream->Seek(stream, 33, STREAM_SEEKFROM_BEGIN)) return res;
|
||||
if ((res = stream->Length(stream, &stream_len))) return res;
|
||||
if ((res = stream->Seek(stream, 33, STREAM_SEEKFROM_BEGIN))) return res;
|
||||
|
||||
Stream_SetU32_BE(&tmp[0], stream_len - 57);
|
||||
return Stream_Write(stream, tmp, 4);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "Stream.h"
|
||||
#include "Errors.h"
|
||||
|
||||
#define Header_ReadU8(value) if (res = s->ReadU8(s, &value)) return res;
|
||||
#define Header_ReadU8(value) if ((res = s->ReadU8(s, &value))) return res;
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------GZip header-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
@ -886,7 +886,7 @@ static ReturnCode GZip_StreamClose(struct Stream* stream) {
|
||||
struct GZipState* state = stream->Meta.Inflate;
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Deflate_StreamClose(stream)) return res;
|
||||
if ((res = Deflate_StreamClose(stream))) return res;
|
||||
Stream_SetU32_LE(&data[0], state->Crc32 ^ 0xFFFFFFFFUL);
|
||||
Stream_SetU32_LE(&data[4], state->Size);
|
||||
return Stream_Write(state->Base.Dest, data, sizeof(data));
|
||||
@ -911,7 +911,7 @@ static ReturnCode GZip_StreamWriteFirst(struct Stream* stream, UInt8* data, UInt
|
||||
struct GZipState* state = stream->Meta.Inflate;
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Stream_Write(state->Base.Dest, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Write(state->Base.Dest, header, sizeof(header)))) return res;
|
||||
stream->Write = GZip_StreamWrite;
|
||||
return GZip_StreamWrite(stream, data, count, modified);
|
||||
}
|
||||
@ -933,7 +933,7 @@ static ReturnCode ZLib_StreamClose(struct Stream* stream) {
|
||||
struct ZLibState* state = stream->Meta.Inflate;
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Deflate_StreamClose(stream)) return res;
|
||||
if ((res = Deflate_StreamClose(stream))) return res;
|
||||
Stream_SetU32_BE(&data[0], state->Adler32);
|
||||
return Stream_Write(state->Base.Dest, data, sizeof(data));
|
||||
}
|
||||
@ -959,7 +959,7 @@ static ReturnCode ZLib_StreamWriteFirst(struct Stream* stream, UInt8* data, UInt
|
||||
struct ZLibState* state = stream->Meta.Inflate;
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Stream_Write(state->Base.Dest, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Write(state->Base.Dest, header, sizeof(header)))) return res;
|
||||
stream->Write = ZLib_StreamWrite;
|
||||
return ZLib_StreamWrite(stream, data, count, modified);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ static ReturnCode Map_SkipGZipHeader(struct Stream* stream) {
|
||||
ReturnCode res;
|
||||
|
||||
while (!gzHeader.Done) {
|
||||
if (res = GZipHeader_Read(stream, &gzHeader)) return res;
|
||||
if ((res = GZipHeader_Read(stream, &gzHeader))) return res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -60,9 +60,9 @@ static ReturnCode Lvl_ReadCustomBlocks(struct Stream* stream) {
|
||||
for (z = 0; z < World_Length; z += LVL_CHUNKSIZE) {
|
||||
for (x = 0; x < World_Width; x += LVL_CHUNKSIZE) {
|
||||
|
||||
if (res = stream->ReadU8(stream, &hasCustom)) return res;
|
||||
if ((res = stream->ReadU8(stream, &hasCustom))) return res;
|
||||
if (hasCustom != 1) continue;
|
||||
if (res = Stream_Read(stream, chunk, sizeof(chunk))) return res;
|
||||
if ((res = Stream_Read(stream, chunk, sizeof(chunk)))) return res;
|
||||
|
||||
Int32 baseIndex = World_Pack(x, y, z);
|
||||
if ((x + LVL_CHUNKSIZE) <= adjWidth && (y + LVL_CHUNKSIZE) <= adjHeight && (z + LVL_CHUNKSIZE) <= adjLength) {
|
||||
@ -117,14 +117,14 @@ ReturnCode Lvl_Load(struct Stream* stream) {
|
||||
Inflate_MakeStream(&compStream, &state, stream);
|
||||
|
||||
UInt8 header[8 + 2];
|
||||
if (res = Stream_Read(&compStream, header, 8)) return res;
|
||||
if ((res = Stream_Read(&compStream, header, 8))) return res;
|
||||
if (Stream_GetU16_LE(&header[0]) != 1874) return LVL_ERR_VERSION;
|
||||
|
||||
World_Width = Stream_GetU16_LE(&header[2]);
|
||||
World_Length = Stream_GetU16_LE(&header[4]);
|
||||
World_Height = Stream_GetU16_LE(&header[6]);
|
||||
|
||||
if (res = Stream_Read(&compStream, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Read(&compStream, header, sizeof(header)))) return res;
|
||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
||||
|
||||
p->Spawn.X = Stream_GetU16_LE(&header[0]);
|
||||
@ -153,7 +153,7 @@ ReturnCode Lvl_Load(struct Stream* stream) {
|
||||
static ReturnCode Fcm_ReadString(struct Stream* stream) {
|
||||
UInt8 data[2];
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(stream, data, sizeof(data))) return res;
|
||||
if ((res = Stream_Read(stream, data, sizeof(data)))) return res;
|
||||
|
||||
UInt16 len = Stream_GetU16_LE(data);
|
||||
return Stream_Skip(stream, len);
|
||||
@ -163,11 +163,11 @@ ReturnCode Fcm_Load(struct Stream* stream) {
|
||||
UInt8 header[(3 * 2) + (3 * 4) + (2 * 1) + (2 * 4) + 16 + 26 + 4];
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Stream_Read(stream, header, 4 + 1)) return res;
|
||||
if ((res = Stream_Read(stream, header, 4 + 1))) return res;
|
||||
if (Stream_GetU32_LE(&header[0]) != 0x0FC2AF40UL) return FCM_ERR_IDENTIFIER;
|
||||
if (header[4] != 13) return FCM_ERR_REVISION;
|
||||
|
||||
if (res = Stream_Read(stream, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Read(stream, header, sizeof(header)))) return res;
|
||||
World_Width = Stream_GetU16_LE(&header[0]);
|
||||
World_Height = Stream_GetU16_LE(&header[2]);
|
||||
World_Length = Stream_GetU16_LE(&header[4]);
|
||||
@ -191,9 +191,9 @@ ReturnCode Fcm_Load(struct Stream* stream) {
|
||||
|
||||
Int32 i;
|
||||
for (i = 0; i < metaSize; i++) {
|
||||
if (res = Fcm_ReadString(&compStream)) return res; /* Group */
|
||||
if (res = Fcm_ReadString(&compStream)) return res; /* Key */
|
||||
if (res = Fcm_ReadString(&compStream)) return res; /* Value */
|
||||
if ((res = Fcm_ReadString(&compStream))) return res; /* Group */
|
||||
if ((res = Fcm_ReadString(&compStream))) return res; /* Key */
|
||||
if ((res = Fcm_ReadString(&compStream))) return res; /* Value */
|
||||
}
|
||||
return Map_ReadBlocks(&compStream);
|
||||
}
|
||||
@ -261,11 +261,11 @@ static String NbtTag_String(struct NbtTag* tag) {
|
||||
static ReturnCode Nbt_ReadString(struct Stream* stream, char* strBuffer, UInt32* strLen) {
|
||||
ReturnCode res;
|
||||
char nameBuffer[NBT_SMALL_SIZE * 4];
|
||||
if (res = Stream_Read(stream, nameBuffer, 2)) return res;
|
||||
if ((res = Stream_Read(stream, nameBuffer, 2))) return res;
|
||||
|
||||
UInt16 nameLen = Stream_GetU16_BE(nameBuffer);
|
||||
if (nameLen > NBT_SMALL_SIZE * 4) return CW_ERR_STRING_LEN;
|
||||
if (res = Stream_Read(stream, nameBuffer, nameLen)) return res;
|
||||
if ((res = Stream_Read(stream, nameBuffer, nameLen))) return res;
|
||||
|
||||
String str = String_Init(strBuffer, 0, NBT_SMALL_SIZE);
|
||||
String_DecodeUtf8(&str, nameBuffer, nameLen);
|
||||
@ -308,7 +308,7 @@ static ReturnCode Nbt_ReadTag(UInt8 typeId, bool readTagName, struct Stream* str
|
||||
break; /* (8) data */
|
||||
|
||||
case NBT_I8S:
|
||||
if (res = Stream_ReadU32_BE(stream, &tag.DataSize)) break;
|
||||
if ((res = Stream_ReadU32_BE(stream, &tag.DataSize))) break;
|
||||
|
||||
if (tag.DataSize < NBT_SMALL_SIZE) {
|
||||
res = Stream_Read(stream, tag.DataSmall, tag.DataSize);
|
||||
@ -323,7 +323,7 @@ static ReturnCode Nbt_ReadTag(UInt8 typeId, bool readTagName, struct Stream* str
|
||||
break;
|
||||
|
||||
case NBT_LIST:
|
||||
if (res = Stream_Read(stream, tmp, 5)) break;
|
||||
if ((res = Stream_Read(stream, tmp, 5))) break;
|
||||
childType = tmp[0];
|
||||
count = Stream_GetU32_BE(&tmp[1]);
|
||||
|
||||
@ -335,7 +335,7 @@ static ReturnCode Nbt_ReadTag(UInt8 typeId, bool readTagName, struct Stream* str
|
||||
|
||||
case NBT_DICT:
|
||||
for (;;) {
|
||||
if (res = stream->ReadU8(stream, &childType)) break;
|
||||
if ((res = stream->ReadU8(stream, &childType))) break;
|
||||
if (childType == NBT_END) break;
|
||||
|
||||
res = Nbt_ReadTag(childType, true, stream, &tag, callback);
|
||||
@ -572,7 +572,7 @@ ReturnCode Cw_Load(struct Stream* stream) {
|
||||
Inflate_MakeStream(&compStream, &state, stream);
|
||||
|
||||
UInt8 tag;
|
||||
if (res = compStream.ReadU8(&compStream, &tag)) return res;
|
||||
if ((res = compStream.ReadU8(&compStream, &tag))) return res;
|
||||
if (tag != NBT_DICT) return CW_ERR_ROOT_TAG;
|
||||
|
||||
res = Nbt_ReadTag(NBT_DICT, true, &compStream, NULL, Cw_Callback);
|
||||
@ -619,7 +619,7 @@ struct JClassDesc {
|
||||
|
||||
static ReturnCode Dat_ReadString(struct Stream* stream, char* buffer) {
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(stream, buffer, 2)) return res;
|
||||
if ((res = Stream_Read(stream, buffer, 2))) return res;
|
||||
UInt16 len = Stream_GetU16_BE(buffer);
|
||||
|
||||
Mem_Set(buffer, 0, JNAME_SIZE);
|
||||
@ -629,12 +629,12 @@ static ReturnCode Dat_ReadString(struct Stream* stream, char* buffer) {
|
||||
|
||||
static ReturnCode Dat_ReadFieldDesc(struct Stream* stream, struct JFieldDesc* desc) {
|
||||
ReturnCode res;
|
||||
if (res = stream->ReadU8(stream, &desc->Type)) return res;
|
||||
if (res = Dat_ReadString(stream, desc->FieldName)) return res;
|
||||
if ((res = stream->ReadU8(stream, &desc->Type))) return res;
|
||||
if ((res = Dat_ReadString(stream, desc->FieldName))) return res;
|
||||
|
||||
if (desc->Type == JFIELD_ARRAY || desc->Type == JFIELD_OBJECT) {
|
||||
UInt8 typeCode;
|
||||
if (res = stream->ReadU8(stream, &typeCode)) return res;
|
||||
if ((res = stream->ReadU8(stream, &typeCode))) return res;
|
||||
|
||||
if (typeCode == TC_STRING) {
|
||||
char className1[JNAME_SIZE];
|
||||
@ -653,23 +653,23 @@ static ReturnCode Dat_ReadClassDesc(struct Stream* stream, struct JClassDesc* de
|
||||
UInt8 typeCode;
|
||||
UInt8 tmp[2];
|
||||
|
||||
if (res = stream->ReadU8(stream, &typeCode)) return res;
|
||||
if ((res = stream->ReadU8(stream, &typeCode))) return res;
|
||||
if (typeCode == TC_NULL) { desc->ClassName[0] = '\0'; desc->FieldsCount = 0; return 0; }
|
||||
if (typeCode != TC_CLASSDESC) return DAT_ERR_JCLASS_TYPE;
|
||||
|
||||
if (res = Dat_ReadString(stream, desc->ClassName)) return res;
|
||||
if (res = Stream_Skip(stream, 9)) return res; /* (8) serial version UID, (1) flags */
|
||||
if ((res = Dat_ReadString(stream, desc->ClassName))) return res;
|
||||
if ((res = Stream_Skip(stream, 9))) return res; /* (8) serial version UID, (1) flags */
|
||||
|
||||
if (res = Stream_Read(stream, tmp, 2)) return res;
|
||||
if ((res = Stream_Read(stream, tmp, 2))) return res;
|
||||
desc->FieldsCount = Stream_GetU16_BE(tmp);
|
||||
if (desc->FieldsCount > Array_Elems(desc->Fields)) return DAT_ERR_JCLASS_FIELDS;
|
||||
|
||||
Int32 i;
|
||||
for (i = 0; i < desc->FieldsCount; i++) {
|
||||
if (res = Dat_ReadFieldDesc(stream, &desc->Fields[i])) return res;
|
||||
if ((res = Dat_ReadFieldDesc(stream, &desc->Fields[i]))) return res;
|
||||
}
|
||||
|
||||
if (res = stream->ReadU8(stream, &typeCode)) return res;
|
||||
if ((res = stream->ReadU8(stream, &typeCode))) return res;
|
||||
if (typeCode != TC_ENDBLOCKDATA) return DAT_ERR_JCLASS_ANNOTATION;
|
||||
|
||||
struct JClassDesc superClassDesc;
|
||||
@ -696,16 +696,16 @@ static ReturnCode Dat_ReadFieldData(struct Stream* stream, struct JFieldDesc* fi
|
||||
/* Other objects (e.g. player) are stored after the fields we actually care about, so ignore them */
|
||||
String fieldName = String_FromRawArray(field->FieldName);
|
||||
if (!String_CaselessEqualsConst(&fieldName, "blockMap")) return 0;
|
||||
if (res = stream->ReadU8(stream, &typeCode)) return res;
|
||||
if ((res = stream->ReadU8(stream, &typeCode))) return res;
|
||||
|
||||
/* Skip all blockMap data with awful hacks */
|
||||
/* These offsets were based on server_level.dat map from original minecraft classic server */
|
||||
if (typeCode == TC_OBJECT) {
|
||||
if (res = Stream_Skip(stream, 315)) return res;
|
||||
if (res = Stream_ReadU32_BE(stream, &count)) return res;
|
||||
if ((res = Stream_Skip(stream, 315))) return res;
|
||||
if ((res = Stream_ReadU32_BE(stream, &count))) return res;
|
||||
|
||||
if (res = Stream_Skip(stream, 17 * count)) return res;
|
||||
if (res = Stream_Skip(stream, 152)) return res;
|
||||
if ((res = Stream_Skip(stream, 17 * count))) return res;
|
||||
if ((res = Stream_Skip(stream, 152))) return res;
|
||||
} else if (typeCode != TC_NULL) {
|
||||
/* WoM maps have this field as null, which makes things easier for us */
|
||||
return DAT_ERR_JOBJECT_TYPE;
|
||||
@ -713,15 +713,15 @@ static ReturnCode Dat_ReadFieldData(struct Stream* stream, struct JFieldDesc* fi
|
||||
} break;
|
||||
|
||||
case JFIELD_ARRAY: {
|
||||
if (res = stream->ReadU8(stream, &typeCode)) return res;
|
||||
if ((res = stream->ReadU8(stream, &typeCode))) return res;
|
||||
if (typeCode == TC_NULL) break;
|
||||
if (typeCode != TC_ARRAY) return DAT_ERR_JARRAY_TYPE;
|
||||
|
||||
struct JClassDesc arrayClassDesc;
|
||||
if (res = Dat_ReadClassDesc(stream, &arrayClassDesc)) return res;
|
||||
if ((res = Dat_ReadClassDesc(stream, &arrayClassDesc))) return res;
|
||||
if (arrayClassDesc.ClassName[1] != JFIELD_INT8) return DAT_ERR_JARRAY_CONTENT;
|
||||
|
||||
if (res = Stream_ReadU32_BE(stream, &count)) return res;
|
||||
if ((res = Stream_ReadU32_BE(stream, &count))) return res;
|
||||
field->Value_Size = count;
|
||||
|
||||
field->Value_Ptr = Mem_Alloc(count, sizeof(UInt8), ".dat map blocks");
|
||||
@ -746,7 +746,7 @@ ReturnCode Dat_Load(struct Stream* stream) {
|
||||
Inflate_MakeStream(&compStream, &state, stream);
|
||||
|
||||
UInt8 header[4 + 1 + 2 * 2];
|
||||
if (res = Stream_Read(&compStream, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Read(&compStream, header, sizeof(header)))) return res;
|
||||
|
||||
/* .dat header */
|
||||
if (Stream_GetU32_BE(&header[0]) != 0x271BB788) return DAT_ERR_IDENTIFIER;
|
||||
@ -757,18 +757,18 @@ ReturnCode Dat_Load(struct Stream* stream) {
|
||||
if (Stream_GetU16_BE(&header[7]) != 0x0005) return DAT_ERR_JVERSION;
|
||||
|
||||
UInt8 typeCode;
|
||||
if (res = compStream.ReadU8(&compStream, &typeCode)) return res;
|
||||
if ((res = compStream.ReadU8(&compStream, &typeCode))) return res;
|
||||
if (typeCode != TC_OBJECT) return DAT_ERR_ROOT_TYPE;
|
||||
|
||||
struct JClassDesc obj;
|
||||
if (res = Dat_ReadClassDesc(&compStream, &obj)) return res;
|
||||
if ((res = Dat_ReadClassDesc(&compStream, &obj))) return res;
|
||||
|
||||
Int32 i;
|
||||
Vector3* spawn = &LocalPlayer_Instance.Spawn;
|
||||
for (i = 0; i < obj.FieldsCount; i++) {
|
||||
struct JFieldDesc* field = &obj.Fields[i];
|
||||
|
||||
if (res = Dat_ReadFieldData(&compStream, field)) return res;
|
||||
if ((res = Dat_ReadFieldData(&compStream, field))) return res;
|
||||
String fieldName = String_FromRawArray(field->FieldName);
|
||||
|
||||
if (String_CaselessEqualsConst(&fieldName, "width")) {
|
||||
@ -945,8 +945,8 @@ ReturnCode Cw_Save(struct Stream* stream) {
|
||||
tmp[107] = Math_Deg2Packed(p->SpawnRotY);
|
||||
tmp[112] = Math_Deg2Packed(p->SpawnHeadX);
|
||||
}
|
||||
if (res = Stream_Write(stream, tmp, sizeof(cw_begin))) return res;
|
||||
if (res = Stream_Write(stream, World_Blocks, World_BlocksSize)) return res;
|
||||
if ((res = Stream_Write(stream, tmp, sizeof(cw_begin)))) return res;
|
||||
if ((res = Stream_Write(stream, World_Blocks, World_BlocksSize))) return res;
|
||||
|
||||
Mem_Copy(tmp, cw_meta_cpe, sizeof(cw_meta_cpe));
|
||||
{
|
||||
@ -964,12 +964,12 @@ ReturnCode Cw_Save(struct Stream* stream) {
|
||||
Stream_SetU16_BE(&tmp[378], WorldEnv_EdgeHeight);
|
||||
}
|
||||
Int32 b, len = Cw_WriteEndString(&tmp[393], &World_TextureUrl);
|
||||
if (res = Stream_Write(stream, tmp, sizeof(cw_meta_cpe) + len)) return res;
|
||||
if ((res = Stream_Write(stream, tmp, sizeof(cw_meta_cpe) + len))) return res;
|
||||
|
||||
if (res = Stream_Write(stream, cw_meta_defs, sizeof(cw_meta_defs))) return res;
|
||||
if ((res = Stream_Write(stream, cw_meta_defs, sizeof(cw_meta_defs)))) return res;
|
||||
for (b = 1; b < 256; b++) {
|
||||
if (!Block_IsCustomDefined(b)) continue;
|
||||
if (res = Cw_WriteBockDef(stream, b)) return res;
|
||||
if ((res = Cw_WriteBockDef(stream, b))) return res;
|
||||
}
|
||||
return Stream_Write(stream, cw_end, sizeof(cw_end));
|
||||
}
|
||||
@ -1007,20 +1007,20 @@ ReturnCode Schematic_Save(struct Stream* stream) {
|
||||
Stream_SetU16_BE(&tmp[63], World_Length);
|
||||
Stream_SetU32_BE(&tmp[74], World_BlocksSize);
|
||||
}
|
||||
if (res = Stream_Write(stream, sc_begin, sizeof(sc_begin))) return res;
|
||||
if (res = Stream_Write(stream, World_Blocks, World_BlocksSize)) return res;
|
||||
if ((res = Stream_Write(stream, sc_begin, sizeof(sc_begin)))) return res;
|
||||
if ((res = Stream_Write(stream, World_Blocks, World_BlocksSize))) return res;
|
||||
|
||||
Mem_Copy(tmp, sc_data, sizeof(sc_data));
|
||||
{
|
||||
Stream_SetU32_BE(&tmp[7], World_BlocksSize);
|
||||
}
|
||||
if (res = Stream_Write(stream, sc_data, sizeof(sc_data))) return res;
|
||||
if ((res = Stream_Write(stream, sc_data, sizeof(sc_data)))) return res;
|
||||
|
||||
UInt8 chunk[8192] = { 0 };
|
||||
Int32 i;
|
||||
for (i = 0; i < World_BlocksSize; i += sizeof(chunk)) {
|
||||
Int32 count = World_BlocksSize - i; count = min(count, sizeof(chunk));
|
||||
if (res = Stream_Write(stream, chunk, count)) return res;
|
||||
if ((res = Stream_Write(stream, chunk, count))) return res;
|
||||
}
|
||||
return Stream_Write(stream, sc_end, sizeof(sc_end));
|
||||
}
|
||||
|
@ -1288,7 +1288,7 @@ static void SaveLevelScreen_SaveMap(struct SaveLevelScreen* s) {
|
||||
stream.Close(&stream);
|
||||
Chat_LogError(res, "encoding", &path); return;
|
||||
}
|
||||
if (res = compStream.Close(&compStream)) {
|
||||
if ((res = compStream.Close(&compStream))) {
|
||||
stream.Close(&stream);
|
||||
Chat_LogError(res, "closing", &path); return;
|
||||
}
|
||||
|
@ -300,13 +300,13 @@ void Stream_SetU32_BE(UInt8* data, UInt32 value) {
|
||||
|
||||
ReturnCode Stream_ReadU32_LE(struct Stream* stream, UInt32* value) {
|
||||
UInt8 data[4]; ReturnCode res;
|
||||
if (res = Stream_Read(stream, data, 4)) return res;
|
||||
if ((res = Stream_Read(stream, data, 4))) return res;
|
||||
*value = Stream_GetU32_LE(data); return 0;
|
||||
}
|
||||
|
||||
ReturnCode Stream_ReadU32_BE(struct Stream* stream, UInt32* value) {
|
||||
UInt8 data[4]; ReturnCode res;
|
||||
if (res = Stream_Read(stream, data, 4)) return res;
|
||||
if ((res = Stream_Read(stream, data, 4))) return res;
|
||||
*value = Stream_GetU32_BE(data); return 0;
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ ReturnCode Stream_ReadUtf8(struct Stream* stream, UInt16* codepoint) {
|
||||
|
||||
*codepoint = data;
|
||||
for (i = 0; i < byteCount - 1; i++) {
|
||||
if (res = stream->ReadU8(stream, &data)) return res;
|
||||
if ((res = stream->ReadU8(stream, &data))) return res;
|
||||
|
||||
*codepoint <<= 6;
|
||||
/* Top two bits of each are always 10 */
|
||||
@ -388,7 +388,7 @@ ReturnCode Stream_WriteLine(struct Stream* stream, STRING_TRANSIENT String* text
|
||||
for (i = 0; i < text->length; i++) {
|
||||
/* For extremely large strings */
|
||||
if (j >= 2048) {
|
||||
if (res = Stream_Write(stream, buffer, j)) return res;
|
||||
if ((res = Stream_Write(stream, buffer, j))) return res;
|
||||
j = 0;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
|
||||
struct Stream* stream = state->Input;
|
||||
UInt8 contents[(3 * 2) + (4 * 4) + (2 * 2)];
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(stream, contents, sizeof(contents))) return res;
|
||||
if ((res = Stream_Read(stream, contents, sizeof(contents)))) return res;
|
||||
|
||||
/* contents[0] (2) version needed */
|
||||
/* contents[2] (2) flags */
|
||||
@ -44,11 +44,11 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
|
||||
|
||||
if (pathLen > ZIP_MAXNAMELEN) return ZIP_ERR_FILENAME_LEN;
|
||||
String path = String_Init(pathBuffer, pathLen, pathLen);
|
||||
if (res = Stream_Read(stream, pathBuffer, pathLen)) return res;
|
||||
if ((res = Stream_Read(stream, pathBuffer, pathLen))) return res;
|
||||
pathBuffer[pathLen] = '\0';
|
||||
|
||||
if (!state->SelectEntry(&path)) return 0;
|
||||
if (res = Stream_Skip(stream, extraLen)) return res;
|
||||
if ((res = Stream_Skip(stream, extraLen))) return res;
|
||||
struct Stream portion, compStream;
|
||||
|
||||
if (compressionMethod == 0) {
|
||||
@ -70,7 +70,7 @@ static ReturnCode Zip_ReadCentralDirectory(struct ZipState* state, struct ZipEnt
|
||||
struct Stream* stream = state->Input;
|
||||
UInt8 contents[(4 * 2) + (4 * 4) + (3 * 2) + (2 * 2) + (2 * 4)];
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(stream, contents, sizeof(contents))) return res;
|
||||
if ((res = Stream_Read(stream, contents, sizeof(contents)))) return res;
|
||||
|
||||
/* contents[0] (2) OS */
|
||||
/* contents[2] (2) version needed*/
|
||||
@ -97,7 +97,7 @@ static ReturnCode Zip_ReadEndOfCentralDirectory(struct ZipState* state, UInt32*
|
||||
struct Stream* stream = state->Input;
|
||||
UInt8 contents[(3 * 2) + 2 + (2 * 4) + 2];
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(stream, contents, sizeof(contents))) return res;
|
||||
if ((res = Stream_Read(stream, contents, sizeof(contents)))) return res;
|
||||
|
||||
/* contents[0] (2) disk number */
|
||||
/* contents[2] (2) disk number start */
|
||||
@ -130,7 +130,7 @@ ReturnCode Zip_Extract(struct ZipState* state) {
|
||||
UInt32 sig = 0, stream_len;
|
||||
|
||||
ReturnCode res;
|
||||
if (res = stream->Length(stream, &stream_len)) return res;
|
||||
if ((res = stream->Length(stream, &stream_len))) return res;
|
||||
|
||||
/* At -22 for nearly all zips, but try a bit further back in case of comment */
|
||||
Int32 i, len = min(257, stream_len);
|
||||
@ -138,7 +138,7 @@ ReturnCode Zip_Extract(struct ZipState* state) {
|
||||
res = stream->Seek(stream, -i, STREAM_SEEKFROM_END);
|
||||
if (res) return ZIP_ERR_SEEK_END_OF_CENTRAL_DIR;
|
||||
|
||||
if (res = Stream_ReadU32_LE(stream, &sig)) return res;
|
||||
if ((res = Stream_ReadU32_LE(stream, &sig))) return res;
|
||||
if (sig == ZIP_SIG_ENDOFCENTRALDIR) break;
|
||||
}
|
||||
if (sig != ZIP_SIG_ENDOFCENTRALDIR) return ZIP_ERR_NO_END_OF_CENTRAL_DIR;
|
||||
@ -154,7 +154,7 @@ ReturnCode Zip_Extract(struct ZipState* state) {
|
||||
/* Read all the central directory entries */
|
||||
Int32 count = 0;
|
||||
while (count < state->EntriesCount) {
|
||||
if (res = Stream_ReadU32_LE(stream, &sig)) return res;
|
||||
if ((res = Stream_ReadU32_LE(stream, &sig))) return res;
|
||||
|
||||
if (sig == ZIP_SIG_CENTRALDIR) {
|
||||
res = Zip_ReadCentralDirectory(state, &state->Entries[count]);
|
||||
@ -173,7 +173,7 @@ ReturnCode Zip_Extract(struct ZipState* state) {
|
||||
res = stream->Seek(stream, entry->LocalHeaderOffset, STREAM_SEEKFROM_BEGIN);
|
||||
if (res) return ZIP_ERR_SEEK_LOCAL_DIR;
|
||||
|
||||
if (res = Stream_ReadU32_LE(stream, &sig)) return res;
|
||||
if ((res = Stream_ReadU32_LE(stream, &sig))) return res;
|
||||
if (sig != ZIP_SIG_LOCALFILEHEADER) return ZIP_ERR_INVALID_LOCAL_DIR;
|
||||
|
||||
res = Zip_ReadLocalFileHeader(state, entry);
|
||||
|
36
src/Vorbis.c
36
src/Vorbis.c
@ -17,7 +17,7 @@ static ReturnCode Ogg_NextPage(struct Stream* stream) {
|
||||
struct Stream* source = stream->Meta.Ogg.Source;
|
||||
ReturnCode res;
|
||||
|
||||
if (res = Stream_Read(source, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Read(source, header, sizeof(header)))) return res;
|
||||
UInt32 sig = Stream_GetU32_BE(&header[0]);
|
||||
if (sig != OGG_FourCC('O','g','g','S')) return OGG_ERR_INVALID_SIG;
|
||||
if (header[4] != 0) return OGG_ERR_VERSION;
|
||||
@ -30,11 +30,11 @@ static ReturnCode Ogg_NextPage(struct Stream* stream) {
|
||||
|
||||
Int32 i, numSegments = header[26];
|
||||
UInt8 segments[255];
|
||||
if (res = Stream_Read(source, segments, numSegments)) return res;
|
||||
if ((res = Stream_Read(source, segments, numSegments))) return res;
|
||||
|
||||
UInt32 dataSize = 0;
|
||||
for (i = 0; i < numSegments; i++) { dataSize += segments[i]; }
|
||||
if (res = Stream_Read(source, stream->Meta.Ogg.Base, dataSize)) return res;
|
||||
if ((res = Stream_Read(source, stream->Meta.Ogg.Base, dataSize))) return res;
|
||||
|
||||
stream->Meta.Ogg.Cur = stream->Meta.Ogg.Base;
|
||||
stream->Meta.Ogg.Left = dataSize;
|
||||
@ -59,7 +59,7 @@ static ReturnCode Ogg_Read(struct Stream* stream, UInt8* data, UInt32 count, UIn
|
||||
if (stream->Meta.Ogg.Last) return 0;
|
||||
|
||||
ReturnCode res;
|
||||
if (res = Ogg_NextPage(stream)) return res;
|
||||
if ((res = Ogg_NextPage(stream))) return res;
|
||||
}
|
||||
}
|
||||
|
||||
@ -988,7 +988,7 @@ static bool Vorbis_ValidBlockSize(UInt32 size) {
|
||||
static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, UInt8 type) {
|
||||
UInt8 header[7];
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(ctx->Source, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
||||
|
||||
if (header[0] != type) return VORBIS_ERR_WRONG_HEADER;
|
||||
bool OK =
|
||||
@ -1000,7 +1000,7 @@ static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, UInt8 type) {
|
||||
static ReturnCode Vorbis_DecodeIdentifier(struct VorbisState* ctx) {
|
||||
UInt8 header[23];
|
||||
ReturnCode res;
|
||||
if (res = Stream_Read(ctx->Source, header, sizeof(header))) return res;
|
||||
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
||||
|
||||
UInt32 version = Stream_GetU32_LE(&header[0]);
|
||||
if (version != 0) return VORBIS_ERR_VERSION;
|
||||
@ -1026,19 +1026,19 @@ static ReturnCode Vorbis_DecodeComments(struct VorbisState* ctx) {
|
||||
struct Stream* stream = ctx->Source;
|
||||
|
||||
/* vendor name, followed by comments */
|
||||
if (res = Stream_ReadU32_LE(stream, &len)) return res;
|
||||
if (res = Stream_Skip(stream, len)) return res;
|
||||
if (res = Stream_ReadU32_LE(stream, &comments)) return res;
|
||||
if ((res = Stream_ReadU32_LE(stream, &len))) return res;
|
||||
if ((res = Stream_Skip(stream, len))) return res;
|
||||
if ((res = Stream_ReadU32_LE(stream, &comments))) return res;
|
||||
|
||||
for (i = 0; i < comments; i++) {
|
||||
/* comments such as artist, year, etc */
|
||||
if (res = Stream_ReadU32_LE(stream, &len)) return res;
|
||||
if (res = Stream_Skip(stream, len)) return res;
|
||||
if ((res = Stream_ReadU32_LE(stream, &len))) return res;
|
||||
if ((res = Stream_Skip(stream, len))) return res;
|
||||
}
|
||||
|
||||
/* check framing flag */
|
||||
UInt8 flag;
|
||||
if (res = stream->ReadU8(stream, &flag)) return res;
|
||||
if ((res = stream->ReadU8(stream, &flag))) return res;
|
||||
return (flag & 1) ? 0 : VORBIS_ERR_FRAMING;
|
||||
}
|
||||
|
||||
@ -1105,12 +1105,12 @@ ReturnCode Vorbis_DecodeHeaders(struct VorbisState* ctx) {
|
||||
ReturnCode res;
|
||||
UInt32 count;
|
||||
|
||||
if (res = Vorbis_CheckHeader(ctx, 1)) return res;
|
||||
if (res = Vorbis_DecodeIdentifier(ctx)) return res;
|
||||
if (res = Vorbis_CheckHeader(ctx, 3)) return res;
|
||||
if (res = Vorbis_DecodeComments(ctx)) return res;
|
||||
if (res = Vorbis_CheckHeader(ctx, 5)) return res;
|
||||
if (res = Vorbis_DecodeSetup(ctx)) return res;
|
||||
if ((res = Vorbis_CheckHeader(ctx, 1))) return res;
|
||||
if ((res = Vorbis_DecodeIdentifier(ctx))) return res;
|
||||
if ((res = Vorbis_CheckHeader(ctx, 3))) return res;
|
||||
if ((res = Vorbis_DecodeComments(ctx))) return res;
|
||||
if ((res = Vorbis_CheckHeader(ctx, 5))) return res;
|
||||
if ((res = Vorbis_DecodeSetup(ctx))) return res;
|
||||
|
||||
/* window calculations can be pre-computed here */
|
||||
count = ctx->BlockSizes[0] + ctx->BlockSizes[1];
|
||||
|
Loading…
x
Reference in New Issue
Block a user