Skip to content

Commit

Permalink
Better default C-flags for Unix builds
Browse files Browse the repository at this point in the history
Add some default C-flags that give better warnings when compiling and
fix errors found during the process. Includes zeniko/unarr#6 written by
Bastien Nocera.
  • Loading branch information
selmf committed Aug 18, 2017
1 parent 1b3133a commit d65676a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 26 deletions.
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ endif()
find_package(ZLIB)
find_package(BZip2)

if(UNIX OR MINGW)
add_compile_options(-fomit-frame-pointer)
if(UNIX OR MINGW OR MSYS)
add_compile_options(-Wall -Wextra -pedantic
-Wstrict-prototypes -Wmissing-prototypes
-Werror-implicit-function-declaration
-fomit-frame-pointer -flto)
add_definitions(-D_FILE_OFFSET_BITS=64)

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Wno-missing-field-initializers)
list(APPEND CMAKE_SHARED_LINKER_FLAGS -flto)
list(APPEND CMAKE_STATIC_LINKER_FLAGS -flto)
endif()
endif()

# Sources
Expand Down Expand Up @@ -73,7 +82,7 @@ set(SOURCES rar/uncompress-rar.c
lzmasdk/LzmaDec.c
lzmasdk/Ppmd7Dec.c
lzmasdk/Ppmd8Dec.c
common/custalloc.c
#common/custalloc.c
common/unarr.c
common/stream.c
common/conv.c
Expand Down
6 changes: 3 additions & 3 deletions lzmasdk/CpuArch.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
: "0" (function)) ;

#endif

#else

int CPUInfo[4];
Expand Down Expand Up @@ -137,7 +137,7 @@ int x86cpuid_GetFirm(const Cx86cpuid *p)
return -1;
}

Bool CPU_Is_InOrder()
Bool CPU_Is_InOrder(void)
{
Cx86cpuid p;
int firm;
Expand Down Expand Up @@ -178,7 +178,7 @@ static Bool CPU_Sys_Is_SSE_Supported()
#define CHECK_SYS_SSE_SUPPORT
#endif

Bool CPU_Is_Aes_Supported()
Bool CPU_Is_Aes_Supported(void)
{
Cx86cpuid p;
CHECK_SYS_SSE_SUPPORT
Expand Down
4 changes: 2 additions & 2 deletions lzmasdk/CpuArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ int x86cpuid_GetFirm(const Cx86cpuid *p);
#define x86cpuid_GetModel(p) (((p)->ver >> 4) & 0xF00F)
#define x86cpuid_GetStepping(p) ((p)->ver & 0xF)

Bool CPU_Is_InOrder();
Bool CPU_Is_Aes_Supported();
Bool CPU_Is_InOrder(void);
Bool CPU_Is_Aes_Supported(void);

#endif

Expand Down
14 changes: 7 additions & 7 deletions lzmasdk/LzmaDec.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
Byte *dic = p->dic;
SizeT dicBufSize = p->dicBufSize;
SizeT dicPos = p->dicPos;

UInt32 processedPos = p->processedPos;
UInt32 checkDicSize = p->checkDicSize;
unsigned len = 0;
Expand Down Expand Up @@ -356,7 +356,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
{
NORMALIZE
range >>= 1;

{
UInt32 t;
code -= range;
Expand Down Expand Up @@ -715,7 +715,7 @@ static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
p->needFlush = 0;
}

void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
{
p->needFlush = 1;
p->remainLen = 0;
Expand Down Expand Up @@ -755,7 +755,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
SizeT inSize = *srcLen;
(*srcLen) = 0;
LzmaDec_WriteRem(p, dicLimit);

*status = LZMA_STATUS_NOT_SPECIFIED;

while (p->remainLen != kMatchSpecLenStart)
Expand Down Expand Up @@ -801,7 +801,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr

if (p->needInitState)
LzmaDec_InitStateReal(p);

if (p->tempBufSize == 0)
{
SizeT processed;
Expand Down Expand Up @@ -932,12 +932,12 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
{
UInt32 dicSize;
Byte d;

if (size < LZMA_PROPS_SIZE)
return SZ_ERROR_UNSUPPORTED;
else
dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);

if (dicSize < LZMA_DIC_MIN)
dicSize = LZMA_DIC_MIN;
p->dicSize = dicSize;
Expand Down
4 changes: 2 additions & 2 deletions rar/parse-rar.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ static char *rar_conv_unicode_to_utf8(const char *data, uint16_t len)
#define Check(cond) if (!(cond)) { free(str); return NULL; } else ((void)0)

uint8_t highbyte, flagbyte, flagbits, size, length, i;
const uint8_t *in = (uint8_t *)data + strlen(data) + 1;
const uint8_t *end_in = (uint8_t *)data + len;
const uint8_t *in = (const uint8_t *)data + strlen(data) + 1;
const uint8_t *end_in = (const uint8_t *)data + len;
char *str = calloc(len + 1, 3);
char *out = str;
char *end_out = str + len * 3;
Expand Down
6 changes: 3 additions & 3 deletions rar/rarvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct RARProgram_s {

/* Program building */

RARProgram *RARCreateProgram()
RARProgram *RARCreateProgram(void)
{
return calloc(1, sizeof(RARProgram));
}
Expand Down Expand Up @@ -416,7 +416,7 @@ void RARVirtualMachineWrite8(RARVirtualMachine *vm, uint32_t address, uint8_t va

static uint32_t _RARGetOperand(RARVirtualMachine *vm, uint8_t addressingmode, uint32_t value, bool bytemode)
{
if (RARRegisterAddressingMode(0) <= addressingmode && addressingmode <= RARRegisterAddressingMode(7)) {
if (/*RARRegisterAddressingMode(0) <= addressingmode && */addressingmode <= RARRegisterAddressingMode(7)) {
uint32_t result = vm->registers[addressingmode % 8];
if (bytemode)
result = result & 0xFF;
Expand All @@ -443,7 +443,7 @@ static uint32_t _RARGetOperand(RARVirtualMachine *vm, uint8_t addressingmode, ui

static void _RARSetOperand(RARVirtualMachine *vm, uint8_t addressingmode, uint32_t value, bool bytemode, uint32_t data)
{
if (RARRegisterAddressingMode(0) <= addressingmode && addressingmode <= RARRegisterAddressingMode(7)) {
if (/*RARRegisterAddressingMode(0) <= addressingmode &&*/ addressingmode <= RARRegisterAddressingMode(7)) {
if (bytemode)
data = data & 0xFF;
vm->registers[addressingmode % 8] = data;
Expand Down
2 changes: 1 addition & 1 deletion rar/rarvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ enum {
RARNumberOfInstructions = 40,
};

RARProgram *RARCreateProgram();
RARProgram *RARCreateProgram(void);
void RARDeleteProgram(RARProgram *prog);
bool RARProgramAddInstr(RARProgram *prog, uint8_t instruction, bool bytemode);
bool RARSetLastInstrOperands(RARProgram *prog, uint8_t addressingmode1, uint32_t value1, uint8_t addressingmode2, uint32_t value2);
Expand Down
6 changes: 3 additions & 3 deletions rar/uncompress-rar.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static uint8_t rar_decode_audio(struct AudioState *state, int8_t *channeldelta,
return byte;
}

int64_t rar_expand_v2(ar_archive_rar *rar, int64_t end)
static int64_t rar_expand_v2(ar_archive_rar *rar, int64_t end)
{
static const uint8_t lengthbases[] =
{ 0, 1, 2, 3, 4, 5, 6,
Expand Down Expand Up @@ -586,7 +586,7 @@ static bool rar_parse_codes(ar_archive_rar *rar)
if (!br_bits(rar, 1))
memset(uncomp_v3->lengthtable, 0, sizeof(uncomp_v3->lengthtable));
memset(&bitlengths, 0, sizeof(bitlengths));
for (i = 0; i < sizeof(bitlengths); i++) {
for (i = 0; i < (int)sizeof(bitlengths); i++) {
if (!br_check(rar, 4))
return false;
bitlengths[i] = (uint8_t)br_bits(rar, 4);
Expand All @@ -595,7 +595,7 @@ static bool rar_parse_codes(ar_archive_rar *rar)
return false;
zerocount = (uint8_t)br_bits(rar, 4);
if (zerocount) {
for (j = 0; j < zerocount + 2 && i < sizeof(bitlengths); j++) {
for (j = 0; j < zerocount + 2 && i < (int)sizeof(bitlengths); j++) {
bitlengths[i++] = 0;
}
i--;
Expand Down
2 changes: 1 addition & 1 deletion zip/parse-zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ off64_t zip_find_end_of_central_directory(ar_stream *stream)
filesize = ar_tell(stream);

while (fromend < UINT16_MAX + ZIP_END_OF_CENTRAL_DIR_SIZE && fromend < filesize) {
count = (int)(filesize - fromend < sizeof(data) ? filesize - fromend : sizeof(data));
count = (filesize - fromend < (int)sizeof(data) ? filesize - fromend : (int)sizeof(data));
fromend += count;
if (count < ZIP_END_OF_CENTRAL_DIR_SIZE)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion zip/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static bool zip_uncompress(ar_archive *ar, void *buffer, size_t count)
return true;
}

size_t zip_get_global_comment(ar_archive *ar, void *buffer, size_t count)
static size_t zip_get_global_comment(ar_archive *ar, void *buffer, size_t count)
{
ar_archive_zip *zip = (ar_archive_zip *)ar;
if (!zip->comment_size)
Expand Down

0 comments on commit d65676a

Please sign in to comment.