Skip to content

Commit

Permalink
fix bugs and modify CRCR options
Browse files Browse the repository at this point in the history
  • Loading branch information
FanWuUCL committed Nov 4, 2015
1 parent 682158e commit 9c4d426
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SOURCES=src/*.c

OBJECTS= App.o ASTNode.o ASTNodeUtil.o ASTPrinter.o ASTUnit.o Milu3.o MultiProcessing.o Mutant.o MutantExecutor.o MutantSet.o MutationId.o MutationOperator.o MutationTemplate.o Mutator.o Options.o Project.o TestInput.o Utility.o $(OPOBJ) $(MUTOBJ)

MUTOBJ=add_arithmetic_assignment_replacement.o add_arithmetic_replacement.o and_logical_negation.o and_logical_replacement.o austin_add_arithmetic_replacement.o austin_and_logical_negation.o austin_and_logical_replacement.o austin_divide_arithmetic_replacement.o austin_equal_relational_replacement.o austin_greater_equal_relational_replacement.o austin_greater_relationa_replacement.o austin_integer_constant_replacement.o austin_less_equal_relational_replacement.o austin_less_relational_replacement.o austin_modulus_arithmetic_replacement.o austin_multiply_arithmetic_replacement.o austin_not_equal_relational_replacement.o austin_or_logical_negation.o austin_or_logical_replacement.o austin_subtract_arithmetic_replacement.o bitwise_and_logical_assignment_replacement.o bitwise_and_logical_replacement.o bitwise_or_logical_assignment_replacement.o bitwise_or_logical_replacement.o divide_arithmetic_assignment_replacement.o divide_arithmetic_replacement.o equal_relational_replacement.o greater_equal_relational_replacement.o greater_relational_replacement.o if_expression_negation_replacement.o integer_constant_replacement.o less_equal_relational_replacement.o less_relational_replacement.o modulus_arithmetic_assignment_replacement.o modulus_arithmetic_replacement.o multiply_arithmetic_assignment_replacement.o multiply_arithmetic_replacement.o not_equal_relational_replacement.o or_logical_negation.o or_logical_replacement.o postfix_decrement_replacement.o postfix_increment_replacement.o prefix_decrement_replacement.o prefix_increment_replacement.o subtract_arithmetic_assignment_replacement.o subtract_arithmetic_replacement.o break_continue_replacement.o float_constant_replacement.o statement_deletion.o integer_var_abs_insertion.o float_var_abs_insertion.o integer_var_uoi_insertion.o while_expression_negation_replacement.o remove_null_assignment.o replace_calloc_with_null.o replace_malloc_with_null.o replace_malloc_size_with_zero.o replace_calloc_size_with_zero.o replace_sizeof_argument_with_pointer_equivalent.o replace_sizeof_argument_with_nonpointer_equivalent.o replace_calloc_with_malloc.o remove_free_statement.o replace_malloc_with_alloca.o replace_calloc_with_alloca.o
MUTOBJ=add_arithmetic_assignment_replacement.o add_arithmetic_replacement.o and_logical_negation.o and_logical_replacement.o austin_add_arithmetic_replacement.o austin_and_logical_negation.o austin_and_logical_replacement.o austin_divide_arithmetic_replacement.o austin_equal_relational_replacement.o austin_greater_equal_relational_replacement.o austin_greater_relationa_replacement.o austin_integer_constant_replacement.o austin_less_equal_relational_replacement.o austin_less_relational_replacement.o austin_modulus_arithmetic_replacement.o austin_multiply_arithmetic_replacement.o austin_not_equal_relational_replacement.o austin_or_logical_negation.o austin_or_logical_replacement.o austin_subtract_arithmetic_replacement.o bitwise_and_logical_assignment_replacement.o bitwise_and_logical_replacement.o bitwise_or_logical_assignment_replacement.o bitwise_or_logical_replacement.o divide_arithmetic_assignment_replacement.o divide_arithmetic_replacement.o equal_relational_replacement.o greater_equal_relational_replacement.o greater_relational_replacement.o if_expression_negation_replacement.o integer_constant_replacement.o less_equal_relational_replacement.o less_relational_replacement.o modulus_arithmetic_assignment_replacement.o modulus_arithmetic_replacement.o multiply_arithmetic_assignment_replacement.o multiply_arithmetic_replacement.o not_equal_relational_replacement.o or_logical_negation.o or_logical_replacement.o postfix_decrement_replacement.o postfix_increment_replacement.o prefix_decrement_replacement.o prefix_increment_replacement.o subtract_arithmetic_assignment_replacement.o subtract_arithmetic_replacement.o break_continue_replacement.o float_constant_replacement.o statement_deletion.o integer_var_abs_insertion.o float_var_abs_insertion.o integer_var_uoi_insertion.o while_expression_negation_replacement.o remove_null_assignment.o replace_calloc_with_null.o replace_malloc_with_null.o replace_malloc_size_with_zero.o replace_calloc_size_with_zero.o replace_sizeof_argument_with_pointer_equivalent.o replace_sizeof_argument_with_nonpointer_equivalent.o replace_calloc_with_malloc.o remove_free_statement.o replace_malloc_with_alloca.o replace_calloc_with_alloca.o replace_cast_calloc_with_alloca.o replace_cast_calloc_with_malloc.o replace_cast_calloc_with_null.o replace_cast_malloc_with_null.o

OPOBJ=Austin_CRCR.o Austin_OAAN.o Austin_OLLN.o Austin_OLNG.o Austin_ORRN.o CRCR.o ABS.o OAAA.o OAAN.o OBBA.o OBBN.o OCNG.o OIDO.o OLLN.o OLNG.o ORRN.o SBRC.o SSDL.o UOI.o RMNA.o REDAWN.o REDAWZ.o RESOTPE.o REMSOTP.o REC2M.o RMFS.o REM2A.o REC2A.o

Expand Down
22 changes: 20 additions & 2 deletions src/include/ASTNodeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,32 @@ gboolean is_ASTNode_null_assignment(const ASTNode * node);
gboolean is_ASTNode_calloc_call(const ASTNode * node);

/**
* \brief Check if the given node is the root of a calloc call
* \brief Check if the given node is the root of a malloc call
*
* \node The given node to check.
*
* \return TRUE if the given node is the root of a calloc call.
* \return TRUE if the given node is the root of a malloc call.
**/
gboolean is_ASTNode_malloc_call(const ASTNode * node);

/**
* \brief Check if the given node is the root of a calloc call with a cast in front
*
* \node The given node to check.
*
* \return TRUE if the given node is the root of a calloc call with a cast in front.
**/
gboolean is_ASTNode_cast_calloc_call(const ASTNode * node);

/**
* \brief Check if the given node is the root of a malloc call with a cast in front
*
* \node The given node to check.
*
* \return TRUE if the given node is the root of a malloc call with a cast in front.
**/
gboolean is_ASTNode_cast_malloc_call(const ASTNode * node);

/**
* \brief Check if the given node has calloc call in it's children nodes
*
Expand Down
26 changes: 26 additions & 0 deletions src/mutation/ASTNodeUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,32 @@ gboolean is_ASTNode_malloc_call(const ASTNode * node)
return FALSE;
}

gboolean is_ASTNode_cast_calloc_call(const ASTNode * node)
{
ASTNode * child;
if(is_ASTNode_has_kind(node, NodeKind_CStyleCastExpr)){
if(!node->children || !node->children->next_sibling) return FALSE;
child=node->children->next_sibling;
if(is_ASTNode_has_kind(child, NodeKind_CallExpr) && is_ASTNode_has_text(child, "calloc")){
return TRUE;
}
}
return FALSE;
}

gboolean is_ASTNode_cast_malloc_call(const ASTNode * node)
{
ASTNode * child;
if(is_ASTNode_has_kind(node, NodeKind_CStyleCastExpr)){
if(!node->children || !node->children->next_sibling) return FALSE;
child=node->children->next_sibling;
if(is_ASTNode_has_kind(child, NodeKind_CallExpr) && is_ASTNode_has_text(child, "malloc")){
return TRUE;
}
}
return FALSE;
}

gboolean has_ASTNode_calloc_call(const ASTNode * node)
{
ASTNode * child;
Expand Down
17 changes: 14 additions & 3 deletions src/mutators/memory_c/REDAWZ/replace_calloc_size_with_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ Mutator * mutator_milu_replace_calloc_size_with_zero()

static gboolean mutator_milu_replace_calloc_size_with_zero_node_checking(ASTNode * node)
{
return is_ASTNode_calloc_call(node);
return is_ASTNode_calloc_call(node) || is_ASTNode_cast_calloc_call(node);
}

static gboolean mutator_milu_replace_calloc_size_with_zero_mutate(ASTNode * node, gint type)
{
ASTNode * replace;
ASTNode * child=node->children->children->next_sibling;
ASTNode * child;
if(is_ASTNode_cast_calloc_call(node)){
child=node->children->next_sibling->children->next_sibling;
}
else{
child=node->children->children->next_sibling;
}
switch(type)
{
case 1:
Expand All @@ -74,7 +80,12 @@ static gboolean mutator_milu_replace_calloc_size_with_zero_mutate(ASTNode * node

static gboolean mutator_milu_replace_calloc_size_with_zero_clean(ASTNode * node, gint type)
{
node=node->children->children->next_sibling;
if(is_ASTNode_cast_calloc_call(node)){
node=node->children->next_sibling->children->next_sibling;
}
else{
node=node->children->children->next_sibling;
}
replace_subtree_with(node, tmpNode);
tmpNode=NULL;
return TRUE;
Expand Down
17 changes: 14 additions & 3 deletions src/mutators/memory_c/REDAWZ/replace_malloc_size_with_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ Mutator * mutator_milu_replace_malloc_size_with_zero()

static gboolean mutator_milu_replace_malloc_size_with_zero_node_checking(ASTNode * node)
{
return is_ASTNode_malloc_call(node);
return is_ASTNode_malloc_call(node) || is_ASTNode_cast_malloc_call(node);
}

static gboolean mutator_milu_replace_malloc_size_with_zero_mutate(ASTNode * node, gint type)
{
ASTNode * replace;
ASTNode * child=node->children->children->next_sibling;
ASTNode * child;
if(is_ASTNode_cast_malloc_call(node)){
child=node->children->next_sibling->children->next_sibling;
}
else{
child=node->children->children->next_sibling;
}
switch(type)
{
case 1:
Expand All @@ -74,7 +80,12 @@ static gboolean mutator_milu_replace_malloc_size_with_zero_mutate(ASTNode * node

static gboolean mutator_milu_replace_malloc_size_with_zero_clean(ASTNode * node, gint type)
{
node=node->children->children->next_sibling;
if(is_ASTNode_cast_malloc_call(node)){
node=node->children->next_sibling->children->next_sibling;
}
else{
node=node->children->children->next_sibling;
}
replace_subtree_with(node, tmpNode);
tmpNode=NULL;
return TRUE;
Expand Down
26 changes: 19 additions & 7 deletions src/mutators/memory_c/REM2A/replace_malloc_with_alloca.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ Mutator * mutator_milu_replace_malloc_with_alloca()

static gboolean mutator_milu_replace_malloc_with_alloca_node_checking(ASTNode * node)
{
return is_ASTNode_malloc_call(node);
return is_ASTNode_malloc_call(node) || is_ASTNode_cast_malloc_call(node);
}

static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, gint type)
{
switch(type)
{
case 1:
ASTNode_set_text(node, "alloca");
ASTNode_set_text(node->children, "alloca");
ASTNode_set_text(node->children->children, "alloca");
if(is_ASTNode_malloc_call(node)){
ASTNode_set_text(node, "alloca");
ASTNode_set_text(node->children, "alloca");
ASTNode_set_text(node->children->children, "alloca");
}
else{
ASTNode_set_text(node->children->next_sibling, "alloca");
ASTNode_set_text(node->children->next_sibling->children, "alloca");
}
return TRUE;

default:
Expand All @@ -70,8 +76,14 @@ static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, g

static gboolean mutator_milu_replace_malloc_with_alloca_clean(ASTNode * node, gint type)
{
ASTNode_set_text(node, "malloc");
ASTNode_set_text(node->children, "malloc");
ASTNode_set_text(node->children->children, "malloc");
if(is_ASTNode_malloc_call(node)){
ASTNode_set_text(node, "malloc");
ASTNode_set_text(node->children, "malloc");
ASTNode_set_text(node->children->children, "malloc");
}
else{
ASTNode_set_text(node->children->next_sibling, "malloc");
ASTNode_set_text(node->children->next_sibling->children, "malloc");
}
return TRUE;
}
23 changes: 10 additions & 13 deletions src/mutators/selective_c/CRCR/integer_constant_replacement.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,25 @@ static gboolean mutator_milu_integer_constant_replacement_mutate(ASTNode * node,
// set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) * -1));
// return TRUE;
case 6:
if(atoi(node->text) != 15)
set_ASTNode_text (node, "15");
if(atoi(node->text) != 1023)
set_ASTNode_text (node, "1023");
else
set_ASTNode_text (node, "16");
set_ASTNode_text (node, "511");
return TRUE;
case 7:
if(atoi(node->text) != 255)
set_ASTNode_text (node, "255");
if(atoi(node->text) != 32767)
set_ASTNode_text (node, "32767");
else
set_ASTNode_text (node, "256");
set_ASTNode_text (node, "16383");
return TRUE;
case 8:
if(atoi(node->text) != 1023)
set_ASTNode_text (node, "1023");
else
set_ASTNode_text (node, "1024");
set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) * 2));
return TRUE;
case 9:
if(atoi(node->text) != 32767)
set_ASTNode_text (node, "32767");
if(atoi(node->text) >= 4 || atoi(node->text) <= -4)
set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) / 2));
else
set_ASTNode_text (node, "32768");
set_ASTNode_text (node, g_strdup_printf("%d", atoi(node->text) * 3));
return TRUE;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions src/operators/REC2A.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Operator * get_REC2A_operator()
Operator * op = mutation_operator_new(name, info);

g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_alloca());
g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_calloc_with_alloca());

return op;
}
Expand Down
1 change: 1 addition & 0 deletions src/operators/REC2M.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Operator * get_REC2M_operator()
Operator * op = mutation_operator_new(name, info);

g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_malloc());
g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_calloc_with_malloc());

return op;
}
Expand Down
2 changes: 2 additions & 0 deletions src/operators/REDAWN.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Operator * get_REDAWN_operator()

g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_null());
g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_malloc_with_null());
g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_calloc_with_null());
g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_cast_malloc_with_null());

return op;
}
Expand Down

0 comments on commit 9c4d426

Please sign in to comment.