alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH 1/3] treewide: Fix -Wformat=2 warnings
@ 2019-12-10  9:10 Rosen Penev
  2019-12-10  9:10 ` [alsa-devel] [PATCH 2/3] topology/builder: Fix absolute value warning Rosen Penev
  2019-12-10  9:10 ` [alsa-devel] [PATCH 3/3] treewide: Remove extra ; warning Rosen Penev
  0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2019-12-10  9:10 UTC (permalink / raw)
  To: alsa-devel

Allows the compiler to check these formats at compile time.

Fixed several such warnings.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 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@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [alsa-devel] [PATCH 2/3] topology/builder: Fix absolute value warning
  2019-12-10  9:10 [alsa-devel] [PATCH 1/3] treewide: Fix -Wformat=2 warnings Rosen Penev
@ 2019-12-10  9:10 ` Rosen Penev
  2019-12-10  9:10 ` [alsa-devel] [PATCH 3/3] treewide: Remove extra ; warning Rosen Penev
  1 sibling, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2019-12-10  9:10 UTC (permalink / raw)
  To: alsa-devel

next_hdr_pos is unsigned and promotes offset as such. This makes
the abs call useless.

Changed the abs call to labs and the offset to off_t to avoid this.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 src/topology/builder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/topology/builder.c b/src/topology/builder.c
index 3adbad45..98956dac 100644
--- a/src/topology/builder.c
+++ b/src/topology/builder.c
@@ -45,7 +45,7 @@ static int write_block_header(snd_tplg_t *tplg, unsigned int type,
 {
 	struct snd_soc_tplg_hdr hdr;
 	size_t bytes;
-	int offset = lseek(tplg->out_fd, 0, SEEK_CUR);
+	off_t offset = lseek(tplg->out_fd, 0, SEEK_CUR);
 
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.magic = SND_SOC_TPLG_MAGIC;
@@ -64,7 +64,7 @@ static int write_block_header(snd_tplg_t *tplg, unsigned int type,
 			" offset 0x%x is %s by %d bytes\n",
 			tplg->next_hdr_pos, offset,
 			(unsigned int)offset > tplg->next_hdr_pos ? "ahead" : "behind",
-			abs(offset - tplg->next_hdr_pos));
+			labs(offset - (off_t)tplg->next_hdr_pos));
 		exit(-EINVAL);
 	}
 
-- 
2.23.0

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [alsa-devel] [PATCH 3/3] treewide: Remove extra ; warning
  2019-12-10  9:10 [alsa-devel] [PATCH 1/3] treewide: Fix -Wformat=2 warnings Rosen Penev
  2019-12-10  9:10 ` [alsa-devel] [PATCH 2/3] topology/builder: Fix absolute value warning Rosen Penev
@ 2019-12-10  9:10 ` Rosen Penev
  1 sibling, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2019-12-10  9:10 UTC (permalink / raw)
  To: alsa-devel

Enclosed defines in a do/while loop to silence this.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 src/conf.c            | 20 ++++++++++----------
 src/mixer/simple.c    | 16 ++++++++--------
 src/topology/parser.c |  2 +-
 src/ucm/ucm_subs.c    | 10 ++++++----
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/conf.c b/src/conf.c
index e4306504..c26999b0 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -3062,7 +3062,7 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
 #ifndef DOC_HIDDEN
 
 #define SND_CONFIG_SEARCH(config, key, result, extra_code) \
-{ \
+do { \
 	snd_config_t *n; \
 	int err; \
 	const char *p; \
@@ -3081,10 +3081,10 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
 		} else \
 			return _snd_config_search(config, key, -1, result); \
 	} \
-}
+} while(0)
 
 #define SND_CONFIG_SEARCHA(root, config, key, result, fcn, extra_code) \
-{ \
+do { \
 	snd_config_t *n; \
 	int err; \
 	const char *p; \
@@ -3108,10 +3108,10 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
 		} else \
 			return _snd_config_search(config, key, -1, result); \
 	} \
-}
+} while(0)
 
 #define SND_CONFIG_SEARCHV(config, result, fcn) \
-{ \
+do { \
 	snd_config_t *n; \
 	va_list arg; \
 	assert(config); \
@@ -3132,10 +3132,10 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
 	if (result) \
 		*result = n; \
 	return 0; \
-}
+} while(0)
 
 #define SND_CONFIG_SEARCHVA(root, config, result, fcn) \
-{ \
+do { \
 	snd_config_t *n; \
 	va_list arg; \
 	assert(config); \
@@ -3156,10 +3156,10 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
 	if (result) \
 		*result = n; \
 	return 0; \
-}
+} while(0)
 
 #define SND_CONFIG_SEARCH_ALIAS(config, base, key, result, fcn1, fcn2) \
-{ \
+do { \
 	snd_config_t *res = NULL; \
 	char *old_key; \
 	int err, first = 1, maxloop = 1000; \
@@ -3201,7 +3201,7 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
 	if (result) \
 		*result = res; \
 	return 0; \
-}
+} while(0)
 
 #endif /* DOC_HIDDEN */
 
diff --git a/src/mixer/simple.c b/src/mixer/simple.c
index 2861d97c..2b9daa6e 100644
--- a/src/mixer/simple.c
+++ b/src/mixer/simple.c
@@ -82,30 +82,30 @@ int snd_mixer_selem_register(snd_mixer_t *mixer,
 #ifndef DOC_HIDDEN
 
 #define CHECK_BASIC(xelem) \
-{ \
+do { \
 	assert(xelem); \
 	assert((xelem)->type == SND_MIXER_ELEM_SIMPLE); \
-}
+} while(0)
 
 #define CHECK_DIR(xelem, xwhat) \
-{ \
+do { \
 	unsigned int xcaps = ((sm_selem_t *)(elem)->private_data)->caps; \
 	if (! (xcaps & (xwhat))) \
 		return -EINVAL; \
-}
+} while(0)
 
 #define CHECK_DIR_CHN(xelem, xwhat, xjoin, xchannel) \
-{ \
+do { \
 	unsigned int xcaps = ((sm_selem_t *)(elem)->private_data)->caps; \
 	if (! (xcaps & (xwhat))) \
 		return -EINVAL; \
 	if (xcaps & (xjoin)) \
 		xchannel = 0; \
-}
+} while(0)
 
-#define CHECK_ENUM(xelem) \
+#define CHECK_ENUM(xelem) do { \
 	if (!(((sm_selem_t *)(elem)->private_data)->caps & (SM_CAP_PENUM|SM_CAP_CENUM))) \
-		return -EINVAL;
+		return -EINVAL; } while(0)
 
 #define COND_CAPS(xelem, what) \
 	!!(((sm_selem_t *)(elem)->private_data)->caps & (what))
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 5940692d..473a65e6 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -382,7 +382,7 @@ int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
 	default:
 		SNDERR("error: invalid object type %d\n", t->type);
 		return -EINVAL;
-	};
+	}
 }
 
 int snd_tplg_build(snd_tplg_t *tplg, const char *outfile)
diff --git a/src/ucm/ucm_subs.c b/src/ucm/ucm_subs.c
index 90e395f0..5d5fd64e 100644
--- a/src/ucm/ucm_subs.c
+++ b/src/ucm/ucm_subs.c
@@ -146,15 +146,16 @@ static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char
 	return strdup(path);
 }
 
-#define MATCH_VARIABLE(name, id, fcn, empty_ok)				\
+#define MATCH_VARIABLE(name, id, fcn, empty_ok)	do {			\
 	if (strncmp((name), (id), sizeof(id) - 1) == 0) { 		\
 		rval = fcn(uc_mgr);					\
 		idsize = sizeof(id) - 1;				\
 		allow_empty = (empty_ok);				\
 		goto __rval;						\
-	}
+	}								\
+} while(0)
 
-#define MATCH_VARIABLE2(name, id, fcn)					\
+#define MATCH_VARIABLE2(name, id, fcn) do {				\
 	if (strncmp((name), (id), sizeof(id) - 1) == 0) {		\
 		idsize = sizeof(id) - 1;				\
 		tmp = strchr(value + idsize, '}');			\
@@ -170,7 +171,8 @@ static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char
 			rval = fcn(uc_mgr, v2);				\
 			goto __rval;					\
 		}							\
-	}
+	}								\
+} while(0)
 
 int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr,
 				 char **_rvalue,
-- 
2.23.0

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-10  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10  9:10 [alsa-devel] [PATCH 1/3] treewide: Fix -Wformat=2 warnings Rosen Penev
2019-12-10  9:10 ` [alsa-devel] [PATCH 2/3] topology/builder: Fix absolute value warning Rosen Penev
2019-12-10  9:10 ` [alsa-devel] [PATCH 3/3] treewide: Remove extra ; warning Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).