mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
Bug#45288: pb2 returns a lot of compilation warnings
Fix assorted compiler warnings. include/my_pthread.h: Like for pthread_cond_timedwait, the abstime is constant. mysys/my_gethwaddr.c: Instead of using a manual copy that introduce warnings due to type mismatch, copy the buffer using memcpy and use memcmp to check whether all bytes of the buffer are zeroed. mysys/thr_mutex.c: Like for pthread_cond_timedwait, the abstime is constant. unittest/mytap/tap.h: Introduce a ok() variant that does not take a format argument. Since ok() is tagged with a printf attribute, GCC complains if the fmt argument is NULL.
This commit is contained in:
parent
1040f98ccf
commit
b5bb13ec03
9 changed files with 60 additions and 37 deletions
|
@ -492,7 +492,8 @@ int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);
|
|||
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
|
||||
uint line);
|
||||
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
|
||||
struct timespec *abstime, const char *file, uint line);
|
||||
const struct timespec *abstime,
|
||||
const char *file, uint line);
|
||||
void safe_mutex_global_init(void);
|
||||
void safe_mutex_end(FILE *file);
|
||||
|
||||
|
|
|
@ -21,18 +21,6 @@
|
|||
|
||||
#ifndef MAIN
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__linux__)
|
||||
static my_bool memcpy_and_test(uchar *to, uchar *from, uint len)
|
||||
{
|
||||
uint i, res=1;
|
||||
|
||||
for (i=0; i < len; i++)
|
||||
if ((*to++= *from++))
|
||||
res=0;
|
||||
return res;
|
||||
}
|
||||
#endif /* FreeBSD || linux */
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
|
||||
#include <net/ethernet.h>
|
||||
|
@ -44,10 +32,11 @@ static my_bool memcpy_and_test(uchar *to, uchar *from, uint len)
|
|||
my_bool my_gethwaddr(uchar *to)
|
||||
{
|
||||
size_t len;
|
||||
uchar *buf, *next, *end, *addr;
|
||||
char *buf, *next, *end;
|
||||
struct if_msghdr *ifm;
|
||||
struct sockaddr_dl *sdl;
|
||||
int res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0};
|
||||
char zero_array[ETHER_ADDR_LEN] = {0};
|
||||
|
||||
if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
|
||||
goto err;
|
||||
|
@ -63,9 +52,9 @@ my_bool my_gethwaddr(uchar *to)
|
|||
ifm = (struct if_msghdr *)next;
|
||||
if (ifm->ifm_type == RTM_IFINFO)
|
||||
{
|
||||
sdl = (struct sockaddr_dl *)(ifm + 1);
|
||||
addr=LLADDR(sdl);
|
||||
res=memcpy_and_test(to, addr, ETHER_ADDR_LEN);
|
||||
sdl= (struct sockaddr_dl *)(ifm + 1);
|
||||
memcpy(to, LLADDR(sdl), ETHER_ADDR_LEN);
|
||||
res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,8 +70,9 @@ err:
|
|||
|
||||
my_bool my_gethwaddr(uchar *to)
|
||||
{
|
||||
int fd, res=1;
|
||||
int fd, res= 1;
|
||||
struct ifreq ifr;
|
||||
char zero_array[ETHER_ADDR_LEN] = {0};
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0)
|
||||
|
@ -91,9 +81,13 @@ my_bool my_gethwaddr(uchar *to)
|
|||
bzero(&ifr, sizeof(ifr));
|
||||
strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
|
||||
res=memcpy_and_test(to, (uchar *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
|
||||
{
|
||||
memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
|
||||
res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
|
||||
}
|
||||
} while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
|
||||
|
||||
close(fd);
|
||||
|
|
|
@ -259,8 +259,8 @@ int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file,
|
|||
|
||||
|
||||
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
|
||||
struct timespec *abstime,
|
||||
const char *file, uint line)
|
||||
const struct timespec *abstime,
|
||||
const char *file, uint line)
|
||||
{
|
||||
int error;
|
||||
pthread_mutex_lock(&mp->global);
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
int main() {
|
||||
plan(4);
|
||||
ok(1, NULL);
|
||||
ok(1, NULL);
|
||||
ok1(1);
|
||||
ok1(1);
|
||||
SKIP_BLOCK_IF(1, 2, "Example of skipping a few test points in a test") {
|
||||
ok(1, NULL);
|
||||
ok(1, NULL);
|
||||
ok1(1);
|
||||
ok1(1);
|
||||
}
|
||||
return exit_status();
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ int main() {
|
|||
if (!has_feature())
|
||||
skip_all("Example of skipping an entire test");
|
||||
plan(4);
|
||||
ok(1, NULL);
|
||||
ok(1, NULL);
|
||||
ok(1, NULL);
|
||||
ok(1, NULL);
|
||||
ok1(1);
|
||||
ok1(1);
|
||||
ok1(1);
|
||||
ok1(1);
|
||||
return exit_status();
|
||||
}
|
||||
|
|
|
@ -21,15 +21,15 @@
|
|||
int main()
|
||||
{
|
||||
plan(4);
|
||||
ok(1, NULL);
|
||||
ok(1, NULL);
|
||||
ok1(1);
|
||||
ok1(1);
|
||||
/*
|
||||
Tests in the todo region is expected to fail. If they don't,
|
||||
something is strange.
|
||||
*/
|
||||
todo_start("Need to fix these");
|
||||
ok(0, NULL);
|
||||
ok(0, NULL);
|
||||
ok1(0);
|
||||
ok1(0);
|
||||
todo_end();
|
||||
return exit_status();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ int main() {
|
|||
plan(5);
|
||||
ok(1 == 1, "testing basic functions");
|
||||
ok(2 == 2, " ");
|
||||
ok(3 == 3, NULL);
|
||||
ok1(3 == 3);
|
||||
if (1 == 1)
|
||||
skip(2, "Sensa fragoli");
|
||||
else {
|
||||
|
|
|
@ -223,6 +223,23 @@ ok(int const pass, char const *fmt, ...)
|
|||
emit_endl();
|
||||
}
|
||||
|
||||
void
|
||||
ok1(int const pass)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
memset(&ap, 0, sizeof(ap));
|
||||
|
||||
if (!pass && *g_test.todo == '\0')
|
||||
++g_test.failed;
|
||||
|
||||
vemit_tap(pass, NULL, ap);
|
||||
|
||||
if (*g_test.todo != '\0')
|
||||
emit_dir("todo", g_test.todo);
|
||||
|
||||
emit_endl();
|
||||
}
|
||||
|
||||
void
|
||||
skip(int how_many, char const *fmt, ...)
|
||||
|
|
|
@ -98,14 +98,25 @@ void plan(int const count);
|
|||
@endcode
|
||||
|
||||
@param pass Zero if the test failed, non-zero if it passed.
|
||||
@param fmt Format string in printf() format. NULL is allowed, in
|
||||
which case nothing is printed.
|
||||
@param fmt Format string in printf() format. NULL is not allowed,
|
||||
use ok1() in this case.
|
||||
*/
|
||||
|
||||
void ok(int const pass, char const *fmt, ...)
|
||||
__attribute__((format(printf,2,3)));
|
||||
|
||||
|
||||
/**
|
||||
Report test result as a TAP line.
|
||||
|
||||
Same as ok() but does not take a message to be printed.
|
||||
|
||||
@param pass Zero if the test failed, non-zero if it passed.
|
||||
*/
|
||||
|
||||
void ok1(int const pass);
|
||||
|
||||
|
||||
/**
|
||||
Skip a determined number of tests.
|
||||
|
||||
|
|
Loading…
Reference in a new issue