Skip to content

Commit 60f30f6

Browse files
author
Davi Arnaut
committed
Bug#45288: pb2 returns a lot of compilation warnings
Fix assorted compiler warnings.
1 parent 39e9bde commit 60f30f6

File tree

9 files changed

+60
-37
lines changed

9 files changed

+60
-37
lines changed

include/my_pthread.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);
492492
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
493493
uint line);
494494
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
495-
struct timespec *abstime, const char *file, uint line);
495+
const struct timespec *abstime,
496+
const char *file, uint line);
496497
void safe_mutex_global_init(void);
497498
void safe_mutex_end(FILE *file);
498499

mysys/my_gethwaddr.c

+13-19
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@
2121

2222
#ifndef MAIN
2323

24-
#if defined(__FreeBSD__) || defined(__linux__)
25-
static my_bool memcpy_and_test(uchar *to, uchar *from, uint len)
26-
{
27-
uint i, res=1;
28-
29-
for (i=0; i < len; i++)
30-
if ((*to++= *from++))
31-
res=0;
32-
return res;
33-
}
34-
#endif /* FreeBSD || linux */
35-
3624
#ifdef __FreeBSD__
3725

3826
#include <net/ethernet.h>
@@ -44,10 +32,11 @@ static my_bool memcpy_and_test(uchar *to, uchar *from, uint len)
4432
my_bool my_gethwaddr(uchar *to)
4533
{
4634
size_t len;
47-
uchar *buf, *next, *end, *addr;
35+
char *buf, *next, *end;
4836
struct if_msghdr *ifm;
4937
struct sockaddr_dl *sdl;
5038
int res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0};
39+
char zero_array[ETHER_ADDR_LEN] = {0};
5140

5241
if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
5342
goto err;
@@ -63,9 +52,9 @@ my_bool my_gethwaddr(uchar *to)
6352
ifm = (struct if_msghdr *)next;
6453
if (ifm->ifm_type == RTM_IFINFO)
6554
{
66-
sdl = (struct sockaddr_dl *)(ifm + 1);
67-
addr=LLADDR(sdl);
68-
res=memcpy_and_test(to, addr, ETHER_ADDR_LEN);
55+
sdl= (struct sockaddr_dl *)(ifm + 1);
56+
memcpy(to, LLADDR(sdl), ETHER_ADDR_LEN);
57+
res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
6958
}
7059
}
7160

@@ -81,8 +70,9 @@ my_bool my_gethwaddr(uchar *to)
8170

8271
my_bool my_gethwaddr(uchar *to)
8372
{
84-
int fd, res=1;
73+
int fd, res= 1;
8574
struct ifreq ifr;
75+
char zero_array[ETHER_ADDR_LEN] = {0};
8676

8777
fd = socket(AF_INET, SOCK_DGRAM, 0);
8878
if (fd < 0)
@@ -91,9 +81,13 @@ my_bool my_gethwaddr(uchar *to)
9181
bzero(&ifr, sizeof(ifr));
9282
strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
9383

94-
do {
84+
do
85+
{
9586
if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
96-
res=memcpy_and_test(to, (uchar *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
87+
{
88+
memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
89+
res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
90+
}
9791
} while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
9892

9993
close(fd);

mysys/thr_mutex.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file,
259259

260260

261261
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
262-
struct timespec *abstime,
263-
const char *file, uint line)
262+
const struct timespec *abstime,
263+
const char *file, uint line)
264264
{
265265
int error;
266266
pthread_mutex_lock(&mp->global);

unittest/examples/skip-t.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
int main() {
2020
plan(4);
21-
ok(1, NULL);
22-
ok(1, NULL);
21+
ok1(1);
22+
ok1(1);
2323
SKIP_BLOCK_IF(1, 2, "Example of skipping a few test points in a test") {
24-
ok(1, NULL);
25-
ok(1, NULL);
24+
ok1(1);
25+
ok1(1);
2626
}
2727
return exit_status();
2828
}

unittest/examples/skip_all-t.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ int main() {
3131
if (!has_feature())
3232
skip_all("Example of skipping an entire test");
3333
plan(4);
34-
ok(1, NULL);
35-
ok(1, NULL);
36-
ok(1, NULL);
37-
ok(1, NULL);
34+
ok1(1);
35+
ok1(1);
36+
ok1(1);
37+
ok1(1);
3838
return exit_status();
3939
}

unittest/examples/todo-t.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
int main()
2222
{
2323
plan(4);
24-
ok(1, NULL);
25-
ok(1, NULL);
24+
ok1(1);
25+
ok1(1);
2626
/*
2727
Tests in the todo region is expected to fail. If they don't,
2828
something is strange.
2929
*/
3030
todo_start("Need to fix these");
31-
ok(0, NULL);
32-
ok(0, NULL);
31+
ok1(0);
32+
ok1(0);
3333
todo_end();
3434
return exit_status();
3535
}

unittest/mytap/t/basic-t.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main() {
2222
plan(5);
2323
ok(1 == 1, "testing basic functions");
2424
ok(2 == 2, " ");
25-
ok(3 == 3, NULL);
25+
ok1(3 == 3);
2626
if (1 == 1)
2727
skip(2, "Sensa fragoli");
2828
else {

unittest/mytap/tap.c

+17
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ ok(int const pass, char const *fmt, ...)
223223
emit_endl();
224224
}
225225

226+
void
227+
ok1(int const pass)
228+
{
229+
va_list ap;
230+
231+
memset(&ap, 0, sizeof(ap));
232+
233+
if (!pass && *g_test.todo == '\0')
234+
++g_test.failed;
235+
236+
vemit_tap(pass, NULL, ap);
237+
238+
if (*g_test.todo != '\0')
239+
emit_dir("todo", g_test.todo);
240+
241+
emit_endl();
242+
}
226243

227244
void
228245
skip(int how_many, char const *fmt, ...)

unittest/mytap/tap.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,25 @@ void plan(int const count);
9898
@endcode
9999
100100
@param pass Zero if the test failed, non-zero if it passed.
101-
@param fmt Format string in printf() format. NULL is allowed, in
102-
which case nothing is printed.
101+
@param fmt Format string in printf() format. NULL is not allowed,
102+
use ok1() in this case.
103103
*/
104104

105105
void ok(int const pass, char const *fmt, ...)
106106
__attribute__((format(printf,2,3)));
107107

108108

109+
/**
110+
Report test result as a TAP line.
111+
112+
Same as ok() but does not take a message to be printed.
113+
114+
@param pass Zero if the test failed, non-zero if it passed.
115+
*/
116+
117+
void ok1(int const pass);
118+
119+
109120
/**
110121
Skip a determined number of tests.
111122

0 commit comments

Comments
 (0)