Skip to content

Commit

Permalink
fix all GCC -Wall, -Wextra, -Wpedantic and -D_FORTIFY_SOURCE=2 warnings
Browse files Browse the repository at this point in the history
Approach used to fix each error type is as follows:

warning: unused parameter ‘x’ [-Wunused-parameter]
- add `__attribute__((unused))` to parameter signature in .c file (but not on its .h counterpart)

warning: ignoring return value of ‘f’, declared with attribute warn_unused_result [-Wunused-result]
- wrap function call in an `if (f(...) ...)` with appopriate error test condition, followed by an
  `fprintf(stderr, "Warning: ...\n")` with some informative error message

warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
- initialize the variable in its declaration with a dummy value such as 0

warning: pointer targets in passing argument 1 of ‘read_d64_le’ differ in signedness [-Wpointer-sign]
- change passed argument type to match signedness. Luckly the argument exists solely for that function call
  • Loading branch information
MestreLion committed Jul 5, 2020
1 parent eb1e488 commit 934e66b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
18 changes: 12 additions & 6 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ int aiff_id(unsigned char *buf, int len)
return 1;
}

int aiff_open(FILE *in, wavegain_opt *opt, unsigned char *buf, int buflen)
int aiff_open(FILE *in, wavegain_opt *opt, unsigned char *buf,
int buflen __attribute__((unused)))
{
int aifc; /* AIFC or AIFF? */
unsigned int len;
Expand Down Expand Up @@ -636,7 +637,9 @@ int wav_id(unsigned char *buf, int len)
return 1;
}

int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
int wav_open(FILE *in, wavegain_opt *opt,
unsigned char *oldbuf __attribute__((unused)),
int buflen __attribute__((unused)))
{
unsigned char buf[81];
Int64_t len;
Expand Down Expand Up @@ -692,9 +695,10 @@ int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
if (!find_gain_chunk(in, &len))
FSEEK64(in, current_pos, SEEK_SET);
else {
char buf_double[8];
unsigned char buf_double[8];
opt->gain_chunk = 1;
fread(buf_double, 1, 8, in);
if (fread(buf_double, 1, 8, in) < 8)
fprintf(stderr, "Warning: Failed to read WAV gain chunk\n");
opt->gain_scale = READ_D64(buf_double);
}
}
Expand All @@ -712,7 +716,8 @@ int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
fprintf(stderr, "Error: unable to allocate memory for header\n");
else {
opt->header_size = current_pos;
fread(opt->header, 1, opt->header_size, in);
if (fread(opt->header, 1, opt->header_size, in) < (size_t)opt->header_size)
fprintf(stderr, "Warning: Failed to read WAV header when applying gain\n");
}
FSEEK64(in, current_pos, SEEK_SET);
}
Expand Down Expand Up @@ -1065,7 +1070,8 @@ void close_audio_file( FILE *in, audio_file *aufile, wavegain_opt *opt)
FSEEK64 (in, current_pos_t, SEEK_SET);
ch = malloc (sizeof(char) * (pos - current_pos_t));

fread (ch, 1, pos - current_pos_t, in);
if (fread (ch, 1, pos - current_pos_t, in) < (pos - current_pos_t))
fprintf(stderr, "Warning: Failed to read input audio file when closing output file\n");
fwrite (ch, pos - current_pos_t, 1, aufile->sndfile);

if (ch)
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const char* ftos(double f, const char* format)
* \return 0 if successful and -1 if an error occured (in which case a
* message has been printed).
*/
int process_files(FILE_LIST* file_list, SETTINGS* settings, const char* dir)
int process_files(FILE_LIST* file_list, SETTINGS* settings, const char* dir __attribute__((unused)))
{
FILE_LIST* file;
double factor_clip,
Expand Down
4 changes: 2 additions & 2 deletions recurse.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int contains_pattern(const char* string)
case '\\':
/* Accept a terminating \ as a literal \ */
if (string[1])
string++;
string++; // @suppress("No break at end of case")
/* Fall through */

default:
Expand Down Expand Up @@ -169,7 +169,7 @@ static int match(const char* pattern, const char* text)
case '\\':
/* Accept a terminating \ as a literal \ */
if (pattern[1])
++pattern;
++pattern; // @suppress("No break at end of case")
/* Fall through */

default:
Expand Down
18 changes: 13 additions & 5 deletions wavegain.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ int get_gain(const char *filename, double *track_peak, double *track_gain,
* If audiophile_gain is selected, that value is used, otherwise the
* radio_gain value is used.
*/
int write_gains(const char *filename, double radio_gain, double audiophile_gain, double TitlePeak,
int write_gains(const char *filename, double radio_gain, double audiophile_gain,
double TitlePeak __attribute__((unused)),
double *dc_offset, double *album_dc_offset, SETTINGS *settings)
{
wavegain_opt *wg_opts = malloc(sizeof(wavegain_opt));
Expand All @@ -393,8 +394,8 @@ int write_gains(const char *filename, double radio_gain, double audiophile_gain,
double Gain;
double scale;
double total_read = 0.;
double wrap_prev_pos;
double wrap_prev_neg;
double wrap_prev_pos = 0;
double wrap_prev_neg = 0;
void *sample_buffer;
input_format *format;

Expand Down Expand Up @@ -674,9 +675,16 @@ int write_gains(const char *filename, double radio_gain, double audiophile_gain,
#endif
#ifndef _WIN32
/* copy owner, group, permissions from original to output */
/* TODO: add -p|--preserve=[=ATTR_LIST] (see `man cp`) and only copy
* attributes if enabled. Silently ignore errors on EPERM
*/
stat(filename, &fst);
chown(tempName, fst.st_uid, -1);
chown(tempName, -1 ,fst.st_gid);
if (
/* FIXME: Could/Should both calls be perfomed in a single step? */
chown(tempName, fst.st_uid, -1) != 0 ||
chown(tempName, -1 ,fst.st_gid) != 0
)
fprintf(stderr, "Warning: could not change file owner: %s (%s)\n", tempName, filename);
chmod(tempName, fst.st_mode);
#endif
if (rename(tempName, filename) != 0) {
Expand Down

0 comments on commit 934e66b

Please sign in to comment.