Skip to content

Commit 9daf785

Browse files
committed
Improved testing of std.cfg regarding uninitialized variables.
1 parent b16a480 commit 9daf785

File tree

3 files changed

+181
-7
lines changed

3 files changed

+181
-7
lines changed

cfg/std.cfg

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,7 @@
24512451
<!-- double pow(double x, double y); -->
24522452
<!-- float powf(float x, float y);-->
24532453
<!-- long double powl(long double x, long double y); -->
2454-
<function name="pow,powf,powl">
2454+
<function name="pow,std::pow,powf,powl">
24552455
<use-retval/>
24562456
<pure/>
24572457
<noreturn>false</noreturn>
@@ -2481,7 +2481,7 @@
24812481
<!-- double remainder(double x, double y); -->
24822482
<!-- float remainderf(float x, float y); -->
24832483
<!-- long double remainderl(long double x, long double y); -->
2484-
<function name="remainder,remainderf,remainderl">
2484+
<function name="remainder,std::remainder,remainderf,std::remainderf,remainderl,std::remainderl">
24852485
<use-retval/>
24862486
<pure/>
24872487
<noreturn>false</noreturn>
@@ -2496,7 +2496,7 @@
24962496
<!-- double remquo(double, x, double y, int *quo); -->
24972497
<!-- float remquof(float x, float y, int *quo); -->
24982498
<!-- long double remquol(long double x, long double y, int *quo); -->
2499-
<function name="remquo,remquof,remquol">
2499+
<function name="remquo,std::remquo,remquof,std::remquof,remquol,std::remquol">
25002500
<use-retval/>
25012501
<pure/>
25022502
<noreturn>false</noreturn>
@@ -2512,36 +2512,39 @@
25122512
</arg>
25132513
</function>
25142514
<!-- int printf(const char *format, ...); -->
2515-
<function name="printf">
2515+
<function name="printf,std::printf">
25162516
<noreturn>false</noreturn>
25172517
<leak-ignore/>
25182518
<formatstr/>
25192519
<arg nr="1">
25202520
<formatstr/>
2521+
<not-uninit/>
25212522
</arg>
25222523
<arg nr="any">
25232524
<not-uninit/>
25242525
</arg>
25252526
</function>
25262527
<!-- int vprintf(const char *format, va_list arg); -->
2527-
<function name="vprintf">
2528+
<function name="vprintf,std::vprintf">
25282529
<noreturn>false</noreturn>
25292530
<leak-ignore/>
25302531
<formatstr/>
25312532
<arg nr="1">
25322533
<formatstr/>
2534+
<not-uninit/>
25332535
</arg>
25342536
<arg nr="any">
25352537
<not-uninit/>
25362538
</arg>
25372539
</function>
2538-
<!-- int vprintf(const wchar_t *format, va_list arg); -->
2539-
<function name="vwprintf">
2540+
<!-- int vwprintf(const wchar_t *format, va_list arg); -->
2541+
<function name="vwprintf,std::vwprintf">
25402542
<noreturn>false</noreturn>
25412543
<leak-ignore/>
25422544
<formatstr/>
25432545
<arg nr="1">
25442546
<formatstr/>
2547+
<not-uninit/>
25452548
</arg>
25462549
<arg nr="any">
25472550
<not-uninit/>

test/cfg/std.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,3 +2464,96 @@ void uninivar_perror(void)
24642464
// cppcheck-suppress uninitvar
24652465
(void)perror(string);
24662466
}
2467+
2468+
void uninitvar_pow(void)
2469+
{
2470+
float f1,f2;
2471+
// cppcheck-suppress uninitvar
2472+
(void)powf(f1,f2);
2473+
2474+
double d1,d2;
2475+
// cppcheck-suppress uninitvar
2476+
(void)pow(d1,d2);
2477+
2478+
long double ld1,ld2;
2479+
// cppcheck-suppress uninitvar
2480+
(void)powl(ld1,ld2);
2481+
}
2482+
2483+
void uninitvar_cpow(void)
2484+
{
2485+
float complex f1,f2;
2486+
// cppcheck-suppress uninitvar
2487+
(void)cpowf(f1,f2);
2488+
2489+
double complex d1,d2;
2490+
// cppcheck-suppress uninitvar
2491+
(void)cpow(d1,d2);
2492+
2493+
long double complex ld1,ld2;
2494+
// cppcheck-suppress uninitvar
2495+
(void)cpowl(ld1,ld2);
2496+
}
2497+
2498+
void uninitvar_remainder(void)
2499+
{
2500+
float f1,f2;
2501+
// cppcheck-suppress uninitvar
2502+
(void)remainderf(f1,f2);
2503+
2504+
double d1,d2;
2505+
// cppcheck-suppress uninitvar
2506+
(void)remainder(d1,d2);
2507+
2508+
long double ld1,ld2;
2509+
// cppcheck-suppress uninitvar
2510+
(void)remainderl(ld1,ld2);
2511+
}
2512+
2513+
void uninitvar_remquo(void)
2514+
{
2515+
float f1,f2;
2516+
int *i1;
2517+
// cppcheck-suppress uninitvar
2518+
(void)remquof(f1,f2,i1);
2519+
2520+
double d1,d2;
2521+
int *i2;
2522+
// cppcheck-suppress uninitvar
2523+
(void)remquo(d1,d2,i2);
2524+
2525+
long double ld1,ld2;
2526+
int *i3;
2527+
// cppcheck-suppress uninitvar
2528+
(void)remquol(ld1,ld2,i3);
2529+
}
2530+
2531+
void uninivar_printf(void)
2532+
{
2533+
char * format;
2534+
int i;
2535+
// no warning is expected
2536+
(void)printf("x");
2537+
// cppcheck-suppress uninitvar
2538+
(void)printf(format,i);
2539+
// cppcheck-suppress uninitvar
2540+
(void)printf(format,1);
2541+
}
2542+
2543+
void uninivar_vprintf(void)
2544+
{
2545+
char * format;
2546+
va_list arg;
2547+
// cppcheck-suppress va_list_usedBeforeStarted
2548+
// cppcheck-suppress uninitvar
2549+
(void)vprintf(format,arg);
2550+
}
2551+
2552+
void uninivar_vwprintf(void)
2553+
{
2554+
wchar_t * format;
2555+
va_list arg;
2556+
// cppcheck-suppress va_list_usedBeforeStarted
2557+
// cppcheck-suppress uninitvar
2558+
(void)vwprintf(format,arg);
2559+
}

test/cfg/std.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,3 +1801,81 @@ void uninivar_perror(void)
18011801
// cppcheck-suppress uninitvar
18021802
(void)std::perror(string);
18031803
}
1804+
1805+
void uninitvar_pow(void)
1806+
{
1807+
float f1,f2;
1808+
// cppcheck-suppress uninitvar
1809+
(void)std::pow(f1,f2);
1810+
1811+
double d1,d2;
1812+
// cppcheck-suppress uninitvar
1813+
(void)std::pow(d1,d2);
1814+
1815+
long double ld1,ld2;
1816+
// cppcheck-suppress uninitvar
1817+
(void)std::pow(ld1,ld2);
1818+
}
1819+
1820+
void uninitvar_remainder(void)
1821+
{
1822+
float f1,f2;
1823+
// cppcheck-suppress uninitvar
1824+
(void)std::remainderf(f1,f2);
1825+
1826+
double d1,d2;
1827+
// cppcheck-suppress uninitvar
1828+
(void)std::remainder(d1,d2);
1829+
1830+
long double ld1,ld2;
1831+
// cppcheck-suppress uninitvar
1832+
(void)std::remainderl(ld1,ld2);
1833+
}
1834+
1835+
void uninitvar_remquo(void)
1836+
{
1837+
float f1,f2;
1838+
int *i1;
1839+
// cppcheck-suppress uninitvar
1840+
(void)std::remquof(f1,f2,i1);
1841+
1842+
double d1,d2;
1843+
int *i2;
1844+
// cppcheck-suppress uninitvar
1845+
(void)std::remquo(d1,d2,i2);
1846+
1847+
long double ld1,ld2;
1848+
int *i3;
1849+
// cppcheck-suppress uninitvar
1850+
(void)std::remquol(ld1,ld2,i3);
1851+
}
1852+
1853+
void uninivar_printf(void)
1854+
{
1855+
char * format;
1856+
int i;
1857+
// no warning is expected
1858+
(void)std::printf("x");
1859+
// cppcheck-suppress uninitvar
1860+
(void)std::printf(format,i);
1861+
// cppcheck-suppress uninitvar
1862+
(void)std::printf(format,1);
1863+
}
1864+
1865+
void uninivar_vprintf(void)
1866+
{
1867+
char * format;
1868+
va_list arg;
1869+
// cppcheck-suppress va_list_usedBeforeStarted
1870+
// cppcheck-suppress uninitvar
1871+
(void)std::vprintf(format,arg);
1872+
}
1873+
1874+
void uninivar_vwprintf(void)
1875+
{
1876+
wchar_t * format;
1877+
va_list arg;
1878+
// cppcheck-suppress va_list_usedBeforeStarted
1879+
// cppcheck-suppress uninitvar
1880+
(void)std::vwprintf(format,arg);
1881+
}

0 commit comments

Comments
 (0)