[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/7] Add -W (-Wextra) to AM_CFLAGS and fix resulting warnings
From: |
Tim Hentenaar |
Subject: |
[PATCH 4/7] Add -W (-Wextra) to AM_CFLAGS and fix resulting warnings |
Date: |
Sun, 5 Jul 2015 15:10:51 +0200 |
---
src/Makefile.am | 2 +-
src/args.c | 2 +-
src/backup.c | 2 +-
src/code_io.c | 16 ++++++++--------
src/handletoken.c | 2 +-
src/indent.c | 3 +++
6 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index ed60768..2361535 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,7 @@ MAINTAINERCLEANFILES= Makefile.in libgettext.h
# Only pass -ansi and -pedantic via CC otherwise clang compains
CCLD := $(CC)
CC := $(CC) -ansi -pedantic
-AM_CFLAGS = -Wall -Werror -Wredundant-decls -Wshadow -Wstrict-prototypes
+AM_CFLAGS = -Wall -W -Werror -Wredundant-decls -Wshadow -Wstrict-prototypes
AM_CFLAGS += -Wmissing-prototypes -Wnested-externs -Wmissing-declarations
AM_CFLAGS += -Wcomment -Wbad-function-cast -Wcast-align
diff --git a/src/args.c b/src/args.c
index a832133..224bc51 100644
--- a/src/args.c
+++ b/src/args.c
@@ -229,7 +229,7 @@ static int exp_ntac = 0;
* their meaning is explained in indent.h.
*/
-user_options_ty settings = {0};
+user_options_ty settings;
/* N.B.: because of the way the table here is scanned, options whose names
* are substrings of other options must occur later; that is, with -lp vs -l,
diff --git a/src/backup.c b/src/backup.c
index 1a76c0b..a9831af 100644
--- a/src/backup.c
+++ b/src/backup.c
@@ -252,7 +252,7 @@ static int highest_version (
else
{
int this_version;
- int file_name_length = strlen(filename);
+ unsigned int file_name_length = strlen(filename);
highestVersion = 0;
diff --git a/src/code_io.c b/src/code_io.c
index d48756b..50a4ae6 100644
--- a/src/code_io.c
+++ b/src/code_io.c
@@ -248,7 +248,7 @@ extern file_buffer_ty * read_file(
char * filename,
struct stat * file_stats)
{
- static file_buffer_ty fileptr = {NULL};
+ static file_buffer_ty fileptr = {NULL, 0, NULL};
#if defined(__MSDOS__) || defined(VMS)
/*
@@ -263,7 +263,7 @@ extern file_buffer_ty * read_file(
size_t size_to_read = 0;
#endif
- int namelen = strlen(filename);
+ unsigned int namelen = strlen(filename);
int fd = open(filename, O_RDONLY, 0777);
if (fd < 0)
@@ -307,13 +307,13 @@ extern file_buffer_ty * read_file(
if (fileptr.data != 0)
{
fileptr.data = xrealloc(fileptr.data,
- (unsigned) file_stats->st_size + 2); /* add 1
for '\0' and 1 for
+ (unsigned)file_stats->st_size + 2); /* add 1
for '\0' and 1 for
* potential final added
* newline. */
}
else
{
- fileptr.data = xmalloc((unsigned) file_stats->st_size + 2); /* add 1
for '\0' and 1 for
+ fileptr.data = xmalloc((unsigned)file_stats->st_size + 2); /* add 1
for '\0' and 1 for
* potential final added
* newline. */
}
@@ -341,7 +341,7 @@ extern file_buffer_ty * read_file(
size_to_read -= size;
}
- if (close (fd) < 0)
+ if (close(fd) < 0)
{
xfree(fileptr.data);
fatal (_("Error closing input file %s"), filename);
@@ -352,14 +352,14 @@ extern file_buffer_ty * read_file(
* then the DOS `read' changes them into '\n'. Thus, the size of the
* file on disc is larger than what is read into memory. Thanks, Bill. */
- if (size < fileptr.size)
+ if ((size_t)size < fileptr.size)
{
fileptr.size = size;
}
if (fileptr.name != NULL)
{
- fileptr.name = xrealloc(fileptr.name, (unsigned) namelen + 1);
+ fileptr.name = xrealloc(fileptr.name, (unsigned)namelen + 1);
}
else
{
@@ -394,7 +394,7 @@ extern file_buffer_ty * read_file(
file_buffer_ty * read_stdin(void)
{
- static file_buffer_ty stdinptr = {NULL};
+ static file_buffer_ty stdinptr = {NULL, 0, NULL};
unsigned int size = 15 * BUFSIZ;
int ch = EOF;
diff --git a/src/handletoken.c b/src/handletoken.c
index ed3aef4..8cab767 100644
--- a/src/handletoken.c
+++ b/src/handletoken.c
@@ -83,7 +83,7 @@ extern void need_chars(buf_ty * bp, size_t needed)
{
size_t current_size = (size_t)(bp->end - bp->ptr);
- if (current_size + needed >= bp->size)
+ if (current_size + needed >= (size_t)bp->size)
{
bp->size = ((current_size + needed) & (size_t)~1023);
bp->ptr = xrealloc(bp->ptr, bp->size);
diff --git a/src/indent.c b/src/indent.c
index f38dedd..2c23117 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -1071,6 +1071,9 @@ int main(
wildexp(&argc, &argv);
#endif /* defined (_WIN32) && !defined (__CYGWIN__) */
+ /* Initialize settings */
+ memset(&settings, 0, sizeof(settings));
+
#ifdef DEBUG
if (debug)
{
--
2.3.6