[PATCH 1/3] treewide: Fix -Wformat=2 warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allows the compiler to check these formats at compile time.

Fixed several such warnings.

Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
 include/use-case.h     | 1 +
 src/error.c            | 2 ++
 src/input.c            | 6 ++++--
 src/output.c           | 6 ++++--
 src/pcm/pcm.c          | 4 ++--
 src/pcm/pcm_direct.c   | 2 +-
 src/pcm/pcm_file.c     | 6 +++---
 src/topology/builder.c | 3 ++-
 src/ucm/ucm_local.h    | 2 ++
 9 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/include/use-case.h b/include/use-case.h
index 2efcb4d8..3f0cf58e 100644
--- a/include/use-case.h
+++ b/include/use-case.h
@@ -188,6 +188,7 @@ typedef struct snd_use_case_mgr snd_use_case_mgr_t;
  * \param ... Optional arguments for sprintf like format
  * \return Allocated string identifier or NULL on error
  */
+__attribute__((format(printf, 1, 2)))
 char *snd_use_case_identifier(const char *fmt, ...);
 
 /**
diff --git a/src/error.c b/src/error.c
index 2e617f87..ad281411 100644
--- a/src/error.c
+++ b/src/error.c
@@ -95,6 +95,7 @@ snd_local_error_handler_t snd_lib_error_set_local(snd_local_error_handler_t func
  * \ref snd_lib_error_set_local, it is called. Otherwise, prints the error
  * message including location to \c stderr.
  */
+__attribute__((format(printf, 5, 6)))
 static void snd_lib_error_default(const char *file, int line, const char *function, int err, const char *fmt, ...)
 {
 	va_list arg;
@@ -149,6 +150,7 @@ const char *snd_asoundlib_version(void)
 /*
  * internal error handling
  */
+__attribute__((format(printf, 5, 6)))
 static void snd_err_msg_default(const char *file, int line, const char *function, int err, const char *fmt, ...)
 {
 	va_list arg;
diff --git a/src/input.c b/src/input.c
index 35324f1f..c204fe7b 100644
--- a/src/input.c
+++ b/src/input.c
@@ -132,6 +132,7 @@ static int snd_input_stdio_close(snd_input_t *input ATTRIBUTE_UNUSED)
 	return 0;
 }
 
+__attribute__((format(scanf, 2, 0)))
 static int snd_input_stdio_scan(snd_input_t *input, const char *format, va_list args)
 {
 	snd_input_stdio_t *stdio = input->private_data;
@@ -144,7 +145,7 @@ static char *snd_input_stdio_gets(snd_input_t *input, char *str, size_t size)
 	snd_input_stdio_t *stdio = input->private_data;
 	return fgets(str, (int) size, stdio->fp);
 }
-			
+
 static int snd_input_stdio_getc(snd_input_t *input)
 {
 	snd_input_stdio_t *stdio = input->private_data;
@@ -236,6 +237,7 @@ static int snd_input_buffer_close(snd_input_t *input)
 	return 0;
 }
 
+__attribute__((format(scanf, 2, 0)))
 static int snd_input_buffer_scan(snd_input_t *input, const char *format, va_list args)
 {
 	snd_input_buffer_t *buffer = input->private_data;
@@ -262,7 +264,7 @@ static char *snd_input_buffer_gets(snd_input_t *input, char *str, size_t size)
 	*str = '\0';
 	return str;
 }
-			
+
 static int snd_input_buffer_getc(snd_input_t *input)
 {
 	snd_input_buffer_t *buffer = input->private_data;
diff --git a/src/output.c b/src/output.c
index 7e3a91b3..935ab003 100644
--- a/src/output.c
+++ b/src/output.c
@@ -141,6 +141,7 @@ static int snd_output_stdio_close(snd_output_t *output)
 	return 0;
 }
 
+__attribute__((format(printf, 2, 0)))
 static int snd_output_stdio_print(snd_output_t *output, const char *format, va_list args)
 {
 	snd_output_stdio_t *stdio = output->private_data;
@@ -152,7 +153,7 @@ static int snd_output_stdio_puts(snd_output_t *output, const char *str)
 	snd_output_stdio_t *stdio = output->private_data;
 	return fputs(str, stdio->fp);
 }
-			
+
 static int snd_output_stdio_putc(snd_output_t *output, int c)
 {
 	snd_output_stdio_t *stdio = output->private_data;
@@ -268,6 +269,7 @@ static int snd_output_buffer_need(snd_output_t *output, size_t size)
 	return buffer->alloc - buffer->size;
 }
 
+__attribute__((format(printf, 2, 0)))
 static int snd_output_buffer_print(snd_output_t *output, const char *format, va_list args)
 {
 	snd_output_buffer_t *buffer = output->private_data;
@@ -304,7 +306,7 @@ static int snd_output_buffer_puts(snd_output_t *output, const char *str)
 	buffer->size += size;
 	return size;
 }
-			
+
 static int snd_output_buffer_putc(snd_output_t *output, int c)
 {
 	snd_output_buffer_t *buffer = output->private_data;
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 1064044c..09dfe967 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -8241,7 +8241,7 @@ int snd_pcm_chmap_print(const snd_pcm_chmap_t *map, size_t maxlen, char *buf)
 				return -ENOMEM;
 		}
 		if (map->pos[i] & SND_CHMAP_DRIVER_SPEC)
-			len += snprintf(buf + len, maxlen - len, "%d", p);
+			len += snprintf(buf + len, maxlen - len, "%u", p);
 		else {
 			const char *name = chmap_names[p];
 			if (name)
@@ -8249,7 +8249,7 @@ int snd_pcm_chmap_print(const snd_pcm_chmap_t *map, size_t maxlen, char *buf)
 						"%s", name);
 			else
 				len += snprintf(buf + len, maxlen - len,
-						"Ch%d", p);
+						"Ch%u", p);
 		}
 		if (len >= maxlen)
 			return -ENOMEM;
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
index 54d99005..719e1692 100644
--- a/src/pcm/pcm_direct.c
+++ b/src/pcm/pcm_direct.c
@@ -1406,7 +1406,7 @@ int snd_pcm_direct_initialize_poll_fd(snd_pcm_direct_t *dmix)
 		SNDERR("unable to info for slave pcm");
 		return ret;
 	}
-	sprintf(name, "hw:CLASS=%i,SCLASS=0,CARD=%i,DEV=%i,SUBDEV=%i",
+	sprintf(name, "hw:CLASS=%i,SCLASS=0,CARD=%i,DEV=%u,SUBDEV=%u",
 		(int)SND_TIMER_CLASS_PCM,
 		snd_pcm_info_get_card(&info),
 		snd_pcm_info_get_device(&info),
diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
index a02b2dc0..c874e863 100644
--- a/src/pcm/pcm_file.c
+++ b/src/pcm/pcm_file.c
@@ -155,7 +155,7 @@ static int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p)
 			 next char */
 			switch (*(++old_index_ch)) {
 			case RATE_KEY:
-				snprintf(value, sizeof(value), "%d",
+				snprintf(value, sizeof(value), "%u",
 						pcm->rate);
 				err = snd_pcm_file_append_value(&new_fname,
 					&new_index_ch, &new_len, value);
@@ -164,7 +164,7 @@ static int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p)
 				break;
 
 			case CHANNELS_KEY:
-				snprintf(value, sizeof(value), "%d",
+				snprintf(value, sizeof(value), "%u",
 						pcm->channels);
 				err = snd_pcm_file_append_value(&new_fname,
 					&new_index_ch, &new_len, value);
@@ -173,7 +173,7 @@ static int snd_pcm_file_replace_fname(snd_pcm_file_t *file, char **new_fname_p)
 				break;
 
 			case BWIDTH_KEY:
-				snprintf(value, sizeof(value), "%d",
+				snprintf(value, sizeof(value), "%u",
 					pcm->frame_bits/pcm->channels);
 				err = snd_pcm_file_append_value(&new_fname,
 						&new_index_ch, &new_len, value);
diff --git a/src/topology/builder.c b/src/topology/builder.c
index 5ae3ae89..3adbad45 100644
--- a/src/topology/builder.c
+++ b/src/topology/builder.c
@@ -21,6 +21,7 @@
 #include "tplg_local.h"
 
 /* verbose output detailing each object size and file position */
+__attribute__((format(printf, 2, 3)))
 static void verbose(snd_tplg_t *tplg, const char *fmt, ...)
 {
 	int offset;
@@ -244,7 +245,7 @@ static int write_manifest_data(snd_tplg_t *tplg)
 		return ret;
 	}
 
-	verbose(tplg, "manifest : write %d bytes\n", sizeof(tplg->manifest));
+	verbose(tplg, "manifest : write %zu bytes\n", sizeof(tplg->manifest));
 	ret = write(tplg->out_fd, &tplg->manifest, sizeof(tplg->manifest));
 	if (ret < 0) {
 		SNDERR("error: failed to write manifest %d\n", ret);
diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h
index ba961507..696a60dc 100644
--- a/src/ucm/ucm_local.h
+++ b/src/ucm/ucm_local.h
@@ -246,7 +246,9 @@ struct snd_use_case_mgr {
 #define uc_dbg(fmt, arg...) do { } while (0)
 #endif
 
+__attribute__((format(printf, 1, 2)))
 void uc_mgr_error(const char *fmt, ...);
+__attribute__((format(printf, 1, 2)))
 void uc_mgr_stdout(const char *fmt, ...);
 
 int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg);
-- 
2.23.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux