added more code
This commit is contained in:
16
CPE455/lab06/.vscode/c_cpp_properties.json
vendored
Normal file
16
CPE455/lab06/.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": []
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
28
CPE455/lab06/.vscode/launch.json
vendored
Normal file
28
CPE455/lab06/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
""
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/student/anw0044/CPE455/lab06",
|
||||
"environment": [],
|
||||
"program": "/home/student/anw0044/CPE455/lab06/build/Debug/outDebug",
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/usr/bin/gdb",
|
||||
"externalConsole": false,
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
30
CPE455/lab06/.vscode/settings.json
vendored
Normal file
30
CPE455/lab06/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "/usr/bin/gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "/usr/bin/g++",
|
||||
"C_Cpp_Runner.debuggerPath": "/usr/bin/gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
]
|
||||
}
|
BIN
CPE455/lab06/CPEX55-Lab06-StaticAnalysis.pdf
Normal file
BIN
CPE455/lab06/CPEX55-Lab06-StaticAnalysis.pdf
Normal file
Binary file not shown.
BIN
CPE455/lab06/JSF-AV-rules.pdf
Normal file
BIN
CPE455/lab06/JSF-AV-rules.pdf
Normal file
Binary file not shown.
BIN
CPE455/lab06/a.out
Executable file
BIN
CPE455/lab06/a.out
Executable file
Binary file not shown.
10
CPE455/lab06/clang++.txt
Normal file
10
CPE455/lab06/clang++.txt
Normal file
@ -0,0 +1,10 @@
|
||||
ec3.cpp:11:5: warning: array index 10 is past the end of the array (which contains 10 elements) [-Warray-bounds]
|
||||
a[10] = 0;
|
||||
^ ~~
|
||||
ec3.cpp:8:5: note: array 'a' declared here
|
||||
char a[10];
|
||||
^
|
||||
ec3.cpp:66:1: warning: control may reach end of non-void function [-Wreturn-type]
|
||||
}
|
||||
^
|
||||
2 warnings generated.
|
13
CPE455/lab06/clang++all.txt
Normal file
13
CPE455/lab06/clang++all.txt
Normal file
@ -0,0 +1,13 @@
|
||||
ec3.cpp:43:10: warning: unused variable 'q' [-Wunused-variable]
|
||||
int* q = new int;
|
||||
^
|
||||
ec3.cpp:11:5: warning: array index 10 is past the end of the array (which contains 10 elements) [-Warray-bounds]
|
||||
a[10] = 0;
|
||||
^ ~~
|
||||
ec3.cpp:8:5: note: array 'a' declared here
|
||||
char a[10];
|
||||
^
|
||||
ec3.cpp:66:1: warning: control may reach end of non-void function [-Wreturn-type]
|
||||
}
|
||||
^
|
||||
3 warnings generated.
|
48
CPE455/lab06/cppcheck-all.txt
Normal file
48
CPE455/lab06/cppcheck-all.txt
Normal file
@ -0,0 +1,48 @@
|
||||
[1mec3.cpp:55:5: [31mstyle:[39m Assignment of function parameter has no effect outside the function. [uselessAssignmentArg][0m
|
||||
a = a + 1; // No side effect outside function
|
||||
^
|
||||
[1mec3.cpp:11:6: [31merror:[39m Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds][0m
|
||||
a[10] = 0;
|
||||
^
|
||||
[1mec3.cpp:16:10: [31merror:[39m Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds][0m
|
||||
a[k] = k;
|
||||
^
|
||||
[1mec3.cpp:62:0: [31merror:[39m Found a exit path from function with non-void return type that has missing return statement [missingReturn][0m
|
||||
return false;
|
||||
^
|
||||
[1mec3.cpp:33:6: [31merror:[39m Null pointer dereference: x [nullPointer][0m
|
||||
*x = 1;
|
||||
^
|
||||
[1mec3.cpp:32:14: [2mnote:[0m Assignment 'x=0', assigned value is 0
|
||||
int* x = 0;
|
||||
^
|
||||
[1mec3.cpp:33:6: [2mnote:[0m Null pointer dereference
|
||||
*x = 1;
|
||||
^
|
||||
[1mec3.cpp:29:6: [31merror:[39m Uninitialized variable: p [uninitvar][0m
|
||||
*p = 5;
|
||||
^
|
||||
[1mec3.cpp:47:12: [31merror:[39m Memory is allocated but not initialized: r [uninitdata][0m
|
||||
delete r;
|
||||
^
|
||||
[1mec3.cpp:23:14: [31mstyle:[39m Variable 'a[m]' is assigned a value that is never used. [unreadVariable][0m
|
||||
a[m] = m;
|
||||
^
|
||||
[1mec3.cpp:43:12: [31mstyle:[39m Variable 'q' is assigned a value that is never used. [unreadVariable][0m
|
||||
int* q = new int;
|
||||
^
|
||||
[1mec3.cpp:28:10: [31mstyle:[39m Variable 'p' is not assigned a value. [unassignedVariable][0m
|
||||
int* p;
|
||||
^
|
||||
[1mec3.cpp:43:10: [31mstyle:[39m Variable 'q' is allocated memory that is never used. [unusedAllocatedMemory][0m
|
||||
int* q = new int;
|
||||
^
|
||||
[1mec3.cpp:46:10: [31mstyle:[39m Variable 'r' is allocated memory that is never used. [unusedAllocatedMemory][0m
|
||||
int* r = new int[4];
|
||||
^
|
||||
[1mec3.cpp:55:7: [31mstyle:[39m Variable 'a' is assigned a value that is never used. [unreadVariable][0m
|
||||
a = a + 1; // No side effect outside function
|
||||
^
|
||||
[1mec3.cpp:53:0: [31mstyle:[39m The function 'f' is never used. [unusedFunction][0m
|
||||
|
||||
^
|
24
CPE455/lab06/cppcheck.txt
Normal file
24
CPE455/lab06/cppcheck.txt
Normal file
@ -0,0 +1,24 @@
|
||||
[1mec3.cpp:11:6: [31merror:[39m Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds][0m
|
||||
a[10] = 0;
|
||||
^
|
||||
[1mec3.cpp:16:10: [31merror:[39m Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds][0m
|
||||
a[k] = k;
|
||||
^
|
||||
[1mec3.cpp:62:0: [31merror:[39m Found a exit path from function with non-void return type that has missing return statement [missingReturn][0m
|
||||
return false;
|
||||
^
|
||||
[1mec3.cpp:33:6: [31merror:[39m Null pointer dereference: x [nullPointer][0m
|
||||
*x = 1;
|
||||
^
|
||||
[1mec3.cpp:32:14: [2mnote:[0m Assignment 'x=0', assigned value is 0
|
||||
int* x = 0;
|
||||
^
|
||||
[1mec3.cpp:33:6: [2mnote:[0m Null pointer dereference
|
||||
*x = 1;
|
||||
^
|
||||
[1mec3.cpp:29:6: [31merror:[39m Uninitialized variable: p [uninitvar][0m
|
||||
*p = 5;
|
||||
^
|
||||
[1mec3.cpp:47:12: [31merror:[39m Memory is allocated but not initialized: r [uninitdata][0m
|
||||
delete r;
|
||||
^
|
68
CPE455/lab06/ec3.cpp
Normal file
68
CPE455/lab06/ec3.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
|
||||
void f(int a);
|
||||
bool g(int& b);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char a[10];
|
||||
|
||||
// Array bounds error
|
||||
a[10] = 0;
|
||||
|
||||
// Array bounds error via loop
|
||||
for(int k = 0; k <= 10; k++)
|
||||
{
|
||||
a[k] = k;
|
||||
}
|
||||
|
||||
// Array bounds error via loop
|
||||
int m = 0;
|
||||
while (true)
|
||||
{
|
||||
a[m] = m;
|
||||
m++;
|
||||
}
|
||||
|
||||
// Pointer variable p uninitialized
|
||||
int* p;
|
||||
*p = 5;
|
||||
|
||||
// Null pointer dereference
|
||||
int* x = 0;
|
||||
*x = 1;
|
||||
|
||||
// Trigger path in function g that does not return Boolean
|
||||
int c = -1;
|
||||
if ( g(c) )
|
||||
c = 2;
|
||||
else
|
||||
c = 3;
|
||||
|
||||
// Memory leak
|
||||
int* q = new int;
|
||||
|
||||
// Memory leak
|
||||
int* r = new int[4];
|
||||
delete r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Unused function f
|
||||
void f(int a)
|
||||
{
|
||||
a = a + 1; // No side effect outside function
|
||||
}
|
||||
|
||||
// Function g has one path that does not return a Boolean value
|
||||
bool g(int& b)
|
||||
{
|
||||
if (b > 0)
|
||||
return false;
|
||||
|
||||
b = 0;
|
||||
// Exit without returning a Boolean
|
||||
}
|
||||
|
||||
|
0
CPE455/lab06/g++.txt
Normal file
0
CPE455/lab06/g++.txt
Normal file
11
CPE455/lab06/g++all.txt
Normal file
11
CPE455/lab06/g++all.txt
Normal file
@ -0,0 +1,11 @@
|
||||
ec3.cpp: In function ‘int main(int, char**)’:
|
||||
ec3.cpp:8:10: warning: variable ‘a’ set but not used [-Wunused-but-set-variable]
|
||||
char a[10];
|
||||
^
|
||||
ec3.cpp:43:10: warning: unused variable ‘q’ [-Wunused-variable]
|
||||
int* q = new int;
|
||||
^
|
||||
ec3.cpp: In function ‘bool g(int&)’:
|
||||
ec3.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
|
||||
}
|
||||
^
|
BIN
CPE455/lab06/sei-cert-c-coding-standard-2016-v01.pdf
Normal file
BIN
CPE455/lab06/sei-cert-c-coding-standard-2016-v01.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user