Skip to content

Commit

Permalink
Compile with -Wall and remove some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Dec 2, 2013
1 parent c5b3b65 commit 7b6bc9b
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 232 deletions.
2 changes: 1 addition & 1 deletion libyara/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AM_YFLAGS=-d

AM_CFLAGS=-g -O4 -std=gnu99
AM_CFLAGS=-g -O4 -Wall -std=gnu99

ACLOCAL_AMFLAGS=-I m4

Expand Down
14 changes: 7 additions & 7 deletions libyara/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uint32_t byte_to_int32[] =

uint32_t hash(
uint32_t seed,
const char* buffer,
uint8_t* buffer,
int len)
{
int i;
Expand All @@ -92,8 +92,8 @@ int yr_hash_table_create(
YR_HASH_TABLE* new_table;
int i;

new_table = yr_malloc(sizeof(YR_HASH_TABLE) +
size * sizeof(YR_HASH_TABLE_ENTRY*));
new_table = yr_malloc(
sizeof(YR_HASH_TABLE) + size * sizeof(YR_HASH_TABLE_ENTRY*));

if (new_table == NULL)
return ERROR_INSUFICIENT_MEMORY;
Expand Down Expand Up @@ -143,10 +143,10 @@ void* yr_hash_table_lookup(
YR_HASH_TABLE_ENTRY* entry;
uint32_t bucket_index;

bucket_index = hash(0, key, strlen(key));
bucket_index = hash(0, (uint8_t*) key, strlen(key));

if (ns != NULL)
bucket_index = hash(bucket_index, ns, strlen(ns));
bucket_index = hash(bucket_index, (uint8_t*) ns, strlen(ns));

bucket_index = bucket_index % table->size;

Expand Down Expand Up @@ -195,10 +195,10 @@ int yr_hash_table_add(
entry->ns = NULL;

entry->value = value;
bucket_index = hash(0, key, strlen(key));
bucket_index = hash(0, (uint8_t*) key, strlen(key));

if (ns != NULL)
bucket_index = hash(bucket_index, ns, strlen(ns));
bucket_index = hash(bucket_index, (uint8_t*) ns, strlen(ns));

bucket_index = bucket_index % table->size;

Expand Down
76 changes: 17 additions & 59 deletions libyara/hex_lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
Expand Down Expand Up @@ -357,7 +358,7 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
yyleng = (size_t) (yy_cp - yy_bp); \
yyleng = (yy_size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
Expand Down Expand Up @@ -498,8 +499,9 @@ limitations under the License.
} \

#define YY_NO_UNISTD_H 1
#define YY_NO_INPUT 1

#line 503 "hex_lexer.c"
#line 505 "hex_lexer.c"

#define INITIAL 0
#define range 1
Expand Down Expand Up @@ -607,8 +609,6 @@ extern int hex_yywrap (yyscan_t yyscanner );
#endif
#endif

static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);

#ifndef yytext_ptr
static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
#endif
Expand Down Expand Up @@ -733,7 +733,7 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

#line 61 "hex_lexer.l"
#line 63 "hex_lexer.l"



Expand Down Expand Up @@ -836,7 +836,7 @@ YY_DECL

case 1:
YY_RULE_SETUP
#line 64 "hex_lexer.l"
#line 66 "hex_lexer.l"
{

yylval->integer = xtoi(yytext);
Expand All @@ -845,7 +845,7 @@ YY_RULE_SETUP
YY_BREAK
case 2:
YY_RULE_SETUP
#line 70 "hex_lexer.l"
#line 72 "hex_lexer.l"
{

yytext[1] = '0'; // replace ? by 0
Expand All @@ -855,7 +855,7 @@ YY_RULE_SETUP
YY_BREAK
case 3:
YY_RULE_SETUP
#line 77 "hex_lexer.l"
#line 79 "hex_lexer.l"
{

yytext[0] = '0'; // replace ? by 0
Expand All @@ -865,7 +865,7 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
#line 84 "hex_lexer.l"
#line 86 "hex_lexer.l"
{

yylval->integer = 0x0000;
Expand All @@ -874,7 +874,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 90 "hex_lexer.l"
#line 92 "hex_lexer.l"
{

BEGIN(range);
Expand All @@ -883,14 +883,14 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
#line 96 "hex_lexer.l"
#line 98 "hex_lexer.l"
{
return yytext[0];
}
YY_BREAK
case 7:
YY_RULE_SETUP
#line 100 "hex_lexer.l"
#line 102 "hex_lexer.l"
{

yylval->integer = atoi(yytext);
Expand All @@ -906,7 +906,7 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
#line 113 "hex_lexer.l"
#line 115 "hex_lexer.l"
{

BEGIN(INITIAL);
Expand All @@ -916,12 +916,12 @@ YY_RULE_SETUP
case 9:
/* rule 9 can match eol */
YY_RULE_SETUP
#line 120 "hex_lexer.l"
#line 122 "hex_lexer.l"
// skip whitespace
YY_BREAK
case 10:
YY_RULE_SETUP
#line 123 "hex_lexer.l"
#line 125 "hex_lexer.l"
{

if (yytext[0] >= 32 && yytext[0] < 127)
Expand All @@ -937,7 +937,7 @@ YY_RULE_SETUP
YY_BREAK
case 11:
YY_RULE_SETUP
#line 136 "hex_lexer.l"
#line 138 "hex_lexer.l"
ECHO;
YY_BREAK
#line 944 "hex_lexer.c"
Expand Down Expand Up @@ -1273,48 +1273,6 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
return yy_is_jam ? 0 : yy_current_state;
}

static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
{
register char *yy_cp;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

yy_cp = yyg->yy_c_buf_p;

/* undo effects of setting up yytext */
*yy_cp = yyg->yy_hold_char;

if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
register yy_size_t number_to_move = yyg->yy_n_chars + 2;
register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char *source =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];

while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
*--dest = *--source;

yy_cp += (int) (dest - source);
yy_bp += (int) (dest - source);
YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;

if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
YY_FATAL_ERROR( "flex scanner push-back overflow" );
}

*--yy_cp = (char) c;

if ( c == '\n' ){
--yylineno;
}

yyg->yytext_ptr = yy_bp;
yyg->yy_hold_char = *yy_cp;
yyg->yy_c_buf_p = yy_cp;
}

#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput (yyscan_t yyscanner)
Expand Down Expand Up @@ -2118,7 +2076,7 @@ void hex_yyfree (void * ptr , yyscan_t yyscanner)

#define YYTABLES_NAME "yytables"

#line 136 "hex_lexer.l"
#line 138 "hex_lexer.l"



Expand Down
2 changes: 2 additions & 0 deletions libyara/hex_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ limitations under the License.
%option reentrant bison-bridge
%option noyywrap
%option nounistd
%option noinput
%option nounput
%option yylineno
%option prefix="hex_yy"

Expand Down
Loading

0 comments on commit 7b6bc9b

Please sign in to comment.