forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd.cpp
5088 lines (4401 loc) · 113 KB
/
std.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Test library configuration for std.cfg
//
// Usage:
// $ cppcheck --check-library --library=std --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr test/cfg/std.cpp
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//
// cppcheck-suppress-file valueFlowBailout
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cinttypes>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define __STDC_WANT_LIB_EXT1__ 1
#include <ctime>
#include <cwchar>
#include <deque>
#include <exception>
#include <filesystem>
#include <fstream>
#include <functional>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <memory>
#include <mutex>
#include <numeric>
#include <queue>
#include <set>
#include <streambuf>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <version>
#ifdef __cpp_lib_span
#include <span>
#endif
#if __cplusplus <= 201402L
void unreachableCode_std_unexpected(int &x)
{
// cppcheck-suppress unexpectedCalled
std::unexpected();
// cppcheck-suppress unreachableCode
x=42;
}
#endif
void unreachableCode_std_terminate(int &x)
{
std::terminate();
// cppcheck-suppress unreachableCode
x=42;
}
bool ignoredReturnValue_std_filesystem_exists(const std::filesystem::path &path, std::error_code& ec)
{
// cppcheck-suppress ignoredReturnValue
std::filesystem::exists(path);
// cppcheck-suppress ignoredReturnValue
std::filesystem::exists(path, ec);
const bool b {std::filesystem::exists(path)};
return b && std::filesystem::exists(path, ec);
}
// https://en.cppreference.com/w/cpp/io/manip/quoted
void uninitvar_std_quoted(std::stringstream &ss, const std::string &input, const char delim, const char escape)
{
ss << std::quoted(input);
ss << std::quoted(input, delim);
ss << std::quoted(input, delim, escape);
char delimChar;
// cppcheck-suppress uninitvar
ss << std::quoted(input, delimChar);
char escapeChar;
// cppcheck-suppress uninitvar
ss << std::quoted(input, delim, escapeChar);
}
int zerodiv_ldexp()
{
int i = std::ldexp(0.0, 42.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_ilogb()
{
int i = std::ilogb(1.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_hypot()
{
int i = std::hypot(0.0, 0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fmod()
{
int i = std::fmod(0.0, 42.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fmin()
{
int i = std::fmin(0.0, 0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fmax()
{
int i = std::fmax(0.0, 0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_floor()
{
int i = std::floor(0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fabs()
{
int i = std::fabs(-0.0) + std::fabs(+0.0) + std::fabs(0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fdim()
{
int i = std::fdim(1.0, 1.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_trunc()
{
int i = std::trunc(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_ceil()
{
int i = std::ceil(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_sqrt()
{
int i = std::sqrt(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_cbrt()
{
int i = std::cbrt(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_erf()
{
int i = std::erf(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_erfc()
{
int i = std::erfc(42);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_asin()
{
int i = std::asin(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_acos()
{
int i = std::acos(1);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_asinh()
{
int i = std::asinh(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_acosh()
{
int i = std::acosh(1);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_log1p()
{
int i = std::log1p(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_nearbyint()
{
int i = std::nearbyint(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_round()
{
int i = std::round(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_sinh()
{
int i = std::sinh(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_tanh()
{
int i = std::tanh(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_atanh()
{
int i = std::atanh(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_atan()
{
int i = std::atan(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_sin()
{
int i = std::sin(0)+std::sin(M_PI)+std::sin(2*M_PI);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_expm1()
{
int i = std::expm1(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int moduloofone_cos()
{
int i = std::cos(0);
// cppcheck-suppress moduloofone
return 42 % i;
}
int moduloofone_exp()
{
int i = std::exp(0);
// cppcheck-suppress moduloofone
return 42 % i;
}
int moduloofone_exp2()
{
int i = std::exp2(0);
// cppcheck-suppress moduloofone
return 42 % i;
}
int moduloofone_pow()
{
int i = std::pow(2, 0);
// cppcheck-suppress moduloofone
return 42 % i;
}
char* invalidFunctionArgStr_strncpy(char * destination)
{
// Copies the first num characters of source to destination.
// If the end of the source C string (which is signaled by a null-character)
// is found before num characters have been copied, destination
// is padded with zeros until a total of num characters have been written to it.
const char source = 'x';
const std::size_t num = 1U;
return strncpy(destination, &source, num);
}
void invalidFunctionArgStr_fprintf(FILE *stream, const char *format)
{
const char formatBuf[] = {'%','d'};
// cppcheck-suppress invalidFunctionArgStr
(void)fprintf(stream,formatBuf,42);
(void)fprintf(stream,format,42);
}
void invalidFunctionArgStr_fopen(const char * const fileName, const char * const mode)
{
const char fileNameBuf[] = {'f','i','l','e'};
const char modeBuf[] = {'r'};
// cppcheck-suppress invalidFunctionArgStr
FILE *fp = fopen(fileName, modeBuf);
fclose(fp);
// cppcheck-suppress invalidFunctionArgStr
fp = fopen(fileNameBuf, mode);
fclose(fp);
}
float invalidFunctionArg_remquo (float x, float y, int* quo )
{
// cppcheck-suppress invalidFunctionArg
(void) std::remquo(x,0.0f,quo);
// cppcheck-suppress invalidFunctionArg
(void) std::remquof(x,0.0f,quo);
return std::remquo(x,y,quo);
}
double invalidFunctionArg_remquo (double x, double y, int* quo )
{
// cppcheck-suppress invalidFunctionArg
(void) std::remquo(x,0.0,quo);
// cppcheck-suppress invalidFunctionArg
(void) std::remquo(x,0.0f,quo);
// cppcheck-suppress invalidFunctionArg
(void) std::remquo(x,0.0L,quo);
return std::remquo(x,y,quo);
}
double invalidFunctionArg_remquo (long double x, long double y, int* quo )
{
// cppcheck-suppress invalidFunctionArg
(void) std::remquo(x,0.0L,quo);
// cppcheck-suppress invalidFunctionArg
(void) std::remquol(x,0.0L,quo);
return std::remquo(x,y,quo);
}
void invalidFunctionArg_remainderl(long double f1, long double f2)
{
// cppcheck-suppress invalidFunctionArg
(void)std::remainderl(f1,0.0);
// cppcheck-suppress invalidFunctionArg
(void)std::remainderl(f1,0.0L);
(void)std::remainderl(f1,f2);
}
void invalidFunctionArg_remainder(double f1, double f2)
{
// cppcheck-suppress invalidFunctionArg
(void)std::remainder(f1,0.0);
(void)std::remainder(f1,f2);
}
void invalidFunctionArg_remainderf(float f1, float f2)
{
// cppcheck-suppress invalidFunctionArg
(void)std::remainderf(f1,0.0);
// cppcheck-suppress invalidFunctionArg
(void)std::remainderf(f1,0.0f);
(void)std::remainderf(f1,f2);
}
void uninitvar_std_fstream_open(std::fstream &fs, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
std::string s;
const char *ptr;
std::ios_base::openmode m;
fs.open(s, mode);
// cppcheck-suppress uninitvar
fs.open(ptr, mode);
// TODO cppcheck-suppress uninitvar
fs.open(filename, m);
// TODO cppcheck-suppress uninitvar
fs.open(strFileName, m);
fs.open(s);
// TODO cppcheck-suppress uninitvar
fs.open(ptr);
}
void uninitvar_std_ifstream_open(std::ifstream &ifs, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
std::string s;
const char *ptr;
std::ios_base::openmode m;
ifs.open(s, mode);
// cppcheck-suppress uninitvar
ifs.open(ptr, mode);
// TODO cppcheck-suppress uninitvar
ifs.open(filename, m);
// TODO cppcheck-suppress uninitvar
ifs.open(strFileName, m);
ifs.open(s);
// TODO cppcheck-suppress uninitvar
ifs.open(ptr);
}
void uninitvar_std_ofstream_open(std::ofstream &os, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
std::string s;
const char *ptr;
std::ios_base::openmode m;
os.open(s, mode);
// cppcheck-suppress uninitvar
os.open(ptr, mode);
// TODO cppcheck-suppress uninitvar
os.open(filename, m);
// TODO cppcheck-suppress uninitvar
os.open(strFileName, m);
os.open(s);
// TODO cppcheck-suppress uninitvar
os.open(ptr);
}
void uninitvar_std_ofstream_precision(std::ofstream& os)
{
std::streamsize s;
// cppcheck-suppress uninitvar
os.precision(s);
}
void nullPointer_std_filebuf_open(std::filebuf &fb, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
// cppcheck-suppress nullPointer
(void)fb.open(nullptr, mode);
(void)fb.open(filename, mode);
(void)fb.open(strFileName, mode);
}
void nullPointer_std_ofstream_open(std::ofstream &os, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
// cppcheck-suppress nullPointer
os.open(nullptr, mode);
os.open(filename, mode);
os.open(strFileName, mode);
// cppcheck-suppress nullPointer
os.open(nullptr);
os.open(filename);
os.open(strFileName);
}
void nullPointer_std_fstream_open(std::fstream &fs, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
// cppcheck-suppress nullPointer
fs.open(nullptr, mode);
fs.open(filename, mode);
fs.open(strFileName, mode);
// cppcheck-suppress nullPointer
fs.open(nullptr);
fs.open(filename);
fs.open(strFileName);
}
void nullPointer_std_ifstream_open(std::ifstream &is, const std::string &strFileName, const char* filename, std::ios_base::openmode mode)
{
// cppcheck-suppress nullPointer
is.open(nullptr, mode);
is.open(filename, mode);
is.open(strFileName, mode);
// cppcheck-suppress nullPointer
is.open(nullptr);
is.open(filename);
is.open(strFileName);
}
void bufferAccessOutOfBounds_std_fstream_write(std::fstream &fs, const char* s, std::streamsize n)
{
const char buf[42] = {0};
(void)fs.write(buf,42);
// cppcheck-suppress bufferAccessOutOfBounds
(void)fs.write(buf,43);
(void)fs.write(buf,n);
(void)fs.write(s,n);
}
void bufferAccessOutOfBounds_std_ostream_write(std::ostream &os, const char* s, std::streamsize n)
{
const char buf[42] = {0};
(void)os.write(buf,42);
// cppcheck-suppress bufferAccessOutOfBounds
(void)os.write(buf,43);
(void)os.write(buf,n);
(void)os.write(s,n);
}
void bufferAccessOutOfBounds_std_ostringstream_write(std::ostringstream &oss, const char* s, std::streamsize n)
{
const char buf[42] = {0};
(void)oss.write(buf,42);
// cppcheck-suppress bufferAccessOutOfBounds
(void)oss.write(buf,43);
(void)oss.write(buf,n);
(void)oss.write(s,n);
}
void bufferAccessOutOfBounds_std_ofstream_write(std::ofstream &os, const char* s, std::streamsize n)
{
const char buf[42] = {0};
(void)os.write(buf,42);
// cppcheck-suppress bufferAccessOutOfBounds
(void)os.write(buf,43);
(void)os.write(buf,n);
(void)os.write(s,n);
}
// cppcheck-suppress constParameterReference // TODO: FP
void bufferAccessOutOfBounds_std_ifstream_get(std::ifstream& in, std::streambuf& sb)
{
char cBuf[10];
// cppcheck-suppress bufferAccessOutOfBounds
in.getline(cBuf, 100);
// cppcheck-suppress bufferAccessOutOfBounds
in.read(cBuf, 100);
// cppcheck-suppress bufferAccessOutOfBounds
in.readsome(cBuf, 100);
// cppcheck-suppress bufferAccessOutOfBounds
in.get(cBuf, 100);
// cppcheck-suppress bufferAccessOutOfBounds
in.get(cBuf, 100, 'a');
// cppcheck-suppress bufferAccessOutOfBounds
in.getline(cBuf, 100, 'a');
in.get(sb, 'a');
in.close();
}
void invalidFunctionArg_fesetexceptflag(const fexcept_t* flagp, int excepts)
{
(void)std::fesetexceptflag(flagp, excepts);
// cppcheck-suppress invalidFunctionArg
(void)std::fesetexceptflag(flagp, 0);
(void)std::fesetexceptflag(flagp, FE_DIVBYZERO);
(void)std::fesetexceptflag(flagp, FE_INEXACT);
(void)std::fesetexceptflag(flagp, FE_INVALID);
(void)std::fesetexceptflag(flagp, FE_OVERFLOW);
(void)std::fesetexceptflag(flagp, FE_UNDERFLOW);
(void)std::fesetexceptflag(flagp, FE_ALL_EXCEPT);
// cppcheck-suppress invalidFunctionArg
(void)std::fesetexceptflag(flagp, FE_ALL_EXCEPT+1);
}
void invalidFunctionArg_fetestexcept(int excepts)
{
(void)std::fetestexcept(excepts);
// cppcheck-suppress invalidFunctionArg
(void)std::fetestexcept(0);
(void)std::fetestexcept(FE_DIVBYZERO);
(void)std::fetestexcept(FE_INEXACT);
(void)std::fetestexcept(FE_INVALID);
(void)std::fetestexcept(FE_OVERFLOW);
(void)std::fetestexcept(FE_UNDERFLOW);
(void)std::fetestexcept(FE_ALL_EXCEPT);
// cppcheck-suppress invalidFunctionArg
(void)std::fetestexcept(FE_ALL_EXCEPT+1);
}
void nullPointer_fprintf(FILE *Stream, const char *Format, int Argument)
{
// cppcheck-suppress nullPointer
(void)std::fprintf(Stream, nullptr, Argument);
// no warning is expected
(void)std::fprintf(Stream, Format, Argument);
}
void bufferAccessOutOfBounds_wcsftime(wchar_t* ptr, size_t maxsize, const wchar_t* format, const struct tm* timeptr)
{
wchar_t buf[42];
(void)std::wcsftime(buf, 42, format, timeptr);
// TODO cppcheck-suppress bufferAccessOutOfBounds
(void)std::wcsftime(buf, 43, format, timeptr);
(void)std::wcsftime(ptr, maxsize, format, timeptr);
}
int qsort_cmpfunc (const void * a, const void * b) {
return (*static_cast<const int*>(a) - *static_cast<const int*>(b));
}
void nullPointer_qsort(void *base, std::size_t n, std::size_t size, int (*cmp)(const void *, const void *))
{
// cppcheck-suppress nullPointer
std::qsort(nullptr, n, size, qsort_cmpfunc);
// cppcheck-suppress nullPointer
std::qsort(base, n, size, nullptr);
std::qsort(base, n, size, qsort_cmpfunc);
}
void nullPointer_vfprintf(FILE *Stream, const char *Format, va_list Arg)
{
// cppcheck-suppress nullPointer
(void)std::vfprintf(Stream, nullptr, Arg);
(void)std::vfprintf(Stream, Format, Arg);
}
void nullPointer_vfwprintf(FILE *Stream, const wchar_t *Format, va_list Arg)
{
// cppcheck-suppress nullPointer
(void)std::vfwprintf(Stream, nullptr, Arg);
(void)std::vfwprintf(Stream, Format, Arg);
}
void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n)
{
char buf[42]={0};
(void)std::memchr(buf,c,42);
// cppcheck-suppress bufferAccessOutOfBounds
(void)std::memchr(buf,c,43);
return std::memchr(s,c,n);
}
// As with all bounds-checked functions, localtime_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including time.h.
#ifdef __STDC_LIB_EXT1__
void uninitvar_localtime_s(const std::time_t *restrict time, struct tm *restrict result)
{
// cppcheck-suppress valueFlowBailoutIncompleteVar
const std::time_t *restrict Time;
// TODO cppcheck-suppress uninitvar
(void)std::localtime_s(Time, result);
(void)std::localtime_s(time, result);
}
void nullPointer_localtime_s(const std::time_t *restrict time, struct tm *restrict result)
{
// cppcheck-suppress nullPointer
(void)std::localtime_s(NULL, result);
// cppcheck-suppress nullPointer
(void)std::localtime_s(time, NULL);
(void)std::localtime_s(time, result);
}
void memleak_localtime_s(const std::time_t *restrict time, struct tm *restrict result) // #9258
{
const time_t t = time(0);
const struct tm* const now = new tm();
if (localtime_s(now, &t) == 0) {
// cppcheck-suppress valueFlowBailoutIncompleteVar
std::cout << now->tm_mday << std::endl;
}
// cppcheck-suppress memleak
}
#endif // __STDC_LIB_EXT1__
size_t nullPointer_strftime(char *s, size_t max, const char *fmt, const struct tm *p)
{
// cppcheck-suppress nullPointer
(void) std::strftime(NULL,max,fmt,p);
// cppcheck-suppress nullPointer
(void) std::strftime(s,max,NULL,p);
// cppcheck-suppress nullPointer
(void) std::strftime(s,max,fmt,NULL);
return std::strftime(s,max,fmt,p);
}
size_t bufferAccessOutOfBounds_wcsrtombs(char * dest, const wchar_t ** src, size_t len, mbstate_t * ps)
{
char buf[42];
(void)std::wcsrtombs(buf,src,42,ps);
// cppcheck-suppress bufferAccessOutOfBounds
(void)std::wcsrtombs(buf,src,43,ps);
return std::wcsrtombs(dest,src,len,ps);
}
void invalidFunctionArg_std_string_substr(const std::string &str, std::size_t pos, std::size_t len) {
// cppcheck-suppress invalidFunctionArg
(void)str.substr(-1,len);
// cppcheck-suppress invalidFunctionArg
(void)str.substr(pos,-1);
// no warning is expected for
(void)str.substr(pos,len);
// cppcheck-suppress valueFlowBailoutIncompleteVar
(void)str.substr(pos, std::string::npos);
}
void invalidFunctionArg_std_wstring_substr(const std::wstring &str, std::size_t pos, std::size_t len) {
// cppcheck-suppress invalidFunctionArg
(void)str.substr(-1,len);
// cppcheck-suppress invalidFunctionArg
(void)str.substr(pos,-1);
// no warning is expected for
(void)str.substr(pos,len);
// cppcheck-suppress valueFlowBailoutIncompleteVar
(void)str.substr(pos, std::wstring::npos);
}
double invalidFunctionArg_log10(double d = 0.0) {
// cppcheck-suppress invalidFunctionArg
return log10(d);
}
void uninitvar_std_next(const std::vector<int> &v, int count)
{
// No warning shall be shown:
if (std::next(v.begin()) != v.end()) {}
if (std::next(v.begin(), count) != v.end()) {}
std::vector<int>::iterator it;
// cppcheck-suppress uninitvar
if (std::next(it) != v.end()) {}
std::vector<int>::const_iterator const_it;
// cppcheck-suppress uninitvar
if (std::next(const_it) != v.end()) {}
std::vector<int>::reverse_iterator rit;
// cppcheck-suppress uninitvar
if (std::next(rit) != v.rend()) {}
std::vector<int>::const_reverse_iterator const_rit;
// cppcheck-suppress uninitvar
if (std::next(const_rit) != v.rend()) {}
}
void uninitvar_std_prev(const std::vector<int> &v, int count)
{
// No warning shall be shown:
if (std::prev(v.begin()) != v.end()) {}
if (std::prev(v.begin(), count) != v.end()) {}
std::vector<int>::iterator it;
// cppcheck-suppress uninitvar
if (std::prev(it) != v.end()) {}
std::vector<int>::const_iterator const_it;
// cppcheck-suppress uninitvar
if (std::prev(const_it) != v.end()) {}
std::vector<int>::reverse_iterator rit;
// cppcheck-suppress uninitvar
if (std::prev(rit) != v.rend()) {}
std::vector<int>::const_reverse_iterator const_rit;
// cppcheck-suppress uninitvar
if (std::prev(const_rit) != v.rend()) {}
}
void overlappingWriteFunction_wcscat(wchar_t *src, wchar_t *dest)
{
// No warning shall be shown:
(void)wcscat(dest, src);
// cppcheck-suppress overlappingWriteFunction
(void)wcscat(src, src);
}
void overlappingWriteFunction_wcsxfrm(wchar_t *s1, const wchar_t *s2, size_t n)
{
// No warning shall be shown:
(void)wcsxfrm(s1, s2, n);
}
char * overlappingWriteFunction_strcat(char *src, char *dest)
{
// No warning shall be shown:
(void)strcat(dest, src);
// cppcheck-suppress overlappingWriteFunction
return strcat(src, src);
}
int nullPointer_wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n)
{
// cppcheck-suppress nullPointer
(void) std::wcsncmp(NULL,s2,n);
// cppcheck-suppress nullPointer
(void) std::wcsncmp(s1,NULL,n);
return std::wcsncmp(s1,s2,n);
}
wchar_t* nullPointer_wcsncpy(wchar_t *s, const wchar_t *cs, size_t n)
{
// cppcheck-suppress nullPointer
(void) std::wcsncpy(NULL,cs,n);
// cppcheck-suppress nullPointer
(void) std::wcsncpy(s,NULL,n);
return std::wcsncpy(s,cs,n);
}
char * overlappingWriteFunction_strncat(const char *src, char *dest, const std::size_t count)
{
// No warning shall be shown:
(void)strncat(dest, src, 42);
(void)strncat(dest, src, count);
(void)strncat(dest, dest, count);
// cppcheck-suppress overlappingWriteFunction
(void)strncat(dest, dest+1, 2);
char buffer[] = "strncat";
// cppcheck-suppress overlappingWriteFunction
return strncat(buffer, buffer + 1, 3);
}
wchar_t * overlappingWriteFunction_wcsncat(const wchar_t *src, wchar_t *dest, const std::size_t count)
{
// No warning shall be shown:
(void)wcsncat(dest, src, 42);
(void)wcsncat(dest, src, count);
(void)wcsncat(dest, dest, count);
// cppcheck-suppress overlappingWriteFunction
(void)wcsncat(dest, dest+1, 2);
wchar_t buffer[] = L"strncat";
// cppcheck-suppress overlappingWriteFunction
return wcsncat(buffer, buffer + 1, 3);
}
wchar_t * overlappingWriteFunction_wcscpy(wchar_t *src, wchar_t *dest)
{
// No warning shall be shown:
(void)wcscpy(dest, src);
const wchar_t * destBuf = dest;
// TODO-cppcheck-suppress overlappingWriteFunction #10355
(void)wcscpy(dest, destBuf);
// cppcheck-suppress overlappingWriteFunction
return wcscpy(src, src);
}
wchar_t * overlappingWriteFunction_wcsncpy(wchar_t *buf, const std::size_t count)
{
// No warning shall be shown:
(void)wcsncpy(&buf[0], &buf[3], count); // size is not known
(void)wcsncpy(&buf[0], &buf[3], 3U); // no-overlap
// cppcheck-suppress overlappingWriteFunction
return wcsncpy(&buf[0], &buf[3], 4U);
}
char * overlappingWriteFunction_strncpy(char *buf, const std::size_t count)
{
// No warning shall be shown:
(void)strncpy(&buf[0], &buf[3], count); // size is not known
(void)strncpy(&buf[0], &buf[3], 3U); // no-overlap
// cppcheck-suppress overlappingWriteFunction
return strncpy(&buf[0], &buf[3], 4U);
}
void * overlappingWriteFunction_memmove(void)
{
// No warning shall be shown:
char str[] = "memmove handles overlapping data well";
return memmove(str,str+3,4);
}
std::bitset<10> std_bitset_test_ignoredReturnValue()
{
std::bitset<10> b1("1111010000");
// cppcheck-suppress ignoredReturnValue
b1.test(2);
return b1;
}
std::bitset<10> std_bitset_all_ignoredReturnValue()
{
std::bitset<10> b1("1111010000");
// cppcheck-suppress ignoredReturnValue
b1.all();
return b1;
}
std::bitset<10> std_bitset_none_ignoredReturnValue()
{
std::bitset<10> b1("1111010000");
// cppcheck-suppress ignoredReturnValue
b1.none();
return b1;
}
std::bitset<10> std_bitset_any_ignoredReturnValue()
{
std::bitset<10> b1("1111010000");
// cppcheck-suppress ignoredReturnValue
b1.any();
return b1;
}
std::bitset<10> std_bitset_size_ignoredReturnValue()
{
std::bitset<10> b1("1111010000");
// cppcheck-suppress ignoredReturnValue
b1.size();
return b1;
}
std::bitset<10> std_bitset_count_ignoredReturnValue()
{
std::bitset<10> b1("1111010000");
// cppcheck-suppress ignoredReturnValue
b1.count();
return b1;
}
void std_unordered_set_count_ignoredReturnValue(const std::unordered_set<int>& u)
{
int i;
// cppcheck-suppress [uninitvar, ignoredReturnValue]
u.count(i);
}
void std_unordered_map_count_ignoredReturnValue(const std::unordered_map<int, int>& u)
{
int i;
// cppcheck-suppress [uninitvar, ignoredReturnValue]
u.count(i);
}
void std_multimap_count_ignoredReturnValue(const std::multimap<int, int>& m)
{
int i;
// cppcheck-suppress [uninitvar, ignoredReturnValue]
m.count(i);
}
void std_unordered_map_insert_unnitvar(std::unordered_set<int>& u)
{
int i;
// cppcheck-suppress uninitvar
u.insert(i);
}
void std_unordered_map_emplace_unnitvar(std::unordered_set<int>& u)
{
int i;
// cppcheck-suppress uninitvar
u.emplace(i);
}
int std_map_find_constref(std::map<int, int>& m) // #11857
{
std::map<int, int>& r = m;
std::map<int, int>::iterator it = r.find(42);
int* p = &it->second;
return ++*p;
}
void std_queue_front_ignoredReturnValue(const std::queue<int>& q) {
// cppcheck-suppress ignoredReturnValue
q.front();
}
void std_priority_queue_top_ignoredReturnValue(const std::priority_queue<int>& pq) {
// cppcheck-suppress ignoredReturnValue
pq.top();
}
void std_tie_ignoredReturnValue(int a, int b)
{
std::set<int> s;
std::set<int>::iterator it;
bool success;
std::tie(it, success) = s.insert(1);
// cppcheck-suppress ignoredReturnValue
std::tie();
// cppcheck-suppress ignoredReturnValue
std::tie(a, b);
}
void std_exception_ignoredReturnValue(const std::exception& e)