2015-01-30 07:52:32 +01:00
|
|
|
|
|
|
|
// Test library configuration for posix.cfg
|
|
|
|
//
|
|
|
|
// Usage:
|
2015-02-16 22:19:51 +01:00
|
|
|
// $ cppcheck --check-library --library=posix --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem test/cfg/posix.c
|
2015-01-30 07:52:32 +01:00
|
|
|
// =>
|
|
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
|
|
//
|
|
|
|
|
2022-04-19 21:13:09 +02:00
|
|
|
#include <aio.h>
|
2015-02-15 18:11:09 +01:00
|
|
|
#include <stdio.h> // <- FILE
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/socket.h>
|
2022-05-01 11:41:31 +02:00
|
|
|
#include <sys/sem.h>
|
2021-05-03 09:39:33 +02:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
2022-05-02 12:28:54 +02:00
|
|
|
#include <grp.h>
|
2022-05-02 12:51:58 +02:00
|
|
|
#include <pwd.h>
|
2019-01-10 21:14:37 +01:00
|
|
|
#include <dlfcn.h>
|
2015-02-15 18:11:09 +01:00
|
|
|
#include <fcntl.h>
|
2015-03-15 13:28:16 +01:00
|
|
|
// unavailable on some linux systems #include <ndbm.h>
|
2015-02-21 11:08:58 +01:00
|
|
|
#include <netdb.h>
|
2015-02-20 20:50:20 +01:00
|
|
|
#include <regex.h>
|
2015-03-11 18:59:34 +01:00
|
|
|
#include <time.h>
|
2018-07-21 17:52:12 +02:00
|
|
|
#include <pthread.h>
|
2019-09-06 10:16:11 +02:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <stdarg.h>
|
2020-02-22 14:49:36 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
2022-06-03 10:20:19 +02:00
|
|
|
#include <mqueue.h>
|
2022-04-20 15:23:46 +02:00
|
|
|
#define _XOPEN_SOURCE
|
2022-12-22 09:36:18 +01:00
|
|
|
#include <stdlib.h>
|
2022-12-22 09:19:46 +01:00
|
|
|
#include <unistd.h>
|
2021-07-10 18:41:36 +02:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <string.h>
|
2022-05-01 15:24:57 +02:00
|
|
|
#include <strings.h>
|
2022-05-01 15:29:35 +02:00
|
|
|
|
2022-12-22 11:58:32 +01:00
|
|
|
void nullPointer_mq_timedsend(mqd_t mqdes, const char* msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec* abs_timeout) {
|
2022-12-22 11:59:10 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) mq_timedsend(mqdes, NULL, msg_len, msg_prio, abs_timeout);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, NULL);
|
2022-12-22 11:58:32 +01:00
|
|
|
}
|
|
|
|
|
2022-12-22 11:39:00 +01:00
|
|
|
#if __TRACE_H__ // <trace.h>
|
2022-12-22 11:48:51 +01:00
|
|
|
|
|
|
|
void nullPointer_posix_trace_event(trace_event_id_t event_id, const void* restrictdata_ptr, size_t data_len)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_event(event_id, NULL, data_len);
|
|
|
|
(void) posix_trace_event(event_id, restrictdata_ptr, 0);
|
|
|
|
}
|
|
|
|
|
2022-12-22 11:39:00 +01:00
|
|
|
void nullPointer_posix_trace_trygetnext_event(trace_id_t trid,
|
2022-12-22 11:59:10 +01:00
|
|
|
struct posix_trace_event_info *event,
|
|
|
|
void *data, size_t num_bytes,
|
|
|
|
size_t *data_len, int *unavailable)
|
2022-12-22 11:39:00 +01:00
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_trygetnext_event(trid, NULL, data, num_bytes, data_len, unavailable);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_trygetnext_event(trid, event, NULL, num_bytes, data_len, unavailable);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_trygetnext_event(trid, event, data, num_bytes, NULL, unavailable);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_trygetnext_event(trid, event, data, num_bytes, data_len, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nullPointer_posix_trace_timedgetnext_event(trace_id_t trid, struct posix_trace_event_info *restrict event, void *restrict data, size_t num_bytes, size_t *restrict data_len, int *restrict unavailable, const struct timespec *restrict abstime)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_timedgetnext_event(trid, NULL, data, num_bytes, data_len, unavailable, abstime);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_timedgetnext_event(trid, event, NULL, num_bytes, data_len, unavailable, abstime);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_timedgetnext_event(trid, event, data, num_bytes, NULL, unavailable, abstime);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_timedgetnext_event(trid, event, data, num_bytes, data_len, NULL, abstime);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_timedgetnext_event(trid, event, data, num_bytes, data_len, unavailable, NULL);
|
|
|
|
return posix_trace_timedgetnext_event(trid, event, data, num_bytes, data_len, unavailable, abstime);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nullPointer_posix_trace_getnext_event(trace_id_t trid, struct posix_trace_event_info *restrict event, void *restrict data, size_t num_bytes, size_t *restrict data_len, int *restrict unavailable)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_getnext_event(trid, NULL, data, num_bytes, data_len, unavailable);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_getnext_event(trid, event, NULL, num_bytes, data_len, unavailable);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_getnext_event(trid, event, data, num_bytes, NULL, unavailable);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) posix_trace_getnext_event(trid, event, data, num_bytes, data_len, NULL);
|
|
|
|
return posix_trace_getnext_event(trid, event, data, num_bytes, data_len, unavailable);
|
|
|
|
}
|
|
|
|
#endif // __TRACE_H__
|
|
|
|
|
2022-12-22 10:07:50 +01:00
|
|
|
void nullPointer_pthread_attr_getstack(const pthread_attr_t *attr, void *stackaddr, size_t stacksize) {
|
2022-12-22 11:59:10 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(NULL, &stackaddr, &stacksize);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(attr, NULL, &stacksize);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(attr, &stackaddr, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(NULL, NULL, &stacksize);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(NULL, &stackaddr, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(attr, NULL, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_getstack(NULL, NULL, NULL);
|
2022-12-22 10:07:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void nullPointer_pthread_attr_setstack(pthread_attr_t *attr) {
|
2022-12-22 11:59:10 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_setstack(NULL, NULL, 0);
|
|
|
|
(void) pthread_attr_setstack(attr, NULL, 0);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) pthread_attr_setstack(NULL, (void*) 1, 0);
|
2022-12-22 10:07:50 +01:00
|
|
|
}
|
|
|
|
|
2022-12-22 09:36:18 +01:00
|
|
|
void nullPointer_setkey(const char *key)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
setkey(NULL);
|
|
|
|
}
|
|
|
|
|
2022-12-22 09:19:46 +01:00
|
|
|
void nullPointer_encrypt(char block[64], int edflag)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
encrypt(NULL, edflag);
|
|
|
|
encrypt(block, edflag);
|
|
|
|
}
|
|
|
|
|
2022-12-22 09:12:57 +01:00
|
|
|
int nullPointer_getopt(int argc, char* const argv[], const char* optstring)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getopt(argc, NULL, optstring);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getopt(argc, argv, NULL);
|
|
|
|
return getopt(argc, argv, optstring);
|
|
|
|
}
|
|
|
|
|
2022-06-03 10:06:32 +02:00
|
|
|
int invalidFunctionArgStr_mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
|
|
|
|
{
|
2022-06-03 10:20:19 +02:00
|
|
|
// No warning is expected for:
|
2022-06-03 10:06:32 +02:00
|
|
|
const char msg = '0';
|
|
|
|
(void) mq_send(mqdes, &msg, 1, 0);
|
|
|
|
return mq_send(mqdes, msg_ptr, msg_len, 0);
|
|
|
|
}
|
|
|
|
|
2022-06-02 19:30:29 +02:00
|
|
|
void invalidFunctionArgStr_mbsnrtowcs(void)
|
|
|
|
{
|
|
|
|
wchar_t wenough[10];
|
|
|
|
mbstate_t s;
|
|
|
|
memset (&s, '\0', sizeof (s));
|
|
|
|
const char* cp = "ABC";
|
|
|
|
wcscpy (wenough, L"DEF");
|
|
|
|
// No warning is expected for - #11119
|
|
|
|
if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1 || wcscmp (wenough, L"AEF") != 0) {}
|
|
|
|
}
|
|
|
|
|
2022-05-02 16:48:22 +02:00
|
|
|
int nullPointer_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwuid_r(uid, NULL, buffer, bufsize, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwuid_r(uid, pwd, NULL, bufsize, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwuid_r(uid, pwd, buffer, bufsize, NULL);
|
|
|
|
return getpwuid_r(uid, pwd, buffer, bufsize, result);
|
|
|
|
}
|
|
|
|
|
2022-05-02 16:41:33 +02:00
|
|
|
int nullPointer_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwnam_r(NULL, pwd, buffer, bufsize, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwnam_r(name, NULL, buffer, bufsize, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwnam_r(name, pwd, NULL, bufsize, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwnam_r(name, pwd, buffer, bufsize, NULL);
|
|
|
|
return getpwnam_r(name, pwd, buffer, bufsize, result);
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:56:47 +02:00
|
|
|
int nullPointer_fgetpwent_r(FILE *restrict stream, struct passwd *restrict pwbuf, char *restrict buf, size_t buflen, struct passwd **restrict pwbufp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) fgetpwent_r(NULL, pwbuf, buf, buflen, pwbufp);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) fgetpwent_r(stream, NULL, buf, buflen, pwbufp);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) fgetpwent_r(stream, pwbuf, NULL, buflen, pwbufp);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) fgetpwent_r(stream, pwbuf, buf, buflen, NULL);
|
|
|
|
return fgetpwent_r(stream, pwbuf, buf, buflen, pwbufp);
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:51:58 +02:00
|
|
|
int nullPointer_getpwent_r(struct passwd *restrict pwbuf, char *restrict buf, size_t buflen, struct passwd **restrict pwbufp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwent_r(NULL, buf, buflen, pwbufp);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwent_r(pwbuf, NULL, buflen, pwbufp);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getpwent_r(pwbuf, buf, buflen, NULL);
|
|
|
|
return getpwent_r(pwbuf, buf, buflen, pwbufp);
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:28:54 +02:00
|
|
|
int nullPointer_getgrgid_r(gid_t gid, struct group *restrict grp, char *restrict buf, size_t buflen, struct group **restrict result)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrgid_r(gid, NULL, buf, buflen, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrgid_r(gid, grp, NULL, buflen, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrgid_r(gid, grp, buf, buflen, NULL);
|
|
|
|
return getgrgid_r(gid, grp, buf, buflen, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nullPointer_getgrnam_r(const char *restrict name, struct group *restrict grp, char *restrict buf, size_t buflen, struct group **restrict result)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrnam_r(NULL, grp, buf, buflen, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrnam_r(name, NULL, buf, buflen, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrnam_r(name, grp, NULL, buflen, result);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) getgrnam_r(name, grp, buf, buflen, NULL);
|
|
|
|
return getgrnam_r(name, grp, buf, buflen, result);
|
|
|
|
}
|
|
|
|
|
2022-05-01 15:24:57 +02:00
|
|
|
void knownConditionTrueFalse_ffs(int i)
|
|
|
|
{
|
|
|
|
// ffs() returns the position of the first bit set, or 0 if no bits are set in i.
|
|
|
|
const int x = ffs(0);
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
2022-05-01 18:15:32 +02:00
|
|
|
if (x == 0) {} // always true
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
|
|
|
if (x == 1) {} // always false
|
2022-05-01 15:24:57 +02:00
|
|
|
if (ffs(i) == 0) {}
|
|
|
|
}
|
|
|
|
|
2022-05-01 14:17:49 +02:00
|
|
|
ssize_t nullPointer_readlink(const char *path, char *buf, size_t bufsiz)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)readlink(NULL, buf, bufsiz);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)readlink(path, NULL, bufsiz);
|
|
|
|
return readlink(path, buf, bufsiz);
|
|
|
|
}
|
|
|
|
|
2022-05-01 14:08:08 +02:00
|
|
|
int nullPointer_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) readlinkat(dirfd, NULL, buf, bufsiz);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) readlinkat(dirfd, pathname, NULL, bufsiz);
|
|
|
|
return readlinkat(dirfd, pathname, buf, bufsiz);
|
|
|
|
}
|
|
|
|
|
2022-05-01 12:27:14 +02:00
|
|
|
ssize_t nullPointer_recv(int sockfd, void *buf, size_t len, int flags)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) recv(sockfd, NULL, len, flags);
|
|
|
|
return recv(sockfd, buf, len, flags);
|
|
|
|
}
|
|
|
|
|
2022-05-01 12:24:15 +02:00
|
|
|
ssize_t nullPointer_recvfrom(int sockfd, void *buf, size_t len, int flags,
|
|
|
|
struct sockaddr *src_addr, socklen_t *addrlen)
|
|
|
|
{
|
|
|
|
// If src_addr is not NULL, and the underlying protocol provides the source address, this source address is filled in.
|
|
|
|
(void) recvfrom(sockfd, buf, len, flags, NULL, addrlen);
|
|
|
|
(void) recvfrom(sockfd, buf, len, flags, src_addr, NULL);
|
|
|
|
(void) recvfrom(sockfd, buf, len, flags, NULL, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) recvfrom(sockfd, NULL, len, flags, src_addr, addrlen);
|
|
|
|
return recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
|
|
|
|
}
|
2022-05-01 11:41:31 +02:00
|
|
|
int nullPointer_semop(int semid, struct sembuf *sops, size_t nsops)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)semop(semid, NULL, nsops);
|
|
|
|
return semop(semid, sops, nsops);
|
|
|
|
}
|
|
|
|
|
2022-04-26 18:13:24 +02:00
|
|
|
int nullPointer_socketpair(int domain, int t, int protocol, int sv[2])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) socketpair(domain, t, protocol, NULL);
|
|
|
|
return socketpair(domain, t, protocol, sv);
|
|
|
|
}
|
|
|
|
|
2022-04-26 17:24:39 +02:00
|
|
|
void nullPointer_lcong48(unsigned short param[7])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) lcong48(NULL);
|
|
|
|
return lcong48(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
long int nullPointer_jrand48(unsigned short xsubi[3])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) jrand48(NULL);
|
|
|
|
return jrand48(xsubi);
|
|
|
|
}
|
|
|
|
|
|
|
|
long int nullPointer_nrand48(unsigned short xsubi[3])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) nrand48(NULL);
|
|
|
|
return nrand48(xsubi);
|
|
|
|
}
|
|
|
|
|
|
|
|
double nullPointer_erand48(unsigned short xsubi[3])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) erand48(NULL);
|
|
|
|
return erand48(xsubi);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short *nullPointer_seed48(unsigned short seed16v[3])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) seed48(NULL);
|
|
|
|
return seed48(seed16v);
|
|
|
|
}
|
|
|
|
|
2022-04-26 10:04:15 +02:00
|
|
|
int nullPointer_getlogin_r(char *buf, size_t bufsize)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)getlogin_r(NULL,bufsize);
|
|
|
|
return getlogin_r(buf,bufsize);
|
|
|
|
}
|
|
|
|
|
2022-04-26 09:37:08 +02:00
|
|
|
ssize_t uninitvar_pread(int fd, void *buf, size_t nbyte, off_t offset)
|
|
|
|
{
|
|
|
|
int Fd;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)pread(Fd,buf,nbyte,offset);
|
|
|
|
size_t Nbyte;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)pread(fd,buf,Nbyte,offset);
|
|
|
|
off_t Offset;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)pread(fd,buf,nbyte,Offset);
|
|
|
|
return pread(fd,buf,nbyte,offset);
|
|
|
|
}
|
|
|
|
|
2022-04-26 09:26:39 +02:00
|
|
|
ssize_t nullPointer_pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)pwrite(fd,NULL,nbyte,offset);
|
|
|
|
return pwrite(fd,buf,nbyte,offset);
|
|
|
|
}
|
|
|
|
|
2022-04-25 12:46:27 +02:00
|
|
|
int nullPointer_ttyname_r(int fd, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)ttyname_r(fd,NULL,buflen);
|
|
|
|
return ttyname_r(fd,buf,buflen);
|
|
|
|
}
|
|
|
|
|
2022-04-25 15:49:37 +02:00
|
|
|
size_t bufferAccessOutOfBounds_wcsnrtombs(char *restrict dest, const wchar_t **restrict src, size_t nwc, size_t len, mbstate_t *restrict ps)
|
|
|
|
{
|
|
|
|
char buf[42];
|
|
|
|
(void)wcsnrtombs(buf,src,nwc,42,ps);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
(void)wcsnrtombs(buf,src,nwc,43,ps);
|
|
|
|
return wcsnrtombs(dest,src,nwc,len,ps);
|
|
|
|
}
|
|
|
|
|
2022-04-25 12:26:02 +02:00
|
|
|
size_t nullPointer_wcsnrtombs(char *restrict dest, const wchar_t **restrict src, size_t nwc, size_t len, mbstate_t *restrict ps)
|
|
|
|
{
|
|
|
|
// It is allowed to set the first arg to NULL
|
|
|
|
(void)wcsnrtombs(NULL,src,nwc,len,ps);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcsnrtombs(dest,NULL,nwc,len,ps);
|
2022-04-25 15:54:44 +02:00
|
|
|
// It is allowed to set the last arg to NULL
|
2022-04-25 12:26:02 +02:00
|
|
|
(void)wcsnrtombs(dest,src,nwc,len,NULL);
|
|
|
|
return wcsnrtombs(dest,src,nwc,len,ps);
|
|
|
|
}
|
|
|
|
|
2022-04-22 08:07:20 +02:00
|
|
|
int nullPointer_wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcsncasecmp(NULL,s2,n);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcsncasecmp(s1,NULL,n);
|
|
|
|
return wcsncasecmp(s1,s2,n);
|
|
|
|
}
|
|
|
|
|
2022-04-20 17:32:26 +02:00
|
|
|
int uninitvar_wcwidth(const wchar_t c)
|
|
|
|
{
|
|
|
|
wchar_t wc;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)wcwidth(wc);
|
|
|
|
// No warning is expected
|
|
|
|
return wcwidth(c);
|
|
|
|
}
|
|
|
|
|
2022-04-20 15:27:14 +02:00
|
|
|
int nullPointer_wcsnlen(const wchar_t *s, size_t n)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcsnlen(NULL, n);
|
|
|
|
// No warning is expected
|
|
|
|
return wcsnlen(s, n);
|
|
|
|
}
|
|
|
|
|
2022-04-21 09:10:13 +02:00
|
|
|
size_t bufferAccessOutOfBounds_wcsnlen(void) // #10997
|
2022-04-21 09:02:02 +02:00
|
|
|
{
|
|
|
|
wchar_t buf[2]={L'4',L'2'};
|
|
|
|
size_t len = wcsnlen(buf,2);
|
|
|
|
// TODO cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
len+=wcsnlen(buf,3);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2022-04-20 17:40:03 +02:00
|
|
|
int nullPointer_gethostname(char *s, size_t n)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)gethostname(NULL, n);
|
|
|
|
// No warning is expected
|
|
|
|
return gethostname(s, n);
|
|
|
|
}
|
|
|
|
|
2022-04-20 15:23:46 +02:00
|
|
|
int nullPointer_wcswidth(const wchar_t *s, size_t n)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcswidth(NULL, n);
|
|
|
|
// No warning is expected
|
|
|
|
return wcswidth(s, n);
|
|
|
|
}
|
|
|
|
|
2022-04-20 07:45:38 +02:00
|
|
|
int nullPointer_aio_cancel(int fd, struct aiocb *aiocbp)
|
|
|
|
{
|
|
|
|
// No warning is expected
|
|
|
|
(void)aio_cancel(fd, NULL);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_cancel(fd, aiocbp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nullPointer_aio_fsync(int op, struct aiocb *aiocbp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)aio_fsync(op, NULL);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_fsync(op, aiocbp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t nullPointer_aio_return(struct aiocb *aiocbp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)aio_return(NULL);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_return(aiocbp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nullPointer_aio_error(const struct aiocb *aiocbp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)aio_error(NULL);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_error(aiocbp);
|
|
|
|
}
|
|
|
|
|
2022-04-20 07:27:28 +02:00
|
|
|
int nullPointer_aio_read(struct aiocb *aiocbp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)aio_read(NULL);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_read(aiocbp);
|
|
|
|
}
|
|
|
|
|
2022-04-20 07:45:38 +02:00
|
|
|
int nullPointer_aio_write(struct aiocb *aiocbp)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)aio_write(NULL);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_write(aiocbp);
|
|
|
|
}
|
|
|
|
|
2022-04-19 21:13:09 +02:00
|
|
|
int nullPointer_aio_suspend(const struct aiocb *const aiocb_list[], int nitems, const struct timespec *restrict timeout)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)aio_suspend(NULL, nitems, timeout);
|
|
|
|
// No warning is expected
|
|
|
|
return aio_suspend(aiocb_list, nitems, timeout);
|
|
|
|
}
|
|
|
|
|
2022-02-09 08:34:35 +01:00
|
|
|
// Note: Since glibc 2.28, this function symbol is no longer available to newly linked applications.
|
|
|
|
void invalidFunctionArg_llseek(int fd, loff_t offset, int origin)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)llseek(-1, offset, SEEK_SET);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)llseek(fd, offset, -1);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)llseek(fd, offset, 3);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)llseek(fd, offset, 42+SEEK_SET);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)llseek(fd, offset, SEEK_SET+42);
|
|
|
|
// No invalidFunctionArg warning is expected for
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
(void)llseek(0, offset, origin);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
(void)llseek(fd, offset, origin);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
(void)llseek(fd, offset, SEEK_SET);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
(void)llseek(fd, offset, SEEK_CUR);
|
|
|
|
// cppcheck-suppress llseekCalled
|
|
|
|
(void)llseek(fd, offset, SEEK_END);
|
|
|
|
}
|
2022-02-07 14:15:48 +01:00
|
|
|
|
|
|
|
void invalidFunctionArg_lseek64(int fd, off_t offset, int origin)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek64(-1, offset, SEEK_SET);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek64(fd, offset, -1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek64(fd, offset, 3);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek64(fd, offset, 42+SEEK_SET);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek64(fd, offset, SEEK_SET+42);
|
|
|
|
// No warning is expected for
|
|
|
|
(void)lseek64(0, offset, origin);
|
|
|
|
(void)lseek64(fd, offset, origin);
|
|
|
|
(void)lseek64(fd, offset, SEEK_SET);
|
|
|
|
(void)lseek64(fd, offset, SEEK_CUR);
|
|
|
|
(void)lseek64(fd, offset, SEEK_END);
|
|
|
|
}
|
|
|
|
|
2022-02-07 13:58:38 +01:00
|
|
|
void invalidFunctionArg_lseek(int fd, off_t offset, int origin)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek(-1, offset, SEEK_SET);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek(fd, offset, -1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek(fd, offset, 3);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek(fd, offset, 42+SEEK_SET);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)lseek(fd, offset, SEEK_SET+42);
|
|
|
|
// No warning is expected for
|
|
|
|
(void)lseek(0, offset, origin);
|
|
|
|
(void)lseek(fd, offset, origin);
|
|
|
|
(void)lseek(fd, offset, SEEK_SET);
|
|
|
|
(void)lseek(fd, offset, SEEK_CUR);
|
|
|
|
(void)lseek(fd, offset, SEEK_END);
|
|
|
|
}
|
|
|
|
|
2022-02-07 09:03:39 +01:00
|
|
|
void invalidFunctionArg_fseeko(FILE* stream, off_t offset, int origin)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)fseeko(stream, offset, -1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)fseeko(stream, offset, 3);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)fseeko(stream, offset, 42+SEEK_SET);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)fseeko(stream, offset, SEEK_SET+42);
|
|
|
|
// No warning is expected for
|
|
|
|
(void)fseeko(stream, offset, origin);
|
|
|
|
(void)fseeko(stream, offset, SEEK_SET);
|
|
|
|
(void)fseeko(stream, offset, SEEK_CUR);
|
|
|
|
(void)fseeko(stream, offset, SEEK_END);
|
|
|
|
}
|
|
|
|
|
2022-04-22 08:23:17 +02:00
|
|
|
wchar_t *nullPointer_wcpncpy(wchar_t *dest, const wchar_t *src, size_t n)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcpncpy(NULL, src, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)wcpncpy(dest, NULL, n);
|
|
|
|
return wcpncpy(dest, src, n);
|
|
|
|
}
|
|
|
|
|
2022-04-22 08:18:21 +02:00
|
|
|
int nullPointer_utimes(const char *path, const struct timeval times[2])
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
// cppcheck-suppress utimesCalled
|
|
|
|
(void)utimes(NULL, times);
|
|
|
|
// cppcheck-suppress utimesCalled
|
|
|
|
return utimes(path, times);
|
|
|
|
}
|
|
|
|
|
2021-07-11 16:42:19 +02:00
|
|
|
char * overlappingWriteFunction_stpcpy(char *src, char *dest)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) stpcpy(dest, src);
|
|
|
|
// cppcheck-suppress overlappingWriteFunction
|
|
|
|
return stpcpy(src, src);
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:15:54 +02:00
|
|
|
int nullPointer_strcasecmp(char *a, char *b)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) strcasecmp(a, b);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) strcasecmp(a, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
return strcasecmp(NULL, b);
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:13:49 +02:00
|
|
|
int nullPointer_strncasecmp(char *a, char *b, size_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) strncasecmp(a, b, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) strncasecmp(a, NULL, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
return strncasecmp(NULL, b, n);
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:18:38 +02:00
|
|
|
int nullPointer_bcmp(const void *a, const void *b, size_t n)
|
|
|
|
{
|
|
|
|
// No nullPointer warning shall be shown:
|
|
|
|
// cppcheck-suppress bcmpCalled
|
|
|
|
(void) bcmp(a, b, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
2022-04-20 18:21:24 +02:00
|
|
|
// cppcheck-suppress bcmpCalled
|
2022-04-20 18:18:38 +02:00
|
|
|
(void) bcmp(a, NULL, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
2022-04-20 18:21:24 +02:00
|
|
|
// cppcheck-suppress bcmpCalled
|
2022-04-20 18:18:38 +02:00
|
|
|
return bcmp(NULL, b, n);
|
|
|
|
}
|
|
|
|
|
2022-04-20 20:57:58 +02:00
|
|
|
void nullPointer_bzero(void *s, size_t n)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
// cppcheck-suppress bzeroCalled
|
|
|
|
bzero(NULL,n);
|
|
|
|
// No nullPointer-warning shall be shown:
|
|
|
|
// cppcheck-suppress bzeroCalled
|
|
|
|
bzero(s,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bufferAccessOutOfBounds_bzero(void *s, size_t n)
|
|
|
|
{
|
|
|
|
char buf[42];
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
// cppcheck-suppress bzeroCalled
|
|
|
|
bzero(buf,43);
|
|
|
|
// cppcheck-suppress bzeroCalled
|
|
|
|
bzero(buf,42);
|
|
|
|
// No nullPointer-warning shall be shown:
|
|
|
|
// cppcheck-suppress bzeroCalled
|
|
|
|
bzero(s,n);
|
|
|
|
}
|
|
|
|
|
2022-04-21 09:02:02 +02:00
|
|
|
size_t bufferAccessOutOfBounds_strnlen(const char *s, size_t maxlen)
|
|
|
|
{
|
2022-06-02 09:41:10 +02:00
|
|
|
const char buf[2]={'4','2'};
|
2022-04-21 09:02:02 +02:00
|
|
|
size_t len = strnlen(buf,2);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
len+=strnlen(buf,3);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2022-08-29 12:24:58 +02:00
|
|
|
void bufferAccessOutOfBounds_wcpncpy()
|
|
|
|
{
|
|
|
|
wchar_t s[16];
|
|
|
|
wcpncpy(s, L"abc", 16);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
wcpncpy(s, L"abc", 17);
|
|
|
|
}
|
|
|
|
|
2022-04-21 09:02:02 +02:00
|
|
|
size_t nullPointer_strnlen(const char *s, size_t maxlen)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) strnlen(s, maxlen);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
return strnlen(NULL, maxlen);
|
|
|
|
}
|
|
|
|
|
2022-04-20 17:52:38 +02:00
|
|
|
char * nullPointer_stpcpy(char *src, char *dest)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) stpcpy(dest, src);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) stpcpy(dest, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
return stpcpy(NULL, src);
|
|
|
|
}
|
|
|
|
|
2022-04-20 17:58:50 +02:00
|
|
|
char * nullPointer_strsep(char **stringptr, char *delim)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) strsep(stringptr, delim);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) strsep(stringptr, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
return strsep(NULL, delim);
|
|
|
|
}
|
|
|
|
|
2021-07-11 16:38:25 +02:00
|
|
|
void overlappingWriteFunction_bcopy(char *buf, const size_t count)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
// cppcheck-suppress bcopyCalled
|
|
|
|
bcopy(&buf[0], &buf[3], count); // size is not known
|
|
|
|
// cppcheck-suppress bcopyCalled
|
|
|
|
bcopy(&buf[0], &buf[3], 3U); // no-overlap
|
|
|
|
// cppcheck-suppress bcopyCalled
|
2022-04-21 08:31:22 +02:00
|
|
|
bcopy(&buf[0], &buf[3], 4U); // The result is correct, even when both areas overlap.
|
|
|
|
}
|
|
|
|
|
|
|
|
void nullPointer_bcopy(const void *src, void *dest, size_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
// cppcheck-suppress bcopyCalled
|
|
|
|
bcopy(src, dest, n);
|
|
|
|
// cppcheck-suppress bcopyCalled
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
bcopy(NULL, dest, n);
|
|
|
|
// cppcheck-suppress bcopyCalled
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
bcopy(src, NULL, n);
|
2021-07-11 16:38:25 +02:00
|
|
|
}
|
|
|
|
|
2021-07-10 18:41:36 +02:00
|
|
|
void overlappingWriteFunction_memccpy(unsigned char *src, unsigned char *dest, int c, size_t count)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void)memccpy(dest, src, c, count);
|
|
|
|
(void)memccpy(dest, src, 42, count);
|
|
|
|
// cppcheck-suppress overlappingWriteFunction
|
|
|
|
(void)memccpy(dest, dest, c, 4);
|
|
|
|
// cppcheck-suppress overlappingWriteFunction
|
|
|
|
(void)memccpy(dest, dest+3, c, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void overlappingWriteFunction_stpncpy(char *src, char *dest, ssize_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) stpncpy(dest, src, n);
|
|
|
|
// cppcheck-suppress overlappingWriteFunction
|
|
|
|
(void)stpncpy(src, src+3, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t* overlappingWriteFunction_wcpncpy(wchar_t *src, wchar_t *dest, ssize_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
(void) wcpncpy(dest, src, n);
|
|
|
|
// cppcheck-suppress overlappingWriteFunction
|
|
|
|
return wcpncpy(src, src+3, 4);
|
|
|
|
}
|
2020-02-22 14:49:36 +01:00
|
|
|
|
2021-07-10 18:28:26 +02:00
|
|
|
void overlappingWriteFunction_swab(char *src, char *dest, ssize_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
swab(dest, src, n);
|
|
|
|
// cppcheck-suppress overlappingWriteFunction
|
|
|
|
swab(src, src+3, 4);
|
|
|
|
}
|
|
|
|
|
2022-04-25 18:34:31 +02:00
|
|
|
void bufferAccessOutOfBounds_swab(char *src, char *dest, ssize_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
swab(dest, src, n);
|
|
|
|
char srcBuf[42] = {0};
|
|
|
|
char destBuf[42] = {0};
|
|
|
|
swab(srcBuf, dest, 42);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
swab(srcBuf, dest, 43);
|
|
|
|
swab(src, destBuf, 42);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
swab(src, destBuf, 43);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nullPointer_swab(char *src, char *dest, ssize_t n)
|
|
|
|
{
|
|
|
|
// No warning shall be shown:
|
|
|
|
swab(dest, src, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
swab(NULL, dest, n);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
swab(src, NULL, n);
|
|
|
|
}
|
|
|
|
|
2020-02-22 14:49:36 +01:00
|
|
|
bool invalidFunctionArgBool_isascii(bool b, int c)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress invalidFunctionArgBool
|
|
|
|
(void)isascii(b);
|
|
|
|
// cppcheck-suppress invalidFunctionArgBool
|
|
|
|
return isascii(c != 0);
|
|
|
|
}
|
2015-02-15 18:11:09 +01:00
|
|
|
|
2019-10-21 10:09:20 +02:00
|
|
|
void uninitvar_putenv(char * envstr)
|
|
|
|
{
|
|
|
|
// No warning is expected
|
|
|
|
(void)putenv(envstr);
|
|
|
|
|
|
|
|
char * p;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)putenv(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nullPointer_putenv(char * envstr)
|
|
|
|
{
|
|
|
|
// No warning is expected
|
|
|
|
(void)putenv(envstr);
|
|
|
|
|
|
|
|
char * p=NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)putenv(p);
|
|
|
|
}
|
|
|
|
|
2019-05-25 23:32:28 +02:00
|
|
|
void memleak_scandir(void)
|
|
|
|
{
|
|
|
|
struct dirent **namelist;
|
|
|
|
int n = scandir(".", &namelist, NULL, alphasort);
|
|
|
|
if (n == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://man7.org/linux/man-pages/man3/scandir.3.html
|
|
|
|
/* The scandir() function scans the directory dirp, calling filter() on
|
|
|
|
each directory entry. Entries for which filter() returns nonzero are
|
|
|
|
stored in strings allocated via malloc(3), sorted using qsort(3) with
|
|
|
|
the comparison function compar(), and collected in array namelist
|
|
|
|
which is allocated via malloc(3). If filter is NULL, all entries are
|
|
|
|
selected.*/
|
|
|
|
|
|
|
|
// TODO: cppcheck-suppress memleak
|
|
|
|
}
|
|
|
|
|
|
|
|
void no_memleak_scandir(void)
|
|
|
|
{
|
|
|
|
struct dirent **namelist;
|
|
|
|
int n = scandir(".", &namelist, NULL, alphasort);
|
|
|
|
if (n == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (n--) {
|
|
|
|
free(namelist[n]);
|
|
|
|
}
|
|
|
|
free(namelist);
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:16:11 +02:00
|
|
|
void validCode(va_list valist_arg1, va_list valist_arg2)
|
2019-05-03 16:35:15 +02:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
if (posix_memalign(&ptr, sizeof(void *), sizeof(void *)) == 0)
|
|
|
|
free(ptr);
|
2019-09-06 10:16:11 +02:00
|
|
|
syslog(LOG_ERR, "err %u", 0U);
|
|
|
|
syslog(LOG_WARNING, "warn %d %d", 5, 1);
|
|
|
|
vsyslog(LOG_EMERG, "emerg %d", valist_arg1);
|
|
|
|
vsyslog(LOG_INFO, "test %s %d %p", valist_arg2);
|
2019-09-06 16:37:51 +02:00
|
|
|
|
|
|
|
void* handle = dlopen("/lib.so", RTLD_NOW);
|
|
|
|
if (handle) {
|
|
|
|
dlclose(handle);
|
|
|
|
}
|
2019-05-03 16:35:15 +02:00
|
|
|
}
|
|
|
|
|
2022-04-27 10:41:57 +02:00
|
|
|
ssize_t nullPointer_send(int socket, const void *buf, size_t len, int flags)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) send(socket, NULL, len, flags);
|
|
|
|
return send(socket, buf, len, flags);
|
|
|
|
}
|
|
|
|
|
2022-04-27 10:35:43 +02:00
|
|
|
ssize_t nullPointer_sendto(int socket, const void *message, size_t length,
|
|
|
|
int flags, const struct sockaddr *dest_addr,
|
|
|
|
socklen_t dest_len)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void) sendto(socket, NULL, length, flags, dest_addr, dest_len);
|
|
|
|
(void) sendto(socket, message, length, flags, NULL, dest_len);
|
|
|
|
return sendto(socket, message, length, flags, dest_addr, dest_len);
|
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void bufferAccessOutOfBounds(int fd)
|
|
|
|
{
|
|
|
|
char a[5];
|
|
|
|
read(fd,a,5);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
read(fd,a,6);
|
|
|
|
write(fd,a,5);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
write(fd,a,6);
|
|
|
|
recv(fd,a,5,0);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
recv(fd,a,6,0);
|
|
|
|
recvfrom(fd,a,5,0,0x0,0x0);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
recvfrom(fd,a,6,0,0x0,0x0);
|
|
|
|
send(fd,a,5,0);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
send(fd,a,6,0);
|
|
|
|
sendto(fd,a,5,0,0x0,0x0);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
sendto(fd,a,6,0,0x0,0x0);
|
|
|
|
// cppcheck-suppress constStatement
|
|
|
|
0;
|
2018-05-09 18:20:45 +02:00
|
|
|
readlink("path", a, 5);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
readlink("path", a, 6);
|
|
|
|
readlinkat(1, "path", a, 5);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
readlinkat(1, "path", a, 6);
|
2018-07-18 09:40:06 +02:00
|
|
|
// This is valid
|
|
|
|
gethostname(a, 5);
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
gethostname(a, 6);
|
2015-02-10 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
2018-07-21 17:52:12 +02:00
|
|
|
void nullPointer(char *p, int fd, pthread_mutex_t mutex)
|
2015-08-14 01:36:44 +02:00
|
|
|
{
|
2015-03-13 18:29:46 +01:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
2015-08-14 01:36:44 +02:00
|
|
|
isatty(0);
|
|
|
|
mkdir(p, 0);
|
|
|
|
getcwd(0, 0);
|
2015-01-30 07:52:32 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress readdirCalled
|
2015-08-14 01:36:44 +02:00
|
|
|
readdir(0);
|
2015-03-08 14:43:25 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress utimeCalled
|
2015-03-08 14:43:25 +01:00
|
|
|
utime(NULL, NULL);
|
2017-04-29 17:57:16 +02:00
|
|
|
// not implemented yet: cppcheck-suppress nullPointer
|
2017-04-26 14:25:14 +02:00
|
|
|
read(fd,NULL,42);
|
2017-04-29 17:57:16 +02:00
|
|
|
read(fd,NULL,0);
|
|
|
|
// not implemented yet: cppcheck-suppress nullPointer
|
2017-04-26 14:25:14 +02:00
|
|
|
write(fd,NULL,42);
|
2017-04-29 17:57:16 +02:00
|
|
|
write(fd,NULL,0);
|
2018-01-18 13:56:36 +01:00
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
open(NULL, 0);
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
open(NULL, 0, 0);
|
2018-01-22 14:54:14 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
int ret = access(NULL, 0);
|
2018-01-29 11:19:31 +01:00
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
fdopen(fd, NULL);
|
2018-01-31 10:58:30 +01:00
|
|
|
// cppcheck-suppress strtokCalled
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
strtok(p, NULL);
|
2018-07-21 17:52:12 +02:00
|
|
|
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
pthread_mutex_init(NULL, NULL);
|
|
|
|
// Second argument can be NULL
|
|
|
|
pthread_mutex_init(&mutex, NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
pthread_mutex_destroy(NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
pthread_mutex_lock(NULL);
|
|
|
|
// cppcheck-suppress nullPointer
|
2019-07-07 12:57:02 +02:00
|
|
|
(void)pthread_mutex_trylock(NULL);
|
2018-07-21 17:52:12 +02:00
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
pthread_mutex_unlock(NULL);
|
2015-01-30 07:52:32 +01:00
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void memleak_getaddrinfo()
|
|
|
|
{
|
|
|
|
//TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
|
|
|
|
struct addrinfo * res=NULL;
|
|
|
|
getaddrinfo("node", NULL, NULL, &res);
|
|
|
|
freeaddrinfo(res);
|
2015-02-21 11:08:58 +01:00
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void memleak_mmap(int fd)
|
|
|
|
{
|
2021-05-13 23:08:58 +02:00
|
|
|
// cppcheck-suppress unusedAllocatedMemory
|
2015-02-16 22:19:51 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
2015-02-15 18:11:09 +01:00
|
|
|
void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
|
|
|
|
// cppcheck-suppress memleak
|
|
|
|
}
|
|
|
|
|
2020-10-29 13:17:33 +01:00
|
|
|
void * memleak_mmap2() // #8327
|
|
|
|
{
|
|
|
|
void * data = mmap(NULL, 10, PROT_READ, MAP_PRIVATE, 1, 0);
|
|
|
|
if (data != MAP_FAILED)
|
|
|
|
return data;
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-02-02 19:30:49 +01:00
|
|
|
|
|
|
|
void * identicalCondition_mmap(int fd, size_t size) // #9940
|
|
|
|
{
|
|
|
|
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
if (buffer == MAP_FAILED) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
2020-10-29 13:17:33 +01:00
|
|
|
|
2022-11-26 15:45:27 +01:00
|
|
|
int munmap_no_double_free(int tofd, // #11396
|
|
|
|
int fromfd,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
void* fptr = mmap(NULL,len,PROT_READ|PROT_WRITE,MAP_SHARED,fromfd,(off_t)0);
|
|
|
|
if (fptr == MAP_FAILED) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* tptr = mmap(NULL,len,PROT_READ|PROT_WRITE,MAP_SHARED,tofd,(off_t)0);
|
|
|
|
if (tptr == MAP_FAILED) {
|
|
|
|
// cppcheck-suppress memleak
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(tptr,fptr,len);
|
|
|
|
|
|
|
|
if ((rc = munmap(fptr,len)) != 0) {
|
|
|
|
// cppcheck-suppress memleak
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rc = munmap(tptr,len)) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-01-30 08:43:15 +01:00
|
|
|
void resourceLeak_fdopen(int fd)
|
|
|
|
{
|
2018-01-29 11:19:31 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
2015-02-15 18:11:09 +01:00
|
|
|
FILE *f = fdopen(fd, "r");
|
|
|
|
// cppcheck-suppress resourceLeak
|
|
|
|
}
|
|
|
|
|
2019-05-16 15:53:22 +02:00
|
|
|
void resourceLeak_mkstemp(char *template)
|
|
|
|
{
|
2019-05-17 09:32:14 +02:00
|
|
|
// cppcheck-suppress unreadVariable
|
|
|
|
int fp = mkstemp(template);
|
|
|
|
// cppcheck-suppress resourceLeak
|
2019-05-16 15:53:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void no_resourceLeak_mkstemp_01(char *template)
|
|
|
|
{
|
2019-05-17 09:32:14 +02:00
|
|
|
int fp = mkstemp(template);
|
|
|
|
close(fp);
|
2019-05-16 15:53:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int no_resourceLeak_mkstemp_02(char *template)
|
|
|
|
{
|
2019-05-17 09:32:14 +02:00
|
|
|
return mkstemp(template);
|
2019-05-16 15:53:22 +02:00
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void resourceLeak_fdopendir(int fd)
|
|
|
|
{
|
2015-02-16 22:19:51 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
2015-02-15 18:11:09 +01:00
|
|
|
DIR* leak1 = fdopendir(fd);
|
|
|
|
// cppcheck-suppress resourceLeak
|
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void resourceLeak_opendir(void)
|
|
|
|
{
|
2015-02-16 22:19:51 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
2015-02-15 18:11:09 +01:00
|
|
|
DIR* leak1 = opendir("abc");
|
|
|
|
// cppcheck-suppress resourceLeak
|
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void resourceLeak_socket(void)
|
|
|
|
{
|
2015-02-16 22:19:51 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
2015-02-15 18:11:09 +01:00
|
|
|
int s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
// cppcheck-suppress resourceLeak
|
|
|
|
}
|
|
|
|
|
2018-01-18 13:56:36 +01:00
|
|
|
void resourceLeak_open1(void)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress unreadVariable
|
|
|
|
int fd = open("file", O_RDWR | O_CREAT);
|
2018-01-19 23:26:28 +01:00
|
|
|
// cppcheck-suppress resourceLeak
|
2018-01-18 13:56:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void resourceLeak_open2(void)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress unreadVariable
|
|
|
|
int fd = open("file", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
2018-01-19 23:26:28 +01:00
|
|
|
// cppcheck-suppress resourceLeak
|
2018-01-18 13:56:36 +01:00
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void noleak(int x, int y, int z)
|
|
|
|
{
|
|
|
|
DIR *p1 = fdopendir(x);
|
|
|
|
closedir(p1);
|
|
|
|
DIR *p2 = opendir("abc");
|
|
|
|
closedir(p2);
|
|
|
|
int s = socket(AF_INET,SOCK_STREAM,0);
|
|
|
|
close(s);
|
2018-01-18 13:56:36 +01:00
|
|
|
int fd1 = open("a", O_RDWR | O_CREAT);
|
|
|
|
close(fd1);
|
|
|
|
int fd2 = open("a", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
close(fd2);
|
2015-08-14 01:36:44 +02:00
|
|
|
/* TODO: add configuration for open/fdopen
|
|
|
|
// #2830
|
|
|
|
int fd = open("path", O_RDONLY);
|
|
|
|
FILE *f = fdopen(fd, "rt");
|
|
|
|
fclose(f);
|
2021-08-07 20:51:18 +02:00
|
|
|
*/
|
2015-02-15 18:11:09 +01:00
|
|
|
}
|
2015-02-16 16:25:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
// unused return value
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void ignoredReturnValue(void *addr, int fd)
|
|
|
|
{
|
2015-02-16 16:25:27 +01:00
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
mmap(addr, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
2015-02-16 22:19:51 +01:00
|
|
|
getuid();
|
2018-01-22 14:54:14 +01:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
access("filename", 1);
|
2020-09-30 15:44:06 +02:00
|
|
|
// no ignoredReturnValue shall be shown for
|
|
|
|
setuid(42);
|
2015-02-16 16:25:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// valid range
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void invalidFunctionArg()
|
|
|
|
{
|
2015-02-16 16:25:27 +01:00
|
|
|
// cppcheck-suppress invalidFunctionArg
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress usleepCalled
|
2015-02-16 16:25:27 +01:00
|
|
|
usleep(-1);
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress usleepCalled
|
2015-02-16 16:25:27 +01:00
|
|
|
usleep(0);
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress usleepCalled
|
2015-02-16 16:25:27 +01:00
|
|
|
usleep(999999);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress usleepCalled
|
2015-02-16 16:25:27 +01:00
|
|
|
usleep(1000000);
|
|
|
|
}
|
2015-02-17 18:08:19 +01:00
|
|
|
|
2019-04-21 12:28:17 +02:00
|
|
|
void invalidFunctionArg_close(int fd)
|
|
|
|
{
|
|
|
|
if (fd < 0) {
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void uninitvar(int fd)
|
|
|
|
{
|
2019-03-02 19:38:11 +01:00
|
|
|
int x1, x2, x3, x4;
|
2015-02-17 18:08:19 +01:00
|
|
|
char buf[2];
|
2015-08-14 01:36:44 +02:00
|
|
|
int decimal, sign;
|
2015-03-08 15:21:50 +01:00
|
|
|
double d;
|
2015-09-10 11:50:47 +02:00
|
|
|
void *p;
|
2019-03-02 19:38:11 +01:00
|
|
|
pthread_mutex_t mutex, mutex1, mutex2, mutex3;
|
2015-02-17 18:08:19 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
write(x1,"ab",2);
|
2018-01-10 15:52:06 +01:00
|
|
|
// TODO cppcheck-suppress uninitvar
|
2015-09-10 13:23:34 +02:00
|
|
|
write(fd,buf,2); // #6325
|
2015-02-17 18:08:19 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
write(fd,"ab",x2);
|
2015-09-10 11:50:47 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
write(fd,p,2);
|
2015-08-14 01:36:44 +02:00
|
|
|
|
|
|
|
|
2015-02-20 20:50:20 +01:00
|
|
|
/* int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags); */
|
|
|
|
regex_t reg;
|
|
|
|
const char * pattern;
|
2019-03-02 19:38:11 +01:00
|
|
|
int cflags1, cflags2;
|
2015-02-20 20:50:20 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
regcomp(®, pattern, cflags1);
|
2015-02-20 20:50:20 +01:00
|
|
|
pattern="";
|
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
regcomp(®, pattern, cflags2);
|
2015-08-14 01:36:44 +02:00
|
|
|
regerror(0, ®, 0, 0);
|
2018-02-22 12:27:46 +01:00
|
|
|
#ifndef __CYGWIN__
|
2015-03-01 20:18:26 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
// cppcheck-suppress unreadVariable
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress ecvtCalled
|
2015-03-01 20:18:26 +01:00
|
|
|
char *buffer = ecvt(d, 11, &decimal, &sign);
|
2018-02-22 12:27:46 +01:00
|
|
|
#endif
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress gcvtCalled
|
2015-03-14 19:40:13 +01:00
|
|
|
gcvt(3.141, 2, buf);
|
2015-08-14 01:36:44 +02:00
|
|
|
|
2021-10-03 20:32:39 +02:00
|
|
|
char *filename1, *filename2;
|
2015-03-08 21:38:43 +01:00
|
|
|
struct utimbuf *times;
|
|
|
|
// cppcheck-suppress uninitvar
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress utimeCalled
|
2021-10-03 20:32:39 +02:00
|
|
|
utime(filename1, times);
|
2015-03-08 21:38:43 +01:00
|
|
|
struct timeval times1[2];
|
|
|
|
// cppcheck-suppress uninitvar
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress utimeCalled
|
2021-10-03 20:32:39 +02:00
|
|
|
utime(filename2, times1);
|
2018-01-23 18:15:37 +01:00
|
|
|
|
2018-01-22 14:54:14 +01:00
|
|
|
// cppcheck-suppress unreadVariable
|
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
int access_ret = access("file", x3);
|
2018-01-29 11:19:31 +01:00
|
|
|
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
fdopen(x4, "rw");
|
2018-01-31 10:58:30 +01:00
|
|
|
|
|
|
|
char *strtok_arg1;
|
|
|
|
// cppcheck-suppress strtokCalled
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
strtok(strtok_arg1, ";");
|
2018-07-21 17:52:12 +02:00
|
|
|
|
2021-05-22 07:39:27 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
pthread_mutex_lock(&mutex1);
|
2021-05-22 07:39:27 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-07-07 12:57:02 +02:00
|
|
|
(void)pthread_mutex_trylock(&mutex2);
|
2021-05-22 07:39:27 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
pthread_mutex_unlock(&mutex3);
|
2018-07-21 17:52:12 +02:00
|
|
|
// after initialization it must be OK to call lock, trylock and unlock for this mutex
|
|
|
|
pthread_mutex_init(&mutex, NULL);
|
|
|
|
pthread_mutex_lock(&mutex);
|
2019-07-07 12:57:02 +02:00
|
|
|
(void)pthread_mutex_trylock(&mutex);
|
2018-07-21 17:52:12 +02:00
|
|
|
pthread_mutex_unlock(&mutex);
|
2015-02-17 18:08:19 +01:00
|
|
|
}
|
2015-02-17 18:16:29 +01:00
|
|
|
|
2015-11-25 11:02:32 +01:00
|
|
|
void uninitvar_getcwd(void)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
size_t size;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)getcwd(buf,size);
|
|
|
|
}
|
|
|
|
|
2015-03-08 21:38:43 +01:00
|
|
|
|
2015-08-14 01:36:44 +02:00
|
|
|
void uninitvar_types(void)
|
|
|
|
{
|
2015-02-17 19:58:07 +01:00
|
|
|
// cppcheck-suppress unassignedVariable
|
2015-02-17 18:16:29 +01:00
|
|
|
blkcnt_t b;
|
|
|
|
// cppcheck-suppress uninitvar
|
2015-02-17 19:58:07 +01:00
|
|
|
b + 1;
|
2015-02-17 18:16:29 +01:00
|
|
|
|
2015-02-17 19:58:07 +01:00
|
|
|
struct dirent d;
|
2019-03-09 15:41:07 +01:00
|
|
|
// TODO cppcheck-suppress uninitvar
|
2015-02-17 19:58:07 +01:00
|
|
|
d.d_ino + 1;
|
2015-02-17 18:16:29 +01:00
|
|
|
}
|
2015-03-11 18:59:34 +01:00
|
|
|
|
2015-09-09 08:53:12 +02:00
|
|
|
void timet_h(struct timespec* ptp1)
|
2015-08-14 01:36:44 +02:00
|
|
|
{
|
2019-03-02 19:38:11 +01:00
|
|
|
clockid_t clk_id1, clk_id2, clk_id3;
|
2015-08-14 01:36:44 +02:00
|
|
|
struct timespec* ptp;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
clock_settime(CLOCK_REALTIME, ptp);
|
2015-09-09 08:53:12 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
clock_settime(clk_id1, ptp);
|
2015-09-09 08:53:12 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
clock_settime(clk_id2, ptp1);
|
2015-09-09 08:53:12 +02:00
|
|
|
|
|
|
|
struct timespec tp;
|
2022-04-11 07:23:44 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2015-09-09 08:53:12 +02:00
|
|
|
clock_settime(CLOCK_REALTIME, &tp); // #6577 - false negative
|
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
clock_settime(clk_id3, &tp);
|
2015-08-14 01:36:44 +02:00
|
|
|
|
|
|
|
time_t clock = time(0);
|
|
|
|
char buf[26];
|
2015-11-22 17:52:47 +01:00
|
|
|
// cppcheck-suppress ctime_rCalled
|
2015-08-14 01:36:44 +02:00
|
|
|
ctime_r(&clock, buf);
|
2015-03-11 18:59:34 +01:00
|
|
|
}
|
2019-01-10 21:14:37 +01:00
|
|
|
|
|
|
|
void dl(const char* libname, const char* func)
|
|
|
|
{
|
|
|
|
void* lib = dlopen(libname, RTLD_NOW);
|
2019-09-04 13:38:19 +02:00
|
|
|
// cppcheck-suppress redundantInitialization
|
2019-01-10 21:14:37 +01:00
|
|
|
// cppcheck-suppress resourceLeak
|
|
|
|
lib = dlopen(libname, RTLD_LAZY);
|
|
|
|
const char* funcname;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
// cppcheck-suppress unreadVariable
|
|
|
|
void* sym = dlsym(lib, funcname);
|
2019-01-12 21:50:02 +01:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
dlsym(lib, "foo");
|
2019-01-10 21:14:37 +01:00
|
|
|
void* uninit;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
dlclose(uninit);
|
|
|
|
// cppcheck-suppress resourceLeak
|
|
|
|
}
|
2019-03-17 14:22:26 +01:00
|
|
|
|
|
|
|
void asctime_r_test(struct tm * tm, char * bufSizeUnknown)
|
|
|
|
{
|
|
|
|
struct tm tm_uninit_data;
|
|
|
|
struct tm * tm_uninit_pointer;
|
|
|
|
char bufSize5[5];
|
|
|
|
char bufSize25[25];
|
|
|
|
char bufSize26[26];
|
|
|
|
char bufSize100[100];
|
|
|
|
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
asctime_r(tm, bufSize5);
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
asctime_r(tm, bufSize25);
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
|
|
|
asctime_r(tm, bufSize26);
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
|
|
|
asctime_r(tm, bufSize100);
|
|
|
|
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
2021-05-22 07:39:27 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-17 14:22:26 +01:00
|
|
|
asctime_r(&tm_uninit_data, bufSize100);
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
asctime_r(tm_uninit_pointer, bufSize100);
|
|
|
|
|
|
|
|
// cppcheck-suppress asctime_rCalled
|
|
|
|
asctime_r(tm, bufSizeUnknown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ctime_r_test(time_t * timep, char * bufSizeUnknown)
|
|
|
|
{
|
|
|
|
time_t time_t_uninit_data;
|
|
|
|
time_t * time_t_uninit_pointer;
|
|
|
|
char bufSize5[5];
|
|
|
|
char bufSize25[25];
|
|
|
|
char bufSize26[26];
|
|
|
|
char bufSize100[100];
|
|
|
|
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
ctime_r(timep, bufSize5);
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
|
|
|
// cppcheck-suppress bufferAccessOutOfBounds
|
|
|
|
ctime_r(timep, bufSize25);
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
|
|
|
ctime_r(timep, bufSize26);
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
|
|
|
ctime_r(timep, bufSize100);
|
|
|
|
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
2021-05-22 07:39:27 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-17 14:22:26 +01:00
|
|
|
ctime_r(&time_t_uninit_data, bufSize100);
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
ctime_r(time_t_uninit_pointer, bufSize100);
|
|
|
|
|
|
|
|
// cppcheck-suppress ctime_rCalled
|
|
|
|
ctime_r(timep, bufSizeUnknown);
|
|
|
|
}
|