You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n"
371
-
"int result is assigned to long variable. If the variable is long to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'l = a * b;' => 'l = (long)a * b;'.", CWE197, Certainty::normal);
395
+
srcStr + " result is assigned to " + tgtStr + "variable. If the variable is " + tgtStr + "to avoid loss of information, then you have loss of information.\n" +
396
+
srcStr + " result is assigned to " + tgtStr + "variable. If the variable is " + tgtStr + "to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to " + tgtStr + ", for example 'l = a * b;' => 'l = (" + tgtStr + ")a * b;'.", CWE197, Certainty::normal);
"int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n"
380
-
"int result is returned as long value. If the return value is long to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'return a*b;' => 'return (long)a*b'.", CWE197, Certainty::normal);
408
+
srcStr +" result is returned as " + tgtStr + "value. If the return value is " + tgtStr + "to avoid loss of information, then you have loss of information.\n" +
409
+
srcStr +" result is returned as " + tgtStr + "value. If the return value is " + tgtStr + " to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'return a*b;' => 'return (long)a*b'.", CWE197, Certainty::normal);
ASSERT_EQUALS("[test.cpp:2]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n", errout.str());
336
+
check(code, settingsWin);
337
+
ASSERT_EQUALS("", errout.str());
328
338
329
339
check("long f(int x, int y) {\n"
330
-
"const long ret = x * y;\n"
340
+
" long ret = x * y;\n"
331
341
" return ret;\n"
332
342
"}\n", settings);
333
343
ASSERT_EQUALS("[test.cpp:2]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n", errout.str());
@@ -351,21 +361,39 @@ class TestType : public TestFixture {
351
361
" return ret;\n"
352
362
"}\n", settings);
353
363
ASSERT_EQUALS("", errout.str());
364
+
365
+
check("double g(float f) {\n"
366
+
" return f * f;\n"
367
+
"}\n", settings);
368
+
ASSERT_EQUALS("[test.cpp:2]: (style) float result is returned as double value. If the return value is double to avoid loss of information, then you have loss of information.\n",
ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout.str());
381
+
check(code, settingsWin);
382
+
ASSERT_EQUALS("", errout.str());
383
+
384
+
constchar code2[] = "long long f(int x, int y) {\n"
385
+
" return x * y;\n"
386
+
"}\n";
387
+
check(code2, settings);
388
+
ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information.\n", errout.str());
389
+
check(code2, settingsWin);
390
+
ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long long value. If the return value is long long to avoid loss of information, then you have loss of information.\n", errout.str());
363
391
364
392
// typedef
365
393
check("size_t f(int x, int y) {\n"
366
394
" return x * y;\n"
367
395
"}\n", settings);
368
-
ASSERT_EQUALS("", errout.str());
396
+
ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout.str());
369
397
}
370
398
371
399
// This function ensure that test works with different compilers. Floats can
0 commit comments