[flac-dev] [PATCH] Fix cppcheck warnings

Rosen Penev rosenp at gmail.com
Thu Jan 19 02:45:28 UTC 2017


---
 src/libFLAC/bitreader.c         | 4 ++--
 src/libFLAC/bitwriter.c         | 4 ++--
 src/plugin_xmms/plugin.c        | 2 +-
 src/share/utf8/charset.c        | 1 +
 src/test_libFLAC++/encoders.cpp | 8 ++++----
 src/test_libFLAC/decoders.c     | 4 ++--
 src/test_libFLAC/encoders.c     | 8 ++++----
 7 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c
index 386f420..7554385 100644
--- a/src/libFLAC/bitreader.c
+++ b/src/libFLAC/bitreader.c
@@ -306,7 +306,7 @@ void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
 				if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
 					fprintf(out, ".");
 				else
-					fprintf(out, "%01u", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
+					fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
 			fprintf(out, "\n");
 		}
 		if(br->bytes > 0) {
@@ -315,7 +315,7 @@ void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
 				if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
 					fprintf(out, ".");
 				else
-					fprintf(out, "%01u", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0);
+					fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0);
 			fprintf(out, "\n");
 		}
 	}
diff --git a/src/libFLAC/bitwriter.c b/src/libFLAC/bitwriter.c
index 8f475d5..bfe79b0 100644
--- a/src/libFLAC/bitwriter.c
+++ b/src/libFLAC/bitwriter.c
@@ -201,13 +201,13 @@ void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
 		for(i = 0; i < bw->words; i++) {
 			fprintf(out, "%08X: ", i);
 			for(j = 0; j < FLAC__BITS_PER_WORD; j++)
-				fprintf(out, "%01u", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
+				fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
 			fprintf(out, "\n");
 		}
 		if(bw->bits > 0) {
 			fprintf(out, "%08X: ", i);
 			for(j = 0; j < bw->bits; j++)
-				fprintf(out, "%01u", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0);
+				fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0);
 			fprintf(out, "\n");
 		}
 	}
diff --git a/src/plugin_xmms/plugin.c b/src/plugin_xmms/plugin.c
index d84d53c..94fbae5 100644
--- a/src/plugin_xmms/plugin.c
+++ b/src/plugin_xmms/plugin.c
@@ -324,7 +324,7 @@ void FLAC_XMMS__play_file(char *filename)
 		}
 		else {
 			/*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */
-			fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", stream_data_.bits_per_sample);
+			fprintf(stderr, "libxmms-flac: can't handle %u bit output\n", stream_data_.bits_per_sample);
 			safe_decoder_finish_(decoder_);
 			return;
 		}
diff --git a/src/share/utf8/charset.c b/src/share/utf8/charset.c
index 432e32d..0c2d1ee 100644
--- a/src/share/utf8/charset.c
+++ b/src/share/utf8/charset.c
@@ -522,6 +522,7 @@ int charset_convert(const char *fromcode, const char *tocode,
   if (to) {
     newbuf = realloc(tobuf, p - tobuf);
     *to = newbuf ? newbuf : tobuf;
+    free(newbuf);
   }
   else
     free(tobuf);
diff --git a/src/test_libFLAC++/encoders.cpp b/src/test_libFLAC++/encoders.cpp
index 277e129..e328a53 100644
--- a/src/test_libFLAC++/encoders.cpp
+++ b/src/test_libFLAC++/encoders.cpp
@@ -438,7 +438,7 @@ static bool test_stream_encoder(Layer layer, bool is_ogg)
 
 	printf("testing get_max_lpc_order()... ");
 	if(encoder->get_max_lpc_order() != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
+		printf("FAILED, expected %d, got %u\n", 0, encoder->get_max_lpc_order());
 		return false;
 	}
 	printf("OK\n");
@@ -471,21 +471,21 @@ static bool test_stream_encoder(Layer layer, bool is_ogg)
 
 	printf("testing get_min_residual_partition_order()... ");
 	if(encoder->get_min_residual_partition_order() != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
+		printf("FAILED, expected %d, got %u\n", 0, encoder->get_min_residual_partition_order());
 		return false;
 	}
 	printf("OK\n");
 
 	printf("testing get_max_residual_partition_order()... ");
 	if(encoder->get_max_residual_partition_order() != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
+		printf("FAILED, expected %d, got %u\n", 0, encoder->get_max_residual_partition_order());
 		return false;
 	}
 	printf("OK\n");
 
 	printf("testing get_rice_parameter_search_dist()... ");
 	if(encoder->get_rice_parameter_search_dist() != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
+		printf("FAILED, expected %d, got %u\n", 0, encoder->get_rice_parameter_search_dist());
 		return false;
 	}
 	printf("OK\n");
diff --git a/src/test_libFLAC/decoders.c b/src/test_libFLAC/decoders.c
index 46114f1..e9d52e9 100644
--- a/src/test_libFLAC/decoders.c
+++ b/src/test_libFLAC/decoders.c
@@ -282,10 +282,10 @@ static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder
 		return;
 
 	if (metadata->type == FLAC__METADATA_TYPE_APPLICATION) {
-		printf ("%d ('%c%c%c%c')... ", dcd->current_metadata_number, metadata->data.application.id [0], metadata->data.application.id [1], metadata->data.application.id [2], metadata->data.application.id [3]);
+		printf ("%u ('%c%c%c%c')... ", dcd->current_metadata_number, metadata->data.application.id [0], metadata->data.application.id [1], metadata->data.application.id [2], metadata->data.application.id [3]);
 	}
 	else {
-		printf("%d... ", dcd->current_metadata_number);
+		printf("%u... ", dcd->current_metadata_number);
 	}
 	fflush(stdout);
 
diff --git a/src/test_libFLAC/encoders.c b/src/test_libFLAC/encoders.c
index 510a9c2..7aefe79 100644
--- a/src/test_libFLAC/encoders.c
+++ b/src/test_libFLAC/encoders.c
@@ -397,7 +397,7 @@ static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg)
 
 	printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
 	if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
+		printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
 		return false;
 	}
 	printf("OK\n");
@@ -430,21 +430,21 @@ static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg)
 
 	printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
 	if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
+		printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
 		return false;
 	}
 	printf("OK\n");
 
 	printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
 	if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
+		printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
 		return false;
 	}
 	printf("OK\n");
 
 	printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
 	if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
-		printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
+		printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
 		return false;
 	}
 	printf("OK\n");
-- 
2.9.3



More information about the flac-dev mailing list