Skip to content

Commit 431c97a

Browse files
committed
fix all GCC -Wall, -Wextra, -Wpedantic and -D_FORTIFY_SOURCE=2 warnings
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
1 parent 91dd136 commit 431c97a

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

audio.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ int aiff_id(unsigned char *buf, int len)
509509
return 1;
510510
}
511511

512-
int aiff_open(FILE *in, wavegain_opt *opt, unsigned char *buf, int buflen)
512+
int aiff_open(FILE *in, wavegain_opt *opt, unsigned char *buf,
513+
int buflen __attribute__((unused)))
513514
{
514515
int aifc; /* AIFC or AIFF? */
515516
unsigned int len;
@@ -636,7 +637,9 @@ int wav_id(unsigned char *buf, int len)
636637
return 1;
637638
}
638639

639-
int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
640+
int wav_open(FILE *in, wavegain_opt *opt,
641+
unsigned char *oldbuf __attribute__((unused)),
642+
int buflen __attribute__((unused)))
640643
{
641644
unsigned char buf[81];
642645
Int64_t len;
@@ -692,9 +695,10 @@ int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
692695
if (!find_gain_chunk(in, &len))
693696
FSEEK64(in, current_pos, SEEK_SET);
694697
else {
695-
char buf_double[8];
698+
unsigned char buf_double[8];
696699
opt->gain_chunk = 1;
697-
fread(buf_double, 1, 8, in);
700+
if (fread(buf_double, 1, 8, in) < 8)
701+
fprintf(stderr, "Warning: Failed to read WAV gain chunk\n");
698702
opt->gain_scale = READ_D64(buf_double);
699703
}
700704
}
@@ -712,7 +716,8 @@ int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
712716
fprintf(stderr, "Error: unable to allocate memory for header\n");
713717
else {
714718
opt->header_size = current_pos;
715-
fread(opt->header, 1, opt->header_size, in);
719+
if (fread(opt->header, 1, opt->header_size, in) < (size_t)opt->header_size)
720+
fprintf(stderr, "Warning: Failed to read WAV header when applying gain\n");
716721
}
717722
FSEEK64(in, current_pos, SEEK_SET);
718723
}
@@ -1065,7 +1070,8 @@ void close_audio_file( FILE *in, audio_file *aufile, wavegain_opt *opt)
10651070
FSEEK64 (in, current_pos_t, SEEK_SET);
10661071
ch = malloc (sizeof(char) * (pos - current_pos_t));
10671072

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

10711077
if (ch)

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const char* ftos(double f, const char* format)
158158
* \return 0 if successful and -1 if an error occured (in which case a
159159
* message has been printed).
160160
*/
161-
int process_files(FILE_LIST* file_list, SETTINGS* settings, const char* dir)
161+
int process_files(FILE_LIST* file_list, SETTINGS* settings, const char* dir __attribute__((unused)))
162162
{
163163
FILE_LIST* file;
164164
double factor_clip,

recurse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int contains_pattern(const char* string)
9696
case '\\':
9797
/* Accept a terminating \ as a literal \ */
9898
if (string[1])
99-
string++;
99+
string++; // @suppress("No break at end of case")
100100
/* Fall through */
101101

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

175175
default:

wavegain.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ int get_gain(const char *filename, double *track_peak, double *track_gain,
381381
* If audiophile_gain is selected, that value is used, otherwise the
382382
* radio_gain value is used.
383383
*/
384-
int write_gains(const char *filename, double radio_gain, double audiophile_gain, double TitlePeak,
384+
int write_gains(const char *filename, double radio_gain, double audiophile_gain,
385+
double TitlePeak __attribute__((unused)),
385386
double *dc_offset, double *album_dc_offset, SETTINGS *settings)
386387
{
387388
wavegain_opt *wg_opts = malloc(sizeof(wavegain_opt));
@@ -393,8 +394,8 @@ int write_gains(const char *filename, double radio_gain, double audiophile_gain,
393394
double Gain;
394395
double scale;
395396
double total_read = 0.;
396-
double wrap_prev_pos;
397-
double wrap_prev_neg;
397+
double wrap_prev_pos = 0;
398+
double wrap_prev_neg = 0;
398399
void *sample_buffer;
399400
input_format *format;
400401

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

0 commit comments

Comments
 (0)