Skip to content

Commit 65327c6

Browse files
authored
test/cfg: fixed -Wimplicit-function-declaration warnings / std.cfg: removed non-existent (draft) functions (#6809)
1 parent 11cf3f4 commit 65327c6

6 files changed

Lines changed: 76 additions & 52 deletions

File tree

cfg/std.cfg

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,8 +4153,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
41534153
</arg>
41544154
</function>
41554155
<!-- time_t mktime(struct tm *tp); -->
4156-
<!-- time_t mkxtime(struct tmx *tp); -->
4157-
<function name="mktime,std::mktime,mkxtime">
4156+
<function name="mktime,std::mktime">
41584157
<returnValue type="time_t"/>
41594158
<noreturn>false</noreturn>
41604159
<leak-ignore/>
@@ -4956,8 +4955,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
49564955
</arg>
49574956
</function>
49584957
<!-- size_t strftime(char *s, size_t max, const char *fmt, const struct tm *p); -->
4959-
<!-- size_t strfxtime(char *s, size_t max, const char *fmt, const struct tmx *p); -->
4960-
<function name="strftime,std::strftime,strfxtime">
4958+
<function name="strftime,std::strftime">
49614959
<returnValue type="size_t"/>
49624960
<noreturn>false</noreturn>
49634961
<leak-ignore/>
@@ -6523,20 +6521,6 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
65236521
<not-uninit/>
65246522
</arg>
65256523
</function>
6526-
<!-- struct tmx *zonetime(const time_t *tp, int zone); -->
6527-
<function name="zonetime">
6528-
<use-retval/>
6529-
<returnValue type="struct tmx *"/>
6530-
<noreturn>false</noreturn>
6531-
<leak-ignore/>
6532-
<arg nr="1" direction="in">
6533-
<not-null/>
6534-
<not-uninit/>
6535-
</arg>
6536-
<arg nr="2" direction="in">
6537-
<not-uninit/>
6538-
</arg>
6539-
</function>
65406524
<!-- size_t c16rtomb ( char * pmb, char16_t c16, mbstate_t * ps ); -->
65416525
<!-- size_t c32rtomb ( char * pmb, char32_t c32, mbstate_t * ps ); -->
65426526
<function name="c16rtomb,c32rtomb">

test/cfg/gnu.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
88
//
99

10-
// cppcheck-suppress-file valueFlowBailout
10+
// cppcheck-suppress-file [valueFlowBailout,purgedConfiguration]
11+
12+
#define _GNU_SOURCE
1113

1214
#include <string.h>
1315
#include <stdlib.h>
@@ -21,18 +23,19 @@
2123
#include <sys/mman.h>
2224
#include <sys/sem.h>
2325
#include <wchar.h>
24-
#if !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__))
26+
#if !defined(__CYGWIN__) && !defined(__APPLE__)
2527
#include <sys/epoll.h>
2628
#endif
2729
#include <strings.h>
2830
#ifdef __gnu_linux__
2931
#include <error.h>
3032
#endif
31-
#ifdef _GNU_SOURCE
3233
#include <unistd.h>
33-
#endif
3434
#include <getopt.h>
3535
#include <netdb.h>
36+
#if !defined(__APPLE__)
37+
#include <byteswap.h>
38+
#endif
3639

3740
#ifdef __gnu_linux__
3841
void unreachableCode_error(void) // #11197
@@ -44,7 +47,6 @@ void unreachableCode_error(void) // #11197
4447
}
4548
#endif
4649

47-
#ifdef _GNU_SOURCE
4850
void leakReturnValNotUsed_get_current_dir_name(void)
4951
{
5052
// cppcheck-suppress leakReturnValNotUsed
@@ -70,7 +72,6 @@ void memleak_get_current_dir_name1(void)
7072
return;
7173
}
7274
}
73-
#endif
7475

7576
int nullPointer_gethostbyname2_r(const char* name, int af, struct hostent* ret, const char* buf, size_t buflen, struct hostent** result, const int* h_errnop)
7677
{
@@ -332,6 +333,7 @@ void valid_code(int argInt1, va_list valist_arg, const int * parg)
332333
// cppcheck-suppress unreadVariable
333334
i64_2 = __builtin_bswap64(i64_1++);
334335

336+
#if !defined(__APPLE__)
335337
// cppcheck-suppress zerodiv
336338
// cppcheck-suppress unreadVariable
337339
i16_1 /= bswap_16(0x1234) - 0x3412;
@@ -341,6 +343,7 @@ void valid_code(int argInt1, va_list valist_arg, const int * parg)
341343
// cppcheck-suppress zerodiv
342344
// cppcheck-suppress unreadVariable
343345
i64_1 /= bswap_64(0x023456789abcde0f) - 0x0fdebc9a78563402;
346+
#endif
344347
}
345348

346349
void ignoreleak(void)
@@ -489,7 +492,7 @@ void leakReturnValNotUsed()
489492
return;
490493
}
491494

492-
#if !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__))
495+
#if !defined(__CYGWIN__) && !defined(__APPLE__)
493496
int nullPointer_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
494497
{
495498
// no warning is expected

test/cfg/gtk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdlib.h>
1111
#include <gtk/gtk.h>
1212
#include <glib.h>
13+
#include <glib/gi18n.h>
1314

1415

1516
void validCode(int argInt, GHashTableIter * hash_table_iter, GHashTable * hash_table)

test/cfg/posix.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
88
//
99

10-
// cppcheck-suppress-file [valueFlowBailout,purgedConfiguration]
10+
// cppcheck-suppress-file [valueFlowBailout]
1111

1212
#define _BSD_SOURCE
13+
#define _XOPEN_SOURCE // wcwidth
1314

1415
#include <aio.h>
1516
#include <stdio.h> // <- FILE
@@ -38,15 +39,17 @@
3839
#if defined(__APPLE__)
3940
#include <xlocale.h>
4041
#endif
41-
#if !(defined(__APPLE__) && defined(__MACH__))
42+
#if !defined(__APPLE__)
4243
#include <mqueue.h>
4344
#endif
4445
#include <stdlib.h>
4546
#include <unistd.h>
4647
#include <wchar.h>
48+
#include <sys/stat.h>
49+
#include <utime.h>
4750

4851

49-
#if !(defined(__APPLE__) && defined(__MACH__))
52+
#if !defined(__APPLE__)
5053
void nullPointer_mq_timedsend(mqd_t mqdes, const char* msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec* abs_timeout) {
5154
// cppcheck-suppress nullPointer
5255
(void) mq_timedsend(mqdes, NULL, msg_len, msg_prio, abs_timeout);
@@ -144,6 +147,7 @@ void nullPointer_pthread_attr_setstack(const pthread_attr_t *attr) {
144147
(void) pthread_attr_setstack(NULL, (void*) 1, 0);
145148
}
146149

150+
#ifndef __linux__
147151
void nullPointer_setkey(const char *key)
148152
{
149153
// cppcheck-suppress nullPointer
@@ -156,6 +160,7 @@ void nullPointer_encrypt(const char block[64], int edflag)
156160
encrypt(NULL, edflag);
157161
encrypt(block, edflag);
158162
}
163+
#endif
159164

160165
int nullPointer_getopt(int argc, char* const argv[], const char* optstring)
161166
{
@@ -166,7 +171,7 @@ int nullPointer_getopt(int argc, char* const argv[], const char* optstring)
166171
return getopt(argc, argv, optstring);
167172
}
168173

169-
#if !(defined(__APPLE__) && defined(__MACH__))
174+
#if !defined(__APPLE__)
170175
int invalidFunctionArgStr_mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
171176
{
172177
// No warning is expected for:
@@ -532,7 +537,7 @@ int nullPointer_aio_suspend(const struct aiocb *const aiocb_list[], int nitems,
532537
return aio_suspend(aiocb_list, nitems, timeout);
533538
}
534539

535-
#ifdef __linux__
540+
#if !defined(__linux__) && !defined(__APPLE__)
536541
// Note: Since glibc 2.28, this function symbol is no longer available to newly linked applications.
537542
void invalidFunctionArg_llseek(int fd, loff_t offset, int origin)
538543
{
@@ -563,7 +568,6 @@ void invalidFunctionArg_llseek(int fd, loff_t offset, int origin)
563568
// cppcheck-suppress llseekCalled
564569
(void)llseek(fd, offset, SEEK_END);
565570
}
566-
#endif
567571

568572
void invalidFunctionArg_lseek64(int fd, off_t offset, int origin)
569573
{
@@ -584,6 +588,7 @@ void invalidFunctionArg_lseek64(int fd, off_t offset, int origin)
584588
(void)lseek64(fd, offset, SEEK_CUR);
585589
(void)lseek64(fd, offset, SEEK_END);
586590
}
591+
#endif
587592

588593
void invalidFunctionArg_lseek(int fd, off_t offset, int origin)
589594
{
@@ -1328,7 +1333,7 @@ void uninitvar(int fd)
13281333
// cppcheck-suppress utimeCalled
13291334
utime(filename1, times);
13301335
// cppcheck-suppress constVariable
1331-
struct timeval times1[2];
1336+
struct utimbuf times1[2];
13321337
// cppcheck-suppress uninitvar
13331338
// cppcheck-suppress utimeCalled
13341339
utime(filename2, times1);

test/cfg/runtests.sh

Lines changed: 12 additions & 4 deletions
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" "-std=c11")
47+
CC_OPT=("-fsyntax-only" "-w" "-Wimplicit-function-declaration" "-std=c11")
4848

4949
function get_pkg_config_cflags {
5050
# TODO: get rid of the error enabling/disabling?
@@ -65,12 +65,14 @@ function get_pkg_config_cflags {
6565

6666
# posix.c
6767
function posix_fn {
68+
echo "POSIX assumed to be present, checking syntax with ${CC} now."
6869
${CC} "${CC_OPT[@]}" ${DIR}posix.c
6970
}
7071

7172
# gnu.c
7273
function gnu_fn {
73-
${CC} "${CC_OPT[@]}" -D_GNU_SOURCE ${DIR}gnu.c
74+
echo "GNU assumed to be present, checking syntax with ${CC} now."
75+
${CC} "${CC_OPT[@]}" ${DIR}gnu.c
7476
}
7577

7678
# qt.cpp
@@ -101,23 +103,26 @@ function qt_fn {
101103

102104
# bsd.c
103105
function bsd_fn {
104-
true
106+
# TODO: add syntax check
107+
true
105108
}
106109

107110
# std.c
108111
function std_c_fn {
112+
echo "C standard library assumed to be present, checking syntax with ${CC} now."
109113
${CC} "${CC_OPT[@]}" "${DIR}"std.c
110114
}
111115

112116
# std.cpp
113117
function std_cpp_fn {
118+
echo "C++ standard library assumed to be present, checking syntax with ${CXX} now."
114119
${CXX} "${CXX_OPT[@]}" "${DIR}"std.cpp
115120
}
116121

117122
# windows.cpp
118123
function windows_fn {
119124
# TODO: Syntax check via g++ does not work because it can not find a valid windows.h
120-
#${CXX} "${CXX_OPT[@]}" ${DIR}windows.cpp
125+
#${CXX} "${CXX_OPT[@]}" ${DIR}windows.cpp
121126
true
122127
}
123128

@@ -224,6 +229,7 @@ function sqlite3_fn {
224229
function openmp_fn {
225230
# MacOS compiler has no OpenMP by default
226231
if ! command -v sw_vers; then
232+
echo "OpenMP assumed to be present, checking syntax with ${CC} now."
227233
${CC} "${CC_OPT[@]}" -fopenmp ${DIR}openmp.c
228234
fi
229235
}
@@ -326,6 +332,7 @@ function cairo_fn {
326332

327333
# googletest.cpp
328334
function googletest_fn {
335+
# TODO: add syntax check
329336
true
330337
}
331338

@@ -455,6 +462,7 @@ function emscripten_fn {
455462

456463
# selinux.c
457464
function selinux_fn {
465+
# TODO: add syntax check
458466
true
459467
}
460468

0 commit comments

Comments
 (0)