Skip to content

Commit

Permalink
WARNINGS: fix against set of -W options (#38)
Browse files Browse the repository at this point in the history
* make __attribute__((fallthrough)) more portable for GCC (>= 7) and CLANG (>= 10)
  • Loading branch information
echasseur-gpfw committed Apr 19, 2022
1 parent 96b11fc commit ea25ea0
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 47 deletions.
3 changes: 1 addition & 2 deletions source/lib/common/private/gpr_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ int read_from_file(gpr_buffer* buffer, const char* file_path, gpr_malloc malloc_
return -1;
}

long result = fread(buffer->buffer, 1, buffer->size, fIN);
if (result != buffer->size)
if (fread(buffer->buffer, 1, buffer->size, fIN) != buffer->size)
{
free_function(buffer->buffer);
fputs ("Reading error", stderr);
Expand Down
4 changes: 2 additions & 2 deletions source/lib/common/private/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

TIMER LogTimer;

bool LogInit()
bool LogInit(void)
{
InitTimer(&LogTimer);

Expand Down Expand Up @@ -54,7 +54,7 @@ int LogPrint(const char* format, ... )
}
#endif // LogPrint

bool LogUninit()
bool LogUninit(void)
{
return true;
}
4 changes: 2 additions & 2 deletions source/lib/common/private/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
extern "C" {
#endif

bool LogInit();
bool LogInit(void);

#ifndef LogPrint
int LogPrint(const char* format, ... );
#endif

bool LogUninit();
bool LogUninit(void);

#define TIMESTAMP(x, y) TIMESTAMP_##y(x)

Expand Down
2 changes: 1 addition & 1 deletion source/lib/dng_sdk/dng_lossless_jpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ inline void dng_lossless_decoder::HuffExtend (int32 &x, int32 s)

if (x < (0x08000 >> (16 - s)))
{
x += (-1 << s) + 1;
x += -(1 << s) + 1;
}

}
Expand Down
8 changes: 4 additions & 4 deletions source/lib/dng_sdk/dng_misc_opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,28 @@ class dng_area_spec

/// The first plane.

const uint32 Plane () const
uint32 Plane () const
{
return fPlane;
}

/// The total number of planes.

const uint32 Planes () const
uint32 Planes () const
{
return fPlanes;
}

/// The row pitch (i.e., stride). A pitch of 1 means all rows.

const uint32 RowPitch () const
uint32 RowPitch () const
{
return fRowPitch;
}

/// The column pitch (i.e., stride). A pitch of 1 means all columns.

const uint32 ColPitch () const
uint32 ColPitch () const
{
return fColPitch;
}
Expand Down
2 changes: 1 addition & 1 deletion source/lib/dng_sdk/dng_negative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@ void dng_negative::SetFujiMosaic6x6 (uint32 phase)
info.fCFAPattern [5] [4] = color2;
info.fCFAPattern [5] [5] = color1;

DNG_REQUIRE (phase >= 0 && phase < patSize * patSize,
DNG_REQUIRE (phase < patSize * patSize,
"Bad phase in SetFujiMosaic6x6.");

if (phase > 0)
Expand Down
2 changes: 1 addition & 1 deletion source/lib/dng_sdk/dng_resample.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class dng_resample_coords
return fCoords->Buffer_int32 () + (index - fOrigin);
}

const int32 Pixel (int32 index) const
int32 Pixel (int32 index) const
{
return Coords (index) [0] >> kResampleSubsampleBits;
}
Expand Down
6 changes: 6 additions & 0 deletions source/lib/expat_lib/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#define PTRFASTCALL __attribute__((regparm(3)))
#endif

#if defined(__GNUC__) && __GNUC__ >= 7 || defined(__clang__) && __clang_major__ >= 10
#define FALL_THROUGH __attribute__ ((fallthrough))
#else
#define FALL_THROUGH ((void)0)
#endif

/* Using __fastcall seems to have an unexpected negative effect under
MS VC++, especially for function pointers, so we won't use it for
now on that platform. It may be reconsidered for a future release
Expand Down
12 changes: 9 additions & 3 deletions source/lib/expat_lib/xmlparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
errorCode = XML_ERROR_NO_MEMORY;
return XML_STATUS_ERROR;
}
FALL_THROUGH;
default:
ps_parsing = XML_PARSING;
}
Expand All @@ -1528,6 +1529,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
case XML_INITIALIZED:
case XML_PARSING:
ps_parsing = XML_FINISHED;
FALL_THROUGH;
/* fall through */
default:
return XML_STATUS_OK;
Expand Down Expand Up @@ -1564,7 +1566,8 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
ps_parsing = XML_FINISHED;
return XML_STATUS_OK;
}
/* fall through */
FALL_THROUGH;
/* fall through */
default:
result = XML_STATUS_OK;
}
Expand Down Expand Up @@ -1628,6 +1631,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
errorCode = XML_ERROR_NO_MEMORY;
return XML_STATUS_ERROR;
}
FALL_THROUGH;
default:
ps_parsing = XML_PARSING;
}
Expand Down Expand Up @@ -2370,7 +2374,6 @@ doContent(XML_Parser parser,
break;
}
case XML_TOK_START_TAG_NO_ATTS:
/* fall through */
case XML_TOK_START_TAG_WITH_ATTS:
{
TAG *tag;
Expand Down Expand Up @@ -2439,7 +2442,6 @@ doContent(XML_Parser parser,
break;
}
case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
/* fall through */
case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
{
const char *rawName = s + enc->minBytesPerChar;
Expand Down Expand Up @@ -3895,6 +3897,7 @@ doProlog(XML_Parser parser,
handleDefault = XML_FALSE;
goto alreadyChecked;
}
FALL_THROUGH;
/* fall through */
case XML_ROLE_ENTITY_PUBLIC_ID:
if (!XmlIsPublicId(enc, s, next, eventPP))
Expand Down Expand Up @@ -4197,6 +4200,7 @@ doProlog(XML_Parser parser,
return XML_ERROR_NO_MEMORY;
declEntity->publicId = NULL;
}
FALL_THROUGH;
/* fall through */
#endif /* XML_DTD */
case XML_ROLE_ENTITY_SYSTEM_ID:
Expand Down Expand Up @@ -4977,6 +4981,7 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
break;
case XML_TOK_TRAILING_CR:
next = ptr + enc->minBytesPerChar;
FALL_THROUGH;
/* fall through */
case XML_TOK_ATTRIBUTE_VALUE_S:
case XML_TOK_DATA_NEWLINE:
Expand Down Expand Up @@ -5181,6 +5186,7 @@ storeEntityValue(XML_Parser parser,
break;
case XML_TOK_TRAILING_CR:
next = entityTextPtr + enc->minBytesPerChar;
FALL_THROUGH;
/* fall through */
case XML_TOK_DATA_NEWLINE:
if (pool->end == pool->ptr && !poolGrow(pool)) {
Expand Down
37 changes: 25 additions & 12 deletions source/lib/expat_lib/xmltok.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ struct normal_encoding {
E ## isInvalid3, \
E ## isInvalid4

#define EMPTY_VTABLE \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL

static int FASTCALL checkCharRefNumber(int);

#include "xmltok_impl.h"
Expand Down Expand Up @@ -467,7 +478,7 @@ static const struct normal_encoding latin1_encoding_ns = {
#include "asciitab.h"
#include "latin1tab.h"
},
STANDARD_VTABLE(sb_)
STANDARD_VTABLE(sb_) EMPTY_VTABLE
};

#endif
Expand All @@ -480,7 +491,7 @@ static const struct normal_encoding latin1_encoding = {
#undef BT_COLON
#include "latin1tab.h"
},
STANDARD_VTABLE(sb_)
STANDARD_VTABLE(sb_) EMPTY_VTABLE
};

static void PTRCALL
Expand All @@ -500,7 +511,7 @@ static const struct normal_encoding ascii_encoding_ns = {
#include "asciitab.h"
/* BT_NONXML == 0 */
},
STANDARD_VTABLE(sb_)
STANDARD_VTABLE(sb_) EMPTY_VTABLE
};

#endif
Expand All @@ -513,7 +524,7 @@ static const struct normal_encoding ascii_encoding = {
#undef BT_COLON
/* BT_NONXML == 0 */
},
STANDARD_VTABLE(sb_)
STANDARD_VTABLE(sb_) EMPTY_VTABLE
};

static int PTRFASTCALL
Expand Down Expand Up @@ -557,6 +568,7 @@ E ## toUtf8(const ENCODING *enc, \
*(*toP)++ = lo; \
break; \
} \
__attribute((fallthrough)); \
/* fall through */ \
case 0x1: case 0x2: case 0x3: \
case 0x4: case 0x5: case 0x6: case 0x7: \
Expand Down Expand Up @@ -726,7 +738,7 @@ static const struct normal_encoding little2_encoding_ns = {
#include "asciitab.h"
#include "latin1tab.h"
},
STANDARD_VTABLE(little2_)
STANDARD_VTABLE(little2_) EMPTY_VTABLE
};

#endif
Expand All @@ -745,7 +757,7 @@ static const struct normal_encoding little2_encoding = {
#undef BT_COLON
#include "latin1tab.h"
},
STANDARD_VTABLE(little2_)
STANDARD_VTABLE(little2_) EMPTY_VTABLE
};

#if BYTEORDER != 4321
Expand All @@ -758,7 +770,7 @@ static const struct normal_encoding internal_little2_encoding_ns = {
#include "iasciitab.h"
#include "latin1tab.h"
},
STANDARD_VTABLE(little2_)
STANDARD_VTABLE(little2_) EMPTY_VTABLE
};

#endif
Expand All @@ -771,7 +783,7 @@ static const struct normal_encoding internal_little2_encoding = {
#undef BT_COLON
#include "latin1tab.h"
},
STANDARD_VTABLE(little2_)
STANDARD_VTABLE(little2_) EMPTY_VTABLE
};

#endif
Expand Down Expand Up @@ -867,7 +879,7 @@ static const struct normal_encoding big2_encoding_ns = {
#include "asciitab.h"
#include "latin1tab.h"
},
STANDARD_VTABLE(big2_)
STANDARD_VTABLE(big2_) EMPTY_VTABLE
};

#endif
Expand All @@ -886,7 +898,7 @@ static const struct normal_encoding big2_encoding = {
#undef BT_COLON
#include "latin1tab.h"
},
STANDARD_VTABLE(big2_)
STANDARD_VTABLE(big2_) EMPTY_VTABLE
};

#if BYTEORDER != 1234
Expand All @@ -899,7 +911,7 @@ static const struct normal_encoding internal_big2_encoding_ns = {
#include "iasciitab.h"
#include "latin1tab.h"
},
STANDARD_VTABLE(big2_)
STANDARD_VTABLE(big2_) EMPTY_VTABLE
};

#endif
Expand All @@ -912,7 +924,7 @@ static const struct normal_encoding internal_big2_encoding = {
#undef BT_COLON
#include "latin1tab.h"
},
STANDARD_VTABLE(big2_)
STANDARD_VTABLE(big2_) EMPTY_VTABLE
};

#endif
Expand Down Expand Up @@ -1528,6 +1540,7 @@ initScan(const ENCODING * const *encodingTable,
if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
&& state == XML_CONTENT_STATE)
break;
__attribute((fallthrough));
/* fall through */
case 0x00:
case 0x3C:
Expand Down
Loading

0 comments on commit ea25ea0

Please sign in to comment.