Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Sep 24, 2015
1 parent 60de3cc commit 92fee0f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion libyara/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ int yr_execute_code(
if (is_undef(r2))
stack[sp - r1.i].i = UNDEFINED;
else
stack[sp - r1.i].d = r2.i;
stack[sp - r1.i].d = (double) r2.i;
break;

case OP_STR_TO_BOOL:
Expand Down
39 changes: 24 additions & 15 deletions libyara/modules/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ double log2(double n)

define_function(string_entropy)
{
int i;
size_t i;
double entropy = 0.0;

SIZED_STRING* s = sized_string_argument(1);
Expand Down Expand Up @@ -67,10 +67,12 @@ define_function(string_entropy)

define_function(data_entropy)
{
int i, past_first_block = FALSE;
int past_first_block = FALSE;
double entropy = 0.0;

size_t total_len = 0;
size_t i;

uint32_t* data;

int64_t offset = integer_argument(1); // offset where to start
Expand All @@ -92,7 +94,7 @@ define_function(data_entropy)
if (offset >= block->base &&
offset < block->base + block->size)
{
size_t data_offset = offset - block->base;
size_t data_offset = (size_t) (offset - block->base);
size_t data_len = (size_t) yr_min(
length, (size_t) (block->size - data_offset));

Expand Down Expand Up @@ -151,7 +153,7 @@ define_function(string_deviation)
double mean = float_argument(2);
double sum = 0.0;

int i;
size_t i;

for (i = 0; i < s->length; i++)
sum += fabs(((double) s->c_string[i]) - mean);
Expand All @@ -162,7 +164,7 @@ define_function(string_deviation)

define_function(data_deviation)
{
int i, past_first_block = FALSE;
int past_first_block = FALSE;

int64_t offset = integer_argument(1);
int64_t length = integer_argument(2);
Expand All @@ -171,6 +173,7 @@ define_function(data_deviation)
double sum = 0.0;

size_t total_len = 0;
size_t i;

YR_SCAN_CONTEXT* context = scan_context();
YR_MEMORY_BLOCK* block = NULL;
Expand All @@ -183,7 +186,7 @@ define_function(data_deviation)
if (offset >= block->base &&
offset < block->base + block->size)
{
size_t data_offset = offset - block->base;
size_t data_offset = (size_t) (offset - block->base);
size_t data_len = (size_t) yr_min(
length, (size_t) (block->size - data_offset));

Expand Down Expand Up @@ -219,7 +222,7 @@ define_function(data_deviation)

define_function(string_mean)
{
int i;
size_t i;
double sum = 0.0;

SIZED_STRING* s = sized_string_argument(1);
Expand All @@ -233,7 +236,7 @@ define_function(string_mean)

define_function(data_mean)
{
int i, past_first_block = FALSE;
int past_first_block = FALSE;
double sum = 0.0;

int64_t offset = integer_argument(1);
Expand All @@ -243,6 +246,7 @@ define_function(data_mean)
YR_MEMORY_BLOCK* block = NULL;

size_t total_len = 0;
size_t i;

if (offset < 0 || length < 0 || offset < context->mem_block->base)
return ERROR_WRONG_ARGUMENTS;
Expand All @@ -252,7 +256,7 @@ define_function(data_mean)
if (offset >= block->base &&
offset < block->base + block->size)
{
size_t data_offset = offset - block->base;
size_t data_offset = (size_t) (offset - block->base);
size_t data_len = (size_t) yr_min(
length, (size_t) (block->size - data_offset));

Expand Down Expand Up @@ -288,8 +292,10 @@ define_function(data_mean)

define_function(data_serial_correlation)
{
int i, past_first_block = FALSE;
int past_first_block = FALSE;

size_t total_len = 0;
size_t i;

int64_t offset = integer_argument(1);
int64_t length = integer_argument(2);
Expand All @@ -312,7 +318,7 @@ define_function(data_serial_correlation)
if (offset >= block->base &&
offset < block->base + block->size)
{
size_t data_offset = offset - block->base;
size_t data_offset = (size_t) (offset - block->base);
size_t data_len = (size_t) yr_min(
length, (size_t) (block->size - data_offset));

Expand Down Expand Up @@ -373,7 +379,7 @@ define_function(string_serial_correlation)
double scct3 = 0;
double scc = 0;

int i;
size_t i;

for (i = 0; i < s->length; i++)
{
Expand All @@ -400,13 +406,15 @@ define_function(string_serial_correlation)

define_function(data_monte_carlo_pi)
{
int i, past_first_block = FALSE;
int past_first_block = FALSE;
int mcount = 0;
int inmont = 0;

double INCIRC = pow(pow(256.0, 3.0) - 1, 2.0);
double mpi = 0;

size_t i;

int64_t offset = integer_argument(1);
int64_t length = integer_argument(2);

Expand All @@ -423,7 +431,7 @@ define_function(data_monte_carlo_pi)
{
unsigned int monte[6];

size_t data_offset = offset - block->base;
size_t data_offset = (size_t) (offset - block->base);
size_t data_len = (size_t) yr_min(
length, (size_t) (block->size - data_offset));

Expand Down Expand Up @@ -489,7 +497,8 @@ define_function(string_monte_carlo_pi)

int mcount = 0;
int inmont = 0;
int i;

size_t i;

for (i = 0; i < s->length; i++)
{
Expand Down
10 changes: 7 additions & 3 deletions libyara/modules/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ define_function(exports)
DWORD* names;

int64_t offset;
int i;
uint32_t i;

// If not a PE file, return UNDEFINED

Expand Down Expand Up @@ -1688,10 +1688,12 @@ define_function(imports_ordinal)
YR_OBJECT* module = module();
PE* pe = (PE*) module->data;

IMPORTED_DLL* imported_dll;

if (!pe)
return_integer(UNDEFINED);

IMPORTED_DLL* imported_dll = pe->imported_dlls;
imported_dll = pe->imported_dlls;

while (imported_dll != NULL)
{
Expand Down Expand Up @@ -1721,10 +1723,12 @@ define_function(imports_dll)
YR_OBJECT* module = module();
PE* pe = (PE*) module->data;

IMPORTED_DLL* imported_dll;

if (!pe)
return_integer(UNDEFINED);

IMPORTED_DLL* imported_dll = pe->imported_dlls;
imported_dll = pe->imported_dlls;

while (imported_dll != NULL)
{
Expand Down
5 changes: 3 additions & 2 deletions libyara/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,11 +1102,12 @@ void yr_object_print_data(
case OBJECT_TYPE_STRING:
if (((YR_OBJECT_STRING*) object)->value != NULL)
{
size_t l;
printf(" = \"");

for (i = 0; i < ((YR_OBJECT_STRING*) object)->value->length; i++)
for (l = 0; l < ((YR_OBJECT_STRING*) object)->value->length; l++)
{
char c = ((YR_OBJECT_STRING*) object)->value->c_string[i];
char c = ((YR_OBJECT_STRING*) object)->value->c_string[l];

if (isprint(c))
printf("%c", c);
Expand Down
6 changes: 3 additions & 3 deletions libyara/re.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ int yr_re_exec(
max_count = (int) yr_min(input_size, RE_SCAN_LIMIT);

// Round down max_count to a multiple of character_size, this way if
// character_size is 2 and input_size is impair we are ignoring the
// character_size is 2 and input_size is odd we are ignoring the
// extra byte which can't match anyways.

max_count = max_count - max_count % character_size;
Expand Down Expand Up @@ -1779,14 +1779,14 @@ int yr_re_exec(

case RE_OPCODE_MATCH_AT_START:
if (flags & RE_FLAGS_BACKWARDS)
kill = input_size > count;
kill = input_size > (size_t) count;
else
kill = (flags & RE_FLAGS_NOT_AT_START) || (count != 0);
action = kill ? ACTION_KILL : ACTION_CONTINUE;
break;

case RE_OPCODE_MATCH_AT_END:
action = input_size > count ? ACTION_KILL : ACTION_CONTINUE;
action = input_size > (size_t) count ? ACTION_KILL : ACTION_CONTINUE;
break;

case RE_OPCODE_MATCH:
Expand Down

0 comments on commit 92fee0f

Please sign in to comment.