treewide: Fix -Wformat=2 warnings
PATCH 1/3 treewide: Fix -Wformat=2 warnings
Allows the compiler to check these formats at compile time.
Fixed several such warnings.
Signed-off-by Rosen Penev <[email protected]>
--- 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(-)
include/use-case.h +1 -0
@@ -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, ...);/**
src/error.c +2 -0
@@ -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;
src/input.c +4 -2
@@ -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;
src/output.c +4 -2
@@ -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;
src/pcm/pcm.c +2 -2
@@ -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 ;
src/pcm/pcm_direct.c +1 -1
@@ -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),
src/pcm/pcm_file.c +3 -3
@@ -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);
src/topology/builder.c +2 -1
@@ -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);
src/ucm/ucm_local.h +2 -0
@@ -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);
Signature · 6 lines
2.23.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 2/3 topology/builder: Fix absolute value warning
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 <[email protected]>
--- src/topology/builder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/topology/builder.c +2 -2
@@ -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 ); }
Signature · 6 lines
2.23.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 3/3 treewide: Remove extra ; warning
In reply to Rosen PenevEnclosed defines in a do/while loop to silence this.
Signed-off-by Rosen Penev <[email protected]>
--- 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(-)
src/conf.c +10 -10
@@ -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 */
src/mixer/simple.c +8 -8
@@ -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))
src/topology/parser.c +1 -1
@@ -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)
src/ucm/ucm_subs.c +6 -4
@@ -146,15 +146,16 @@ static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const charreturn 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,
Signature · 6 lines
2.23.0 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel