From 91790ef965553fd6d76e1f51b55dc4de3b54ad4b Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 5 Mar 2013 22:19:27 +1100 Subject: [PATCH] Fix compiler warnings from new compiler flags. --- include/share/Makefile.am | 1 + include/share/macros.h | 41 +++++++++++++++++++++++ src/libFLAC/metadata_iterators.c | 5 +-- src/metaflac/operations_shorthand_vorbiscomment.c | 3 +- src/test_libFLAC++/metadata_manip.cpp | 5 +-- src/test_libFLAC/metadata_manip.c | 5 +-- src/test_seeking/main.c | 8 ++--- 7 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 include/share/macros.h diff --git a/include/share/Makefile.am b/include/share/Makefile.am index a881e77..fd8b947 100644 --- a/include/share/Makefile.am +++ b/include/share/Makefile.am @@ -8,6 +8,7 @@ EXTRA_DIST = \ endswap.h \ getopt.h \ grabbag.h \ + macros.h \ replaygain_analysis.h \ replaygain_synthesis.h \ utf8.h diff --git a/include/share/macros.h b/include/share/macros.h new file mode 100644 index 0000000..5be07a1 --- /dev/null +++ b/include/share/macros.h @@ -0,0 +1,41 @@ +/* libFLAC - Free Lossless Audio Codec library + * Copyright (C) 2013 Xiph.org Foundation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the Xiph.org Foundation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/* FLAC_CHECK_RETURN : Check the return value of of the provided function and + * print and error message if it fails (ie returns a value < 0). + */ + +#define FLAC_CHECK_RETURN(x) \ + { if ((x) < 0) \ + printf ("%s : %s\n", #x, strerror (errno)) ; \ + } diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c index b321e45..a679165 100644 --- a/src/libFLAC/metadata_iterators.c +++ b/src/libFLAC/metadata_iterators.c @@ -46,6 +46,7 @@ #include "FLAC/stream_decoder.h" #include "share/alloc.h" #include "share/compat.h" +#include "share/macros.h" #include "private/macros.h" #include "private/memory.h" @@ -3295,8 +3296,8 @@ void set_file_stats_(const char *filename, struct stat *stats) (void)chmod(filename, stats->st_mode); (void)utime(filename, &srctime); #if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__ - (void)chown(filename, stats->st_uid, -1); - (void)chown(filename, -1, stats->st_gid); + FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1)); + FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid)); #endif } diff --git a/src/metaflac/operations_shorthand_vorbiscomment.c b/src/metaflac/operations_shorthand_vorbiscomment.c index 5233832..a8d5cd1 100644 --- a/src/metaflac/operations_shorthand_vorbiscomment.c +++ b/src/metaflac/operations_shorthand_vorbiscomment.c @@ -302,8 +302,7 @@ FLAC__bool import_vc_from(const char *filename, FLAC__StreamMetadata *block, con } ret = true; - while(ret && !feof(f)) { - fgets(line, sizeof(line), f); + while(ret && !feof(f) && fgets(line, sizeof(line), f) != NULL) { if(!feof(f)) { char *p = strchr(line, '\n'); if(0 == p) { diff --git a/src/test_libFLAC++/metadata_manip.cpp b/src/test_libFLAC++/metadata_manip.cpp index 1d75dca..f278e53 100644 --- a/src/test_libFLAC++/metadata_manip.cpp +++ b/src/test_libFLAC++/metadata_manip.cpp @@ -32,6 +32,7 @@ #include "FLAC++/metadata.h" #include "share/grabbag.h" #include "share/compat.h" +#include "share/macros.h" extern "C" { #include "test_libs_common/file_utils_flac.h" } @@ -270,8 +271,8 @@ void set_file_stats_(const char *filename, struct stat *stats) (void)chmod(filename, stats->st_mode); (void)utime(filename, &srctime); #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__ - (void)chown(filename, stats->st_uid, (gid_t)(-1)); - (void)chown(filename, (uid_t)(-1), stats->st_gid); + FLAC_CHECK_RETURN(chown(filename, stats->st_uid, (gid_t)(-1))); + FLAC_CHECK_RETURN(chown(filename, (uid_t)(-1), stats->st_gid)); #endif } diff --git a/src/test_libFLAC/metadata_manip.c b/src/test_libFLAC/metadata_manip.c index a3d021f..e720056 100644 --- a/src/test_libFLAC/metadata_manip.c +++ b/src/test_libFLAC/metadata_manip.c @@ -37,6 +37,7 @@ #include "FLAC/metadata.h" #include "share/grabbag.h" #include "share/compat.h" +#include "share/macros.h" #include "test_libs_common/file_utils_flac.h" #include "test_libs_common/metadata_utils.h" #include "metadata.h" @@ -260,8 +261,8 @@ static void set_file_stats_(const char *filename, struct stat *stats) (void)chmod(filename, stats->st_mode); (void)utime(filename, &srctime); #if !defined _MSC_VER && !defined __MINGW32__ - (void)chown(filename, stats->st_uid, -1); - (void)chown(filename, -1, stats->st_gid); + FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1)); + FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid)); #endif } diff --git a/src/test_seeking/main.c b/src/test_seeking/main.c index 629ee16..c9f9567 100644 --- a/src/test_seeking/main.c +++ b/src/test_seeking/main.c @@ -167,8 +167,8 @@ static FLAC__bool read_pcm_(FLAC__int32 *pcm[], const char *rawfilename, const c signed char c; for(i = 0; i < samples; i++) { for(j = 0; j < channels; j++) { - fread(&c, 1, 1, f); - pcm[j][i] = c; + if (fread(&c, 1, 1, f) == 1) + pcm[j][i] = c; } } } @@ -176,8 +176,8 @@ static FLAC__bool read_pcm_(FLAC__int32 *pcm[], const char *rawfilename, const c unsigned char c[2]; for(i = 0; i < samples; i++) { for(j = 0; j < channels; j++) { - fread(&c, 1, 2, f); - pcm[j][i] = ((int)((signed char)c[0])) << 8 | (int)c[1]; + if (fread(&c, 1, 2, f) == 2) + pcm[j][i] = ((int)((signed char)c[0])) << 8 | (int)c[1]; } } } -- 2.7.4