Various compier warnings

gcc 5.4 and 7.1, Debug and Release builds
This commit is contained in:
Sergei Golubchik 2017-10-22 13:18:38 +02:00
parent 9d2e2d7533
commit 2aa51f528f
21 changed files with 48 additions and 210 deletions

View file

@ -20,6 +20,11 @@ IF(HAVE_C__Wvla)
SET(MY_WARNING_FLAGS "${MY_WARNING_FLAGS} -Wvla")
ENDIF()
MY_CHECK_C_COMPILER_FLAG("-Wno-format-truncation")
IF(HAVE_C__Wno_format_truncation)
SET(MY_WARNING_FLAGS "${MY_WARNING_FLAGS} -Wno-format-truncation")
ENDIF()
# Common warning flags for GCC and Clang
SET(MY_C_WARNING_FLAGS
"${MY_WARNING_FLAGS} -Wwrite-strings -Wdeclaration-after-statement")

View file

@ -5054,7 +5054,7 @@ xb_process_datadir(
callback */
{
ulint ret;
char dbpath[FN_REFLEN];
char dbpath[OS_FILE_MAX_PATH];
os_file_dir_t dir;
os_file_dir_t dbdir;
os_file_stat_t dbinfo;
@ -5120,8 +5120,7 @@ next_file_item_1:
goto next_datadir_item;
}
sprintf(dbpath, "%s/%s", path,
dbinfo.name);
snprintf(dbpath, sizeof(dbpath), "%s/%s", path, dbinfo.name);
srv_normalize_path_for_win(dbpath);
dbdir = os_file_opendir(dbpath, FALSE);

View file

@ -98,7 +98,8 @@ static struct my_option my_long_options[] =
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
void cleanup_and_exit(int exit_code)
static void cleanup_and_exit(int exit_code) __attribute__ ((noreturn));
static void cleanup_and_exit(int exit_code)
{
my_end(0);
exit(exit_code);

View file

@ -2469,8 +2469,8 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr,
case 2:
{
strmake(typestr, "ENUM(2 bytes)", typestr_length);
if (!ptr)
goto return_null;
if (!ptr)
goto return_null;
int32 i32= uint2korr(ptr);
my_b_printf(file, "%d", i32);

View file

@ -634,9 +634,6 @@ bool ROLE_GRANT_PAIR::init(MEM_ROOT *mem, char *username,
char *hostname, char *rolename,
bool with_admin_option)
{
if (!this)
return true;
size_t uname_l = safe_strlen(username);
size_t hname_l = safe_strlen(hostname);
size_t rname_l = safe_strlen(rolename);
@ -10516,7 +10513,6 @@ bool check_role_is_granted(const char *username,
DBUG_RETURN(result);
}
int fill_schema_enabled_roles(THD *thd, TABLE_LIST *tables, COND *cond)
{
TABLE *table= tables->table;

View file

@ -45,34 +45,17 @@ add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT -DPIVOT_SUPPORT -DUSE_TRY )
# OS specific C flags, definitions and source files.
#
IF(UNIX)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Bar: -Wfatal-errors removed (does not present in gcc on solaris10)
if(WITH_WARNINGS)
add_definitions(-Wall -Wextra -Wmissing-declarations)
#message(STATUS "CONNECT: GCC: All warnings enabled")
else()
add_definitions(-Wall -Wmissing-declarations)
add_definitions(-Wno-write-strings)
add_definitions(-Wno-unused-variable)
# Bar: -Wno-unused-but-set-variables commented (does not present on sol10)
# add_definitions(-Wno-unused-but-set-variable)
add_definitions(-Wno-unused-value)
add_definitions(-Wno-unused-function)
add_definitions(-Wno-parentheses)
#add_definitions(-Wno-missing-declarations)
# Bar: -Wno-int-to-pointer-cast commended (does not present in gcc on sol10)
# add_definitions(-Wno-int-to-pointer-cast)
# Bar: -Wno-narrowing commented (does not present in gcc on solaris10)
# add_definitions(-Wno-narrowing)
# This switch is for pure C only:
# add_definitions(-Wno-implicit-function-declaration)
# These switches are for C++ only
# add_definitions(-Wno-reorder)
#message(STATUS "CONNECT: GCC: Some warnings disabled")
endif(WITH_WARNINGS)
endif()
MY_CHECK_AND_SET_COMPILER_FLAG("-Wall -Wmissing-declarations")
if(NOT WITH_WARNINGS)
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-function")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-variable")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-value")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-parentheses")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-strict-aliasing")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-misleading-indentation")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-format-truncation")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough")
endif(NOT WITH_WARNINGS)
add_definitions( -DUNIX -DLINUX -DUBUNTU )

View file

@ -417,10 +417,10 @@ static PDTP pp;
static void MakeParm(int n);
static void MakeMMDD(int n);
static void MakeAMPM(int n);
static void MakeIn(char *);
static void MakeOut(char *);
static void Quotin(char *);
static void Quotout(char *);
static void MakeIn(const char *);
static void MakeOut(const char *);
static void Quotin(const char *);
static void Quotout(const char *);
/* Macros after this point can all be overridden by user definitions in
* section 1.
@ -1492,7 +1492,7 @@ void MakeAMPM(int n)
} /* end of MakeAMPM */
void MakeIn(char *text)
void MakeIn(const char *text)
{
if (!pp->InFmt)
return;
@ -1500,14 +1500,14 @@ void MakeIn(char *text)
strncat(pp->InFmt, text, (pp->Outsize - 1) - strlen(pp->InFmt));
} /* end of MakeIn */
void MakeOut(char *text)
void MakeOut(const char *text)
{
if (!pp->OutFmt) return;
strncat(pp->OutFmt, text, (pp->Outsize - 1) - strlen(pp->OutFmt));
} /* end of MakeOut */
void Quotin(char *text)
void Quotin(const char *text)
{
if (!pp->InFmt)
return;
@ -1516,7 +1516,7 @@ void Quotin(char *text)
pp->InFmt[strlen(pp->InFmt)-1] = '\0';
} /* end of Quotin */
void Quotout(char *text)
void Quotout(const char *text)
{
if (!pp->OutFmt)
return;

View file

@ -1510,7 +1510,7 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n,
if (!(g->Sarea = PlugAllocMem(g, ml))) {
char errmsg[MAX_STR];
sprintf(errmsg, MSG(WORK_AREA), g->Message);
snprintf(errmsg, sizeof(errmsg)-1, MSG(WORK_AREA), g->Message);
strcpy(g->Message, errmsg);
g->Sarea_Size = 0;
return true;

View file

@ -162,7 +162,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
/*******************************************************************/
if (worksize && !(g->Sarea = PlugAllocMem(g, worksize))) {
char errmsg[MAX_STR];
sprintf(errmsg, MSG(WORK_AREA), g->Message);
snprintf(errmsg, sizeof(errmsg) - 1, MSG(WORK_AREA), g->Message);
strcpy(g->Message, errmsg);
g->Sarea_Size = 0;
} else

View file

@ -27,9 +27,9 @@
char *msglang(void);
char *GetMsgid(int id)
const char *GetMsgid(int id)
{
char *p = NULL;
const char *p = NULL;
// This conditional until a real fix is found for MDEV-7304
#if defined(FRENCH)
@ -55,7 +55,8 @@ char *GetMsgid(int id)
int GetRcString(int id, char *buf, int bufsize)
{
char *p = NULL, msg[32];
const char *p = NULL;
char msg[32];
if (!(p = GetMsgid(id))) {
sprintf(msg, "ID=%d unknown", id);

View file

@ -5,7 +5,7 @@
extern "C" {
#endif
char *GetMsgid(int id);
const char *GetMsgid(int id);
int GetRcString(int id, char *buf, int bufsize);
#ifdef __cplusplus

View file

@ -203,12 +203,12 @@ bool TDBMUL::InitFileNames(PGLOBAL g)
// Data files can be imported from Windows (having CRLF)
if (*p == '\n' || *p == '\r') {
// is this enough for Unix ???
*p--; // Eliminate ending CR or LF character
p--; // Eliminate ending CR or LF character
if (p >= filename)
// is this enough for Unix ???
if (*p == '\n' || *p == '\r')
*p--; // Eliminate ending CR or LF character
p--; // Eliminate ending CR or LF character
} // endif p

View file

@ -1374,7 +1374,7 @@ bool TYPVAL<PSZ>::SetValue_char(const char *cp, int n)
} else if (cp != Strp) {
const char *p = cp + n - 1;
for (p; p >= cp; p--, n--)
for (; p >= cp; p--, n--)
if (*p && *p != ' ')
break;

View file

@ -343,6 +343,7 @@ else()
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-exceptions")
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-rtti")
MY_CHECK_AND_SET_COMPILER_FLAG("-felide-constructors")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough")
endif()
set_source_files_properties(${MRN_SOURCES} PROPERTIES
COMPILE_FLAGS "${MYSQL_CFLAGS} ${MRN_CXX_COMPILE_FLAGS}")

View file

@ -154,7 +154,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
MY_CHECK_AND_SET_COMPILER_FLAG("-Wformat=2")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wstrict-aliasing=2")
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-strict-aliasing")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wdisabled-optimization")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-disabled-optimization")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wfloat-equal")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wpointer-arith")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wdeclaration-after-statement")
@ -165,6 +165,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
MY_CHECK_AND_SET_COMPILER_FLAG("-fexceptions")
MY_CHECK_AND_SET_COMPILER_FLAG("-fimplicit-templates")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-clobbered")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough")
endif()
if(NOT DEFINED CMAKE_C_COMPILE_OPTIONS_PIC)

View file

@ -32,7 +32,6 @@ Cursor *CursorFactory::open(const Trie &trie,
UInt32 offset,
UInt32 limit,
UInt32 flags) {
GRN_DAT_THROW_IF(PARAM_ERROR, &trie == NULL);
const UInt32 cursor_type = flags & CURSOR_TYPE_MASK;
switch (cursor_type) {

View file

@ -544,7 +544,7 @@ regexp_next(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
grn_obj *buffer = &(tokenizer->buffer);
const char *current = tokenizer->next;
const char *end = tokenizer->end;
const const uint_least8_t *char_types = tokenizer->char_types;
const uint_least8_t *char_types = tokenizer->char_types;
grn_tokenize_mode mode = tokenizer->query->tokenize_mode;
grn_bool is_begin = tokenizer->is_begin;
grn_bool is_start_token = tokenizer->is_start_token;

View file

@ -1,3 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(snappy_srcs

View file

@ -19870,98 +19870,6 @@ if test -n "$CFLAG_VISIBILITY" && test "$is_w32" = no; then
AM_CFLAGS="$AM_CFLAGS $CFLAG_VISIBILITY"
fi
if test "$GCC" = yes ; then
# Enable as much warnings as possible. These commented warnings won't
# work for this package though:
# * -Wunreachable-code breaks several assert(0) cases, which are
# backed up with "return LZMA_PROG_ERROR".
# * -Wcast-qual would break various things where we need a non-const
# pointer although we don't modify anything through it.
# * -Wcast-align breaks optimized CRC32 and CRC64 implementation
# on some architectures (not on x86), where this warning is bogus,
# because we take care of correct alignment.
# * -Winline, -Wdisabled-optimization, -Wunsafe-loop-optimizations
# don't seem so useful here; at least the last one gives some
# warnings which are not bugs.
for NEW_FLAG in \
-Wall \
-Wextra \
-Wformat=2 \
-Winit-self \
-Wmissing-include-dirs \
-Wstrict-aliasing \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wpointer-arith \
-Wbad-function-cast \
-Wwrite-strings \
-Wlogical-op \
-Waggregate-return \
-Wstrict-prototypes \
-Wold-style-definition \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wmissing-noreturn \
-Wredundant-decls
do
{ $as_echo "$as_me:$LINENO: checking if $CC accepts $NEW_FLAG" >&5
$as_echo_n "checking if $CC accepts $NEW_FLAG... " >&6; }
OLD_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $NEW_FLAG"
cat >conftest.$ac_ext <<_ACEOF
void foo(void) { }
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$ac_try_echo") >&5
(eval "$ac_compile") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest.$ac_objext; then
AM_CFLAGS="$AM_CFLAGS $NEW_FLAG"
{ $as_echo "$as_me:$LINENO: result: yes" >&5
$as_echo "yes" >&6; }
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
{ $as_echo "$as_me:$LINENO: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$OLD_CFLAGS"
done
# Check whether --enable-werror was given.
if test "${enable_werror+set}" = set; then
enableval=$enable_werror;
else
enable_werror=no
fi
if test "x$enable_werror" = "xyes"; then
AM_CFLAGS="$AM_CFLAGS -Werror"
fi
fi
###############################################################################
# Create the makefiles and config.h
###############################################################################

View file

@ -569,63 +569,6 @@ if test -n "$CFLAG_VISIBILITY" && test "$is_w32" = no; then
AM_CFLAGS="$AM_CFLAGS $CFLAG_VISIBILITY"
fi
if test "$GCC" = yes ; then
# Enable as much warnings as possible. These commented warnings won't
# work for this package though:
# * -Wunreachable-code breaks several assert(0) cases, which are
# backed up with "return LZMA_PROG_ERROR".
# * -Wcast-qual would break various things where we need a non-const
# pointer although we don't modify anything through it.
# * -Wcast-align breaks optimized CRC32 and CRC64 implementation
# on some architectures (not on x86), where this warning is bogus,
# because we take care of correct alignment.
# * -Winline, -Wdisabled-optimization, -Wunsafe-loop-optimizations
# don't seem so useful here; at least the last one gives some
# warnings which are not bugs.
for NEW_FLAG in \
-Wall \
-Wextra \
-Wformat=2 \
-Winit-self \
-Wmissing-include-dirs \
-Wstrict-aliasing \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wpointer-arith \
-Wbad-function-cast \
-Wwrite-strings \
-Wlogical-op \
-Waggregate-return \
-Wstrict-prototypes \
-Wold-style-definition \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wmissing-noreturn \
-Wredundant-decls
do
AC_MSG_CHECKING([if $CC accepts $NEW_FLAG])
OLD_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $NEW_FLAG"
AC_COMPILE_IFELSE([void foo(void) { }], [
AM_CFLAGS="$AM_CFLAGS $NEW_FLAG"
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
CFLAGS="$OLD_CFLAGS"
done
AC_ARG_ENABLE([werror],
AC_HELP_STRING([--enable-werror], [Enable -Werror to abort
compilation on all compiler warnings.]),
[], [enable_werror=no])
if test "x$enable_werror" = "xyes"; then
AM_CFLAGS="$AM_CFLAGS -Werror"
fi
fi
###############################################################################
# Create the makefiles and config.h
###############################################################################

View file

@ -1021,7 +1021,7 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES],
# to the aix ld manual.
m4_defun([_LT_SYS_MODULE_PATH_AIX],
[m4_require([_LT_DECL_SED])dnl
AC_LINK_IFELSE(AC_LANG_PROGRAM,[
AC_LINK_IFELSE([AC_LANG_PROGRAM],[
lt_aix_libpath_sed='
/Import File Strings/,/^$/ {
/^0/ {
@ -4826,9 +4826,9 @@ _LT_EOF
# implicitly export all symbols.
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
AC_LINK_IFELSE(int foo(void) {},
AC_LINK_IFELSE([AC_LANG_SOURCE([int foo(void) {}]),
_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
)
])
LDFLAGS="$save_LDFLAGS"
else
_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'