Skip to content

Commit

Permalink
Fixed several compiler warnings
Browse files Browse the repository at this point in the history
- Warnings detected thanks to Xcode's compiler settings (more strict by
  default) and clang, warnings mostly but not only related to data sizes
  on 64 bit systems, that were silenced until now by very lax compiler
  settings.
- This also decreases by a great deal the amount of warnings produced by
  MSVC in x64 mode (for the adventurous ones who tried that)
- Also fixed (or silenced in case of false positives) the potential
  issues pointed out by the (awesome) clang static analyzer.
- Patch co-produced with Ind, I'm merging and committing in his place!

Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Dec 17, 2013
1 parent a23d072 commit 15a0f6d
Show file tree
Hide file tree
Showing 61 changed files with 878 additions and 690 deletions.
1 change: 1 addition & 0 deletions 3rdparty/libconfig/extra/gen/Makefile
Expand Up @@ -31,6 +31,7 @@ AM_YFLAGS = -d -p $(PARSER_PREFIX)
AM_LFLAGS = --nounistd --header-file=scanner.h --prefix=$(PARSER_PREFIX)

all: $(BUILT_SOURCES)
@patch -p1 < clangwarnings.patch

.SUFFIXES: .c .l .y

Expand Down
1 change: 1 addition & 0 deletions 3rdparty/libconfig/extra/gen/Makefile.in
Expand Up @@ -31,6 +31,7 @@ AM_YFLAGS = -d -p $(PARSER_PREFIX)
AM_LFLAGS = --nounistd --header-file=scanner.h --prefix=$(PARSER_PREFIX)

all: $(BUILT_SOURCES)
@patch -p1 < clangwarnings.patch

.SUFFIXES: .c .l .y

Expand Down
36 changes: 36 additions & 0 deletions 3rdparty/libconfig/extra/gen/clangwarnings.patch
@@ -0,0 +1,36 @@
diff --git a/grammar.c b/grammar.c
index 3595578..26444f8 100644
--- a/grammar.c
+++ b/grammar.c
@@ -1187,9 +1187,7 @@ void libconfig_yyerror(void *scanner, struct parse_context *ctx,
YYUSE (ctx);
YYUSE (scan_ctx);

- if (!yymsg)
- yymsg = "Deleting";
- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+ YY_SYMBOL_PRINT (yymsg ? yymsg : "Deleting", yytype, yyvaluep, yylocationp);

switch (yytype)
{
diff --git a/scanner.c b/scanner.c
index aebd34c..c3a717f 100644
--- a/scanner.c
+++ b/scanner.c
@@ -1500,6 +1500,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;

+#ifndef __clang_analyzer__
+ // FIXME: Clang's static analyzer complains about leaking the result of libconfig_yyrealloc
if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
@@ -1507,6 +1509,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
}
+#endif // __clang_analyzer__

yyg->yy_n_chars += number_to_move;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
12 changes: 8 additions & 4 deletions 3rdparty/libconfig/extra/gen/scanner.l
Expand Up @@ -86,6 +86,13 @@ static unsigned long long fromhex(const char *s)
#endif /* __MINGW32__ */
}

static int fromihex(const char *s) {
unsigned long l = strtoul(s, NULL, 16);
if (l > INT32_MAX)
l = INT32_MAX;
return (int)l;
}

%}

true [Tt][Rr][Uu][Ee]
Expand Down Expand Up @@ -178,10 +185,7 @@ include_open ^[ \t]*@include[ \t]+\"
{float} { yylval->fval = atof(yytext); return(TOK_FLOAT); }
{integer} { yylval->ival = atoi(yytext); return(TOK_INTEGER); }
{integer64} { yylval->llval = atoll(yytext); return(TOK_INTEGER64); }
{hex} {
yylval->ival = strtoul(yytext, NULL, 16);
return(TOK_HEX);
}
{hex} { yylval->ival = fromihex(yytext); return(TOK_HEX); }
{hex64} { yylval->llval = fromhex(yytext); return(TOK_HEX64); }
\[ { return(TOK_ARRAY_START); }
\] { return(TOK_ARRAY_END); }
Expand Down
4 changes: 1 addition & 3 deletions 3rdparty/libconfig/grammar.c
Expand Up @@ -1187,9 +1187,7 @@ yydestruct (yymsg, yytype, yyvaluep, scanner, ctx, scan_ctx)
YYUSE (ctx);
YYUSE (scan_ctx);

if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
YY_SYMBOL_PRINT (yymsg ? yymsg : "Deleting", yytype, yyvaluep, yylocationp);

switch (yytype)
{
Expand Down
2 changes: 2 additions & 0 deletions 3rdparty/libconfig/scanctx.c
Expand Up @@ -39,6 +39,7 @@ static const char *err_include_too_deep = "include file nesting too deep";
static const char *__scanctx_add_filename(struct scan_context *ctx,
const char *filename)
{
#ifndef __clang_analyzer__ // FIXME: Clang's static analyzer doesn't like this
unsigned int count = ctx->num_filenames;
const char **f;

Expand All @@ -60,6 +61,7 @@ static const char *__scanctx_add_filename(struct scan_context *ctx,

ctx->filenames[ctx->num_filenames] = filename;
++ctx->num_filenames;
#endif // __clang_analyzer__
return(filename);
}

Expand Down

0 comments on commit 15a0f6d

Please sign in to comment.