Skip to content

Commit 300cb89

Browse files
author
Davi Arnaut
committed
Bug#45288: pb2 returns a lot of compilation warnings
Fix assorted compiler warnings.
1 parent 1fa19f5 commit 300cb89

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
@@ -490,7 +490,8 @@ int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);
490490
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
491491
uint line);
492492
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
493-
struct timespec *abstime, const char *file, uint line);
493+
const struct timespec *abstime,
494+
const char *file, uint line);
494495
void safe_mutex_global_init(void);
495496
void safe_mutex_end(FILE *file);
496497

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=(uchar *)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
@@ -262,8 +262,8 @@ int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file,
262262

263263

264264
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
265-
struct timespec *abstime,
266-
const char *file, uint line)
265+
const struct timespec *abstime,
266+
const char *file, uint line)
267267
{
268268
int error;
269269
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
@@ -251,6 +251,23 @@ ok(int const pass, char const *fmt, ...)
251251
emit_endl();
252252
}
253253

254+
void
255+
ok1(int const pass)
256+
{
257+
va_list ap;
258+
259+
memset(&ap, 0, sizeof(ap));
260+
261+
if (!pass && *g_test.todo == '\0')
262+
++g_test.failed;
263+
264+
vemit_tap(pass, NULL, ap);
265+
266+
if (*g_test.todo != '\0')
267+
emit_dir("todo", g_test.todo);
268+
269+
emit_endl();
270+
}
254271

255272
void
256273
skip(int how_many, char const *fmt, ...)

unittest/mytap/tap.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,25 @@ void plan(int const count);
121121
@endcode
122122
123123
@param pass Zero if the test failed, non-zero if it passed.
124-
@param fmt Format string in printf() format. NULL is allowed, in
125-
which case nothing is printed.
124+
@param fmt Format string in printf() format. NULL is not allowed,
125+
use ok1() in this case.
126126
*/
127127

128128
void ok(int const pass, char const *fmt, ...)
129129
__attribute__((format(printf,2,3)));
130130

131131

132+
/**
133+
Report test result as a TAP line.
134+
135+
Same as ok() but does not take a message to be printed.
136+
137+
@param pass Zero if the test failed, non-zero if it passed.
138+
*/
139+
140+
void ok1(int const pass);
141+
142+
132143
/**
133144
Skip a determined number of tests.
134145

0 commit comments

Comments
 (0)