Skip to content

Commit f4e3ed7

Browse files
committed
test/cfg: mitigated -Wimplicit-function-declaration compiler warnings on macOS
1 parent 490252f commit f4e3ed7

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
@@ -58,6 +58,7 @@ int deallocuse_backtrace(int size) {
5858
return numEntries;
5959
}
6060

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

117-
118118
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)
119119
{
120120
// cppcheck-suppress nullPointer
@@ -129,6 +129,7 @@ int nullPointer_gethostbyaddr_r(const void* addr, socklen_t len, int type, struc
129129
(void) gethostbyaddr_r(addr, len, type, ret, buf, buflen, result, NULL);
130130
return gethostbyaddr_r(addr, len, type, ret, buf, buflen, result, h_errnop);
131131
}
132+
#endif
132133

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

158+
#if !defined(__APPLE__)
157159
int nullPointer_getservent_r(struct servent *restrict result_buf, const char *restrict buf, size_t buflen, struct servent **restrict result)
158160
{
159161
// cppcheck-suppress nullPointer
@@ -173,6 +175,7 @@ void *bufferAccessOutOfBounds_memrchr(const void *s, int c, size_t n)
173175
(void)memrchr(buf,c,43);
174176
return memrchr(s,c,n);
175177
}
178+
#endif
176179

177180
void knownConditionTrueFalse_ffsl(long i)
178181
{
@@ -192,6 +195,7 @@ void knownConditionTrueFalse_ffsll(long long i)
192195
if (ffsll(i) == 0) {}
193196
}
194197

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

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

295301
if (__builtin_expect(argInt1, 0)) {}
296302
if (__builtin_expect_with_probability(argInt1 + 1, 2, 0.5)) {}
303+
#ifdef __GLIBC__
297304
if (__glibc_unlikely(argInt1 != 0)) {}
298305
if (__glibc_likely(parg != NULL)) {}
306+
#endif
299307
const void *ax1 = __builtin_assume_aligned(parg, 16);
300308
printf("%p", ax1);
301309
const void *ax2 = __builtin_assume_aligned(parg, 32, 8);
@@ -489,6 +497,7 @@ void bufferAccessOutOfBounds()
489497
free(pAlloc2);
490498
}
491499

500+
#if !defined(__APPLE__)
492501
void leakReturnValNotUsed()
493502
{
494503
// cppcheck-suppress [unreadVariable, constVariablePointer]
@@ -508,6 +517,7 @@ void leakReturnValNotUsed()
508517
if (42 == __builtin_expect(42, 0))
509518
return;
510519
}
520+
#endif
511521

512522
#if !defined(__CYGWIN__) && !defined(__APPLE__)
513523
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
@@ -225,6 +225,7 @@ int nullPointer_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, s
225225
return getpwnam_r(name, pwd, buffer, bufsize, result);
226226
}
227227

228+
#if !defined(__APPLE__)
228229
int nullPointer_fgetpwent_r(FILE *restrict stream, const struct passwd *restrict pwbuf, char *restrict buf, size_t buflen, struct passwd **restrict pwbufp)
229230
{
230231
// cppcheck-suppress nullPointer
@@ -248,6 +249,7 @@ int nullPointer_getpwent_r(const struct passwd *restrict pwbuf, char *restrict b
248249
(void) getpwent_r(pwbuf, buf, buflen, NULL);
249250
return getpwent_r(pwbuf, buf, buflen, pwbufp);
250251
}
252+
#endif
251253

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

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)