Skip to content

Commit 8f641aa

Browse files
committed
Added gets_s() to std.cfg (C11), added <use-retval/> to min/max().
1 parent 6c43cb2 commit 8f641aa

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

cfg/std.cfg

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,22 @@
14421442
<arg nr="1">
14431443
<not-null/>
14441444
</arg>
1445-
<warn severity="warning">Obsolete function 'gets' called. It is recommended to use 'fgets' instead.
1446-
The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun if the input data exceeds the size of the buffer. It is recommended to use the function 'fgets' instead.</warn>
1445+
<warn severity="warning">Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.
1446+
The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun if the input data exceeds the size of the buffer. It is recommended to use the functions 'fgets' or 'gets_s' instead.</warn>
1447+
</function>
1448+
<!-- char *gets_s(char *buffer, rsize_t size); -->
1449+
<function name="gets_s,std::gets_s">
1450+
<noreturn>false</noreturn>
1451+
<leak-ignore/>
1452+
<arg nr="1">
1453+
<not-null/>
1454+
<minsize type="argvalue" arg="2"/>
1455+
</arg>
1456+
<arg nr="2">
1457+
<not-uninit/>
1458+
<not-bool/>
1459+
<valid>0:</valid>
1460+
</arg>
14471461
</function>
14481462
<!-- struct tm * gmtime(const time_t *tp); -->
14491463
<function name="gmtime,std::gmtime">
@@ -3842,6 +3856,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
38423856
</function>
38433857
<!-- template <class T> const T& min(const T& a, const T& b); -->
38443858
<function name="min,std::min">
3859+
<use-retval/>
38453860
<noreturn>false</noreturn>
38463861
<leak-ignore/>
38473862
<arg nr="1">
@@ -3853,6 +3868,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
38533868
</function>
38543869
<!-- template <class T> const T& max(const T& a, const T& b); -->
38553870
<function name="max,std::max">
3871+
<use-retval/>
38563872
<noreturn>false</noreturn>
38573873
<leak-ignore/>
38583874
<arg nr="1">

test/testfunctions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ class TestFunctions : public TestFixture {
216216
"{\n"
217217
" char *x = gets(a);\n"
218218
"}");
219-
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' instead.\n", errout.str());
219+
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str());
220220

221221
check("void f()\n"
222222
"{\n"
223223
" foo(x, gets(a));\n"
224224
"}");
225-
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' instead.\n", errout.str());
225+
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str());
226226
}
227227

228228
void prohibitedFunctions_alloca() {
@@ -276,8 +276,8 @@ class TestFunctions : public TestFixture {
276276
" char *x = std::gets(str);\n"
277277
" char *y = gets(str);\n"
278278
"}");
279-
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' instead.\n"
280-
"[test.cpp:4]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' instead.\n", errout.str());
279+
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n"
280+
"[test.cpp:4]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str());
281281
}
282282

283283
// multiple use
@@ -287,7 +287,7 @@ class TestFunctions : public TestFixture {
287287
" char *x = std::gets(str);\n"
288288
" usleep( 1000 );\n"
289289
"}");
290-
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' instead.\n"
290+
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n"
291291
"[test.cpp:4]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead.\n", errout.str());
292292
}
293293

@@ -298,7 +298,7 @@ class TestFunctions : public TestFixture {
298298
" char s [ 10 ] ;\n"
299299
" gets ( s ) ;\n"
300300
"}");
301-
ASSERT_EQUALS("[test.cpp:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' instead.\n", errout.str());
301+
ASSERT_EQUALS("[test.cpp:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str());
302302

303303
check("int getcontext(ucontext_t *ucp);\n"
304304
"int f (ucontext_t *ucp)\n"

0 commit comments

Comments
 (0)