Skip to content

Commit

Permalink
Bug#53445: Build with -Wall and fix warnings that it generates
Browse files Browse the repository at this point in the history
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.

One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.

There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.
  • Loading branch information
Davi Arnaut authored and Davi Arnaut committed Jul 2, 2010
1 parent 6d5b440 commit 93fb8bb
Show file tree
Hide file tree
Showing 67 changed files with 257 additions and 362 deletions.
13 changes: 5 additions & 8 deletions BUILD/SETUP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,19 @@ SSL_LIBRARY=--with-ssl

if [ "x$warning_mode" != "xpedantic" ]; then
# Both C and C++ warnings
warnings="-Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W"
warnings="$warnings -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare"
warnings="$warnings -Wwrite-strings -Wunused-function -Wunused-label -Wunused-value -Wunused-variable"
warnings="-Wall -Wextra -Wunused -Wwrite-strings"

# For more warnings, uncomment the following line
# warnings="$global_warnings -Wshadow"
# warnings="$warnings -Wshadow"

# C warnings
c_warnings="$warnings -Wunused-parameter"
c_warnings="$warnings"
# C++ warnings
cxx_warnings="$warnings"
cxx_warnings="$warnings -Wno-unused-parameter"
# cxx_warnings="$cxx_warnings -Woverloaded-virtual -Wsign-promo"
cxx_warnings="$cxx_warnings -Wreorder"
cxx_warnings="$cxx_warnings -Wctor-dtor-privacy -Wnon-virtual-dtor"
# Added unless --with-debug=full
debug_extra_cflags="-O0 -g3 -gdwarf-2" #1 -Wuninitialized"
debug_extra_cflags="-O0 -g3 -gdwarf-2"
else
warnings="-W -Wall -ansi -pedantic -Wno-long-long -Wno-unused -D_POSIX_SOURCE"
c_warnings="$warnings"
Expand Down
23 changes: 13 additions & 10 deletions BUILD/check-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,17 @@ check_cpu () {
cc=$CC
fi

cc_ver=`$cc --version | sed 1q`
cc_verno=`echo $cc_ver | sed -e 's/^.*(GCC)//g; s/[^0-9. ]//g; s/^ *//g; s/ .*//g'`
set -- `echo $cc_verno | tr '.' ' '`
cc_major=$1
cc_minor=$2
cc_patch=$3
cc_comp=`expr $cc_major '*' 100 '+' $cc_minor`

# check if compiler is gcc and dump its version
cc_verno=`$cc -dumpversion 2>/dev/null`
if test "x$?" = "x0" ; then
set -- `echo $cc_verno | tr '.' ' '`
cc_ver="GCC"
cc_major=$1
cc_minor=$2
cc_patch=$3
cc_comp=`expr $cc_major '*' 100 '+' $cc_minor`
fi

case "$cc_ver--$cc_verno" in
*GCC*)
# different gcc backends (and versions) have different CPU flags
Expand Down Expand Up @@ -229,7 +232,7 @@ check_cpu () {
fi
while [ "$cpu_arg" ] ; do
printf "testing $cpu_arg ... " >&2

# compile check
eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null
if test "x$?" = "x0" ; then
Expand All @@ -243,5 +246,5 @@ check_cpu () {
done
rm __test.*
}

check_cpu
1 change: 0 additions & 1 deletion client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ extern "C" {
#endif
#endif

#undef bcmp // Fix problem with new readline
#if defined(__WIN__)
#include <conio.h>
#elif !defined(__NETWARE__)
Expand Down
21 changes: 9 additions & 12 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5780,7 +5780,7 @@ int read_command(struct st_command** command_ptr)
(struct st_command*) my_malloc(sizeof(*command),
MYF(MY_WME|MY_ZEROFILL))) ||
insert_dynamic(&q_lines, (uchar*) &command))
die(NullS);
die("Out of memory");
command->type= Q_UNKNOWN;

read_command_buf[0]= 0;
Expand Down Expand Up @@ -6260,7 +6260,7 @@ void init_win_path_patterns()
}

if (insert_dynamic(&patterns, (uchar*) &p))
die(NullS);
die("Out of memory");

DBUG_PRINT("info", ("p: %s", p));
while (*p)
Expand Down Expand Up @@ -9331,8 +9331,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
for (i=1 ; i <= found_sets ; i++)
{
pos=from[found_set[i-1].table_offset];
rep_str[i].found= !bcmp((const uchar*) pos,
(const uchar*) "\\^", 3) ? 2 : 1;
rep_str[i].found= !memcmp(pos, "\\^", 3) ? 2 : 1;
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
Expand Down Expand Up @@ -9460,8 +9459,8 @@ void copy_bits(REP_SET *to,REP_SET *from)

int cmp_bits(REP_SET *set1,REP_SET *set2)
{
return bcmp((uchar*) set1->bits,(uchar*) set2->bits,
sizeof(uint) * set1->size_of_bits);
return memcmp(set1->bits, set2->bits,
sizeof(uint) * set1->size_of_bits);
}


Expand Down Expand Up @@ -9530,17 +9529,15 @@ int find_found(FOUND_SET *found_set,uint table_offset, int found_offset)

uint start_at_word(char * pos)
{
return (((!bcmp((const uchar*) pos, (const uchar*) "\\b",2) && pos[2]) ||
!bcmp((const uchar*) pos, (const uchar*) "\\^", 2)) ? 1 : 0);
return (((!memcmp(pos, "\\b",2) && pos[2]) ||
!memcmp(pos, "\\^", 2)) ? 1 : 0);
}

uint end_of_word(char * pos)
{
char * end=strend(pos);
return ((end > pos+2 && !bcmp((const uchar*) end-2,
(const uchar*) "\\b", 2)) ||
(end >= pos+2 && !bcmp((const uchar*) end-2,
(const uchar*) "\\$",2))) ? 1 : 0;
return ((end > pos+2 && !memcmp(end-2, "\\b", 2)) ||
(end >= pos+2 && !memcmp(end-2, "\\$",2))) ? 1 : 0;
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion cmd-line-utils/readline/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ noinst_HEADERS = readline.h chardefs.h keymaps.h \

EXTRA_DIST= emacs_keymap.c vi_keymap.c

DEFS = -DMYSQL_CLIENT_NO_THREADS -DHAVE_CONFIG_H -DNO_KILL_INTR
DEFS = -DMYSQL_CLIENT_NO_THREADS -DHAVE_CONFIG_H -DNO_KILL_INTR -D_GNU_SOURCE=1

# Don't update the files from bitkeeper
%::SCCS/s.%
2 changes: 2 additions & 0 deletions cmd-line-utils/readline/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ _rl_input_available ()
return (_kbhit ());
#endif

#if !defined (HAVE_SELECT)
return 0;
#endif
}

int
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ MYSQL_TYPE_QSORT
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF

AC_CHECK_FUNCS(alarm bcmp bfill bmove bsearch bzero \
AC_CHECK_FUNCS(alarm bfill bmove bsearch bzero \
chsize cuserid fchmod fcntl \
fconvert fdatasync fesetround finite fpresetsticky fpsetmask fsync ftruncate \
getcwd gethostbyaddr_r gethostbyname_r getpass getpassphrase getpwnam \
Expand Down
6 changes: 3 additions & 3 deletions extra/comp_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ static struct message *find_message(struct errors *err, const char *lang,
static ha_checksum checksum_format_specifier(const char* msg)
{
ha_checksum chksum= 0;
const char* p= msg;
const char* start= 0;
int num_format_specifiers= 0;
const uchar* p= (const uchar*) msg;
const uchar* start= NULL;
uint32 num_format_specifiers= 0;
while (*p)
{

Expand Down
12 changes: 6 additions & 6 deletions extra/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ static REPLACE *init_replace(char * *from, char * *to,uint count,
for (i=1 ; i <= found_sets ; i++)
{
pos=from[found_set[i-1].table_offset];
rep_str[i].found= (my_bool) (!bcmp(pos,"\\^",3) ? 2 : 1);
rep_str[i].found= (my_bool) (!memcmp(pos,"\\^",3) ? 2 : 1);
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
Expand Down Expand Up @@ -776,8 +776,8 @@ static void copy_bits(REP_SET *to,REP_SET *from)

static int cmp_bits(REP_SET *set1,REP_SET *set2)
{
return bcmp((uchar*) set1->bits,(uchar*) set2->bits,
sizeof(uint) * set1->size_of_bits);
return memcmp(set1->bits, set2->bits,
sizeof(uint) * set1->size_of_bits);
}


Expand Down Expand Up @@ -849,14 +849,14 @@ static short find_found(FOUND_SET *found_set,uint table_offset,

static uint start_at_word(char * pos)
{
return (((!bcmp(pos,"\\b",2) && pos[2]) || !bcmp(pos,"\\^",2)) ? 1 : 0);
return (((!memcmp(pos,"\\b",2) && pos[2]) || !memcmp(pos,"\\^",2)) ? 1 : 0);
}

static uint end_of_word(char * pos)
{
char * end=strend(pos);
return ((end > pos+2 && !bcmp(end-2,"\\b",2)) ||
(end >= pos+2 && !bcmp(end-2,"\\$",2))) ?
return ((end > pos+2 && !memcmp(end-2,"\\b",2)) ||
(end >= pos+2 && !memcmp(end-2,"\\$",2))) ?
1 : 0;
}

Expand Down
5 changes: 3 additions & 2 deletions extra/yassl/src/crypto_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,9 @@ x509* PemToDer(FILE* file, CertType type, EncryptedInfo* info)
info->set = true;
}
}
fgets(line,sizeof(line), file); // get blank line
begin = ftell(file);
// get blank line
if (fgets(line, sizeof(line), file))
begin = ftell(file);
}

}
Expand Down
6 changes: 3 additions & 3 deletions extra/yassl/taocrypt/include/blowfish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Blowfish : public Mode_BASE {
enum { BLOCK_SIZE = BLOWFISH_BLOCK_SIZE, ROUNDS = 16 };

Blowfish(CipherDir DIR, Mode MODE)
: Mode_BASE(BLOCK_SIZE, DIR, MODE) {}
: Mode_BASE(BLOCK_SIZE, DIR, MODE), sbox_(pbox_ + ROUNDS + 2) {}

#ifdef DO_BLOWFISH_ASM
void Process(byte*, const byte*, word32);
Expand All @@ -62,8 +62,8 @@ class Blowfish : public Mode_BASE {
static const word32 p_init_[ROUNDS + 2];
static const word32 s_init_[4 * 256];

word32 pbox_[ROUNDS + 2];
word32 sbox_[4 * 256];
word32 pbox_[ROUNDS + 2 + 4 * 256];
word32* sbox_;

void crypt_block(const word32 in[2], word32 out[2]) const;
void AsmProcess(const byte* in, byte* out) const;
Expand Down
16 changes: 2 additions & 14 deletions extra/yassl/taocrypt/include/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@

// Handler for pure virtual functions
namespace __Crun {
static void pure_error(void)
{
assert("Pure virtual method called." == "Aborted");
}
void pure_error(void);
} // namespace __Crun

#endif // __sun
Expand All @@ -54,16 +51,7 @@ extern "C" {
#else
#include "kernelc.hpp"
#endif

/* Disallow inline __cxa_pure_virtual() */
static int __cxa_pure_virtual() __attribute__((noinline, used));
static int __cxa_pure_virtual()
{
// oops, pure virtual called!
assert("Pure virtual method called." == "Aborted");
return 0;
}

int __cxa_pure_virtual () __attribute__ ((weak));
} // extern "C"

#endif // __GNUC__ > 2
Expand Down
3 changes: 2 additions & 1 deletion extra/yassl/taocrypt/src/aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void AES::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
else if (mode_ == CBC)
else if (mode_ == CBC) {
if (dir_ == ENCRYPTION)
while (blocks--) {
r_[0] ^= *(word32*)in;
Expand All @@ -78,6 +78,7 @@ void AES::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
}
}

#endif // DO_AES_ASM
Expand Down
6 changes: 3 additions & 3 deletions extra/yassl/taocrypt/src/algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ Integer AbstractGroup::CascadeScalarMultiply(const Element &x,

struct WindowSlider
{
WindowSlider(const Integer &exp, bool fastNegate,
WindowSlider(const Integer &expIn, bool fastNegateIn,
unsigned int windowSizeIn=0)
: exp(exp), windowModulus(Integer::One()), windowSize(windowSizeIn),
windowBegin(0), fastNegate(fastNegate), firstTime(true),
: exp(expIn), windowModulus(Integer::One()), windowSize(windowSizeIn),
windowBegin(0), fastNegate(fastNegateIn), firstTime(true),
finished(false)
{
if (windowSize == 0)
Expand Down
3 changes: 2 additions & 1 deletion extra/yassl/taocrypt/src/blowfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
else if (mode_ == CBC)
else if (mode_ == CBC) {
if (dir_ == ENCRYPTION)
while (blocks--) {
r_[0] ^= *(word32*)in;
Expand All @@ -78,6 +78,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
}
}

#endif // DO_BLOWFISH_ASM
Expand Down
32 changes: 19 additions & 13 deletions extra/yassl/taocrypt/src/integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,23 @@ DWord() {}
word GetHighHalfAsBorrow() const {return 0-halfs_.high;}

private:
struct dword_struct
{
#ifdef LITTLE_ENDIAN_ORDER
word low;
word high;
#else
word high;
word low;
#endif
};

union
{
#ifdef TAOCRYPT_NATIVE_DWORD_AVAILABLE
dword whole_;
#endif
struct
{
#ifdef LITTLE_ENDIAN_ORDER
word low;
word high;
#else
word high;
word low;
#endif
} halfs_;
struct dword_struct halfs_;
};
};

Expand Down Expand Up @@ -1214,20 +1216,24 @@ class LowLevel : public PentiumOptimized
#define AS1(x) #x ";"
#define AS2(x, y) #x ", " #y ";"
#define AddPrologue \
word res; \
__asm__ __volatile__ \
( \
"push %%ebx;" /* save this manually, in case of -fPIC */ \
"mov %2, %%ebx;" \
"mov %3, %%ebx;" \
".intel_syntax noprefix;" \
"push ebp;"
#define AddEpilogue \
"pop ebp;" \
".att_syntax prefix;" \
"pop %%ebx;" \
: \
"mov %%eax, %0;" \
: "=g" (res) \
: "c" (C), "d" (A), "m" (B), "S" (N) \
: "%edi", "memory", "cc" \
);
); \
return res;

#define MulPrologue \
__asm__ __volatile__ \
( \
Expand Down
Loading

0 comments on commit 93fb8bb

Please sign in to comment.