Commit 7f4a7ea2 authored by Sergio Costas's avatar Sergio Costas

Now manages the global variables like aliases, but only allows to assign a...

Now manages the global variables like aliases, but only allows to assign a block to a single global variable to avoid dangling pointers
parent 0760adec
......@@ -16,19 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
import glob
import sys
import os
from crust import crust
lib = crust.crust("lexyacclib/crust.h", "lexyacclib/crust.so", True)
parameters = get_parameters()
filelist = []
for f in parameters["files"]:
filelist.append(f)
filelist.sort()
for f in filelist:
if parameters["files"][f]:
process_file(f, parameters)
crust.main()
This diff is collapsed.
......@@ -488,8 +488,8 @@ class Test(unittest.TestCase):
def test118CallingPointerWithPosibleNull(self):
self._generic_test("unitest/test118.c", [ (crust.crust.MSG_WARNING, "Using function pointer '{:s}' at line {:d} with a possible NULL value", "test1", 11) ])
def test119CallingPointerWithPosibleNull(self):
self._generic_test("unitest/test119.c", [ (crust.crust.MSG_WARNING, "Using function pointer '{:s}' at line {:d} with a possible NULL value", "test1", 9) ])
def test119BlockToGlobalVar(self):
self._all_fine_test("unitest/test119.c")
def test120DoWhileUsesTwice(self):
self._generic_test("unitest/test120.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 10) ])
......@@ -825,6 +825,14 @@ class Test(unittest.TestCase):
def test182CheckCompareWithNullWhenFreed(self):
self._all_fine_test("unitest/test182.c")
def test183CheckIfWithUninitializedVariable(self):
self._generic_test("unitest/test183.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}", "param3", 5, 9) ])
def test184CheckIfWithUninitializedVariable(self):
self._generic_test("unitest/test184.c", [ (crust.crust.MSG_ERROR, "Assigning the variable '{:s}' to the global variable '{:s}' at line {:d}, but it is already assigned to the global variable '{:s}'", "param1", "global_var2", 11, "global_var1") ])
def test185CheckIfWithUninitializedVariable(self):
self._generic_test("unitest/test185.c", [ (crust.crust.MSG_ERROR, "Assigning the global variable '{:s}' to the global variable '{:s}' at line {:d}, but it already has assigned the block '{:s}'", "global_var1", "global_var2", 11, "param1" ) ])
if __name__ == '__main__':
try:
......
......@@ -2,9 +2,9 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
char* (*function)(crust_t) ();
crust_t global_var1;
void main(crust_t param1) {
char* (*test1)(crust_t) = function();
(*test1)(param1); // WARNING: calling a function pointer with a possible NULL value
void function(crust_t param3) {
global_var1 = param3; // It is fine: since we are storing the block from "param3" in a global variable, it is not a dangling pointer
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void function(crust_t param3) {
__crust_alias__ crust_t var1;
var1 = param3; // ERROR: it is assigned to an alias, but it is a local one
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
crust_t global_var1;
crust_t global_var2;
void function(crust_t param1) {
global_var1 = param1; // It is fine: since we are storing the block from "param3" in a global variable, it is not a dangling pointer
global_var2 = param1; // ERROR: it is not allowed to assign the same block to several global variables
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
crust_t global_var1;
crust_t global_var2;
void function(crust_t param1) {
global_var1 = param1; // It is fine: since we are storing the block from "param3" in a global variable, it is not a dangling pointer
global_var2 = global_var1; // ERROR: it is not allowed to assign the same block to several global variables
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment