Skip to content

Commit 95131e0

Browse files
committed
test/cfg: mitigated -Wimplicit-function-declaration compiler warnings on macOS
1 parent cac2240 commit 95131e0

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

test/cfg/gnu.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int deallocuse_backtrace(int size) {
5757
return numEntries;
5858
}
5959

60+
#if !defined(__APPLE__)
6061
void leakReturnValNotUsed_get_current_dir_name(void)
6162
{
6263
// cppcheck-suppress leakReturnValNotUsed
@@ -113,7 +114,6 @@ int nullPointer_gethostbyname_r(const char* name, struct hostent* ret, const cha
113114
return gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
114115
}
115116

116-
117117
int nullPointer_gethostbyaddr_r(const void* addr, socklen_t len, int type, struct hostent* ret, const char* buf, size_t buflen, struct hostent** result, const int* h_errnop)
118118
{
119119
// cppcheck-suppress nullPointer
@@ -128,6 +128,7 @@ int nullPointer_gethostbyaddr_r(const void* addr, socklen_t len, int type, struc
128128
(void) gethostbyaddr_r(addr, len, type, ret, buf, buflen, result, NULL);
129129
return gethostbyaddr_r(addr, len, type, ret, buf, buflen, result, h_errnop);
130130
}
131+
#endif
131132

132133
int nullPointer_getopt_long(int argc, char **argv, const char *optstring,
133134
const struct option *longopts, int *longindex)
@@ -153,6 +154,7 @@ int nullPointer_getopt_long_only(int argc, char* const* argv, const char* optstr
153154
return getopt_long_only(argc, argv, optstring, longopts, longindex);
154155
}
155156

157+
#if !defined(__APPLE__)
156158
int nullPointer_getservent_r(struct servent *restrict result_buf, const char *restrict buf, size_t buflen, struct servent **restrict result)
157159
{
158160
// cppcheck-suppress nullPointer
@@ -172,6 +174,7 @@ void *bufferAccessOutOfBounds_memrchr(const void *s, int c, size_t n)
172174
(void)memrchr(buf,c,43);
173175
return memrchr(s,c,n);
174176
}
177+
#endif
175178

176179
void knownConditionTrueFalse_ffsl(long i)
177180
{
@@ -191,6 +194,7 @@ void knownConditionTrueFalse_ffsll(long long i)
191194
if (ffsll(i) == 0) {}
192195
}
193196

197+
#if !defined(__APPLE__)
194198
int nullPointer_semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout)
195199
{
196200
(void) semtimedop(semid, sops, nsops, NULL); // If the timeout argument is NULL, then semtimedop() behaves exactly like semop().
@@ -226,8 +230,10 @@ int uninitvar_getpw(uid_t uid, char *buf)
226230
// cppcheck-suppress uninitvar
227231
return getpw(someUid, buf);
228232
}
233+
#endif
229234

230235
// Declaration necessary because there is no specific / portable header.
236+
// https://www.eyrie.org/~eagle/software/rra-c-util/xmalloc.html
231237
extern void *xcalloc(size_t nmemb, size_t size);
232238
extern void *xmalloc(size_t size);
233239
extern void *xrealloc(void *block, size_t newsize);
@@ -293,8 +299,10 @@ void valid_code(int argInt1, va_list valist_arg, const int * parg)
293299

294300
if (__builtin_expect(argInt1, 0)) {}
295301
if (__builtin_expect_with_probability(argInt1 + 1, 2, 0.5)) {}
302+
#ifdef __GLIBC__
296303
if (__glibc_unlikely(argInt1 != 0)) {}
297304
if (__glibc_likely(parg != NULL)) {}
305+
#endif
298306
const void *ax1 = __builtin_assume_aligned(parg, 16);
299307
printf("%p", ax1);
300308
const void *ax2 = __builtin_assume_aligned(parg, 32, 8);
@@ -482,6 +490,7 @@ void bufferAccessOutOfBounds()
482490
free(pAlloc2);
483491
}
484492

493+
#if !defined(__APPLE__)
485494
void leakReturnValNotUsed()
486495
{
487496
// cppcheck-suppress [unreadVariable, constVariablePointer]
@@ -501,6 +510,7 @@ void leakReturnValNotUsed()
501510
if (42 == __builtin_expect(42, 0))
502511
return;
503512
}
513+
#endif
504514

505515
#if !defined(__CYGWIN__) && !defined(__APPLE__)
506516
int nullPointer_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)

test/cfg/posix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int nullPointer_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, s
224224
return getpwnam_r(name, pwd, buffer, bufsize, result);
225225
}
226226

227+
#if !defined(__APPLE__)
227228
int nullPointer_fgetpwent_r(FILE *restrict stream, const struct passwd *restrict pwbuf, char *restrict buf, size_t buflen, struct passwd **restrict pwbufp)
228229
{
229230
// cppcheck-suppress nullPointer
@@ -247,6 +248,7 @@ int nullPointer_getpwent_r(const struct passwd *restrict pwbuf, char *restrict b
247248
(void) getpwent_r(pwbuf, buf, buflen, NULL);
248249
return getpwent_r(pwbuf, buf, buflen, pwbufp);
249250
}
251+
#endif
250252

251253
int nullPointer_getgrgid_r(gid_t gid, struct group *restrict grp, char *restrict buf, size_t buflen, struct group **restrict result)
252254
{

test/cfg/runtests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CPPCHECK_OPT=(
4444
CXX=g++
4545
CXX_OPT=("-fsyntax-only" "-w" "-std=c++2a")
4646
CC=gcc
47-
CC_OPT=("-fsyntax-only" "-w" "-Wno-implicit-function-declaration" "-std=c11") # TODO: remove -Wno-implicit-function-declaration when warnings are fixed on MacOS
47+
CC_OPT=("-fsyntax-only" "-w" "-std=c11")
4848

4949
function get_pkg_config_cflags {
5050
# TODO: get rid of the error enabling/disabling?

0 commit comments

Comments
 (0)