diff --git a/audio.c b/audio.c index 8390145..eace2dd 100644 --- a/audio.c +++ b/audio.c @@ -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; @@ -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; @@ -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); } } @@ -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); } @@ -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) diff --git a/main.c b/main.c index 6104c97..5909876 100644 --- a/main.c +++ b/main.c @@ -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, diff --git a/recurse.c b/recurse.c index c7f6367..1e28fdd 100644 --- a/recurse.c +++ b/recurse.c @@ -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: @@ -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: diff --git a/wavegain.c b/wavegain.c index 8014b79..bd053e8 100644 --- a/wavegain.c +++ b/wavegain.c @@ -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)); @@ -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; @@ -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) {