mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-26 19:40:24 +00:00
Fix pedantic warnings (#703)
* Fix warnings about incorrect format specifiers. GCC only wants to see void pointers for %p formatters, so cast as appropriate. * Fix a warning about an invalid enum value. The following warning was observed when compiling with -pedantic: warning: ISO C restricts enumerator values to range of 'int' (2147483648 is too large) The values of these enums don't escape wav_read_header() and are only used to set bits in a bitmask, so simply use the next bit rather than jumping to a huge number. * Give anonymous unions a name. This fixes the 'anonymous unions are a C11 extension' warning when compiling with -pedantic. * Use flexible array members rather than zero sized arrays. This flagged up the following warning when compiling with -pedantic: warning: zero size arrays are an extension [-Wzero-length-array] * Safely return the smallest value of a short. GCC gives the following warning when compiling with -pedantic: warning: overflow in conversion from 'int' to 'short int' changes value from '32768' to '-32768' [-Woverflow] This looks intentional from the surrounding code, so return -32768 in a legal way rather than depending on undefined behaviour. * Use the same min/max approach with all compilers. The GCC specific code gives the following warning from GCC when compiled with -pedantic: warning: ISO C forbids braced-groups within expressions [-pedantic] This code was also a fundamentally different way of calculating min/max since it didn't evaluate the inputs more than once, which meant there was potentially a difference in behaviour when the library was built with different compilers if the evaluation of 'a' or 'b' had side effects.
This commit is contained in:
parent
ecb9672aaa
commit
5ba69401c1
@ -267,14 +267,14 @@ db_check_all (REG_DB * db_handle)
|
||||
int
|
||||
db_list_all (REG_DB * db_handle)
|
||||
{
|
||||
printf ("%s : %p\n", __func__, db_handle) ;
|
||||
printf ("%s : %p\n", __func__, (void *) db_handle) ;
|
||||
return 0 ;
|
||||
} /* db_list_all */
|
||||
|
||||
int
|
||||
db_del_entry (REG_DB * db_handle, const char * entry)
|
||||
{
|
||||
printf ("%s : %p %s\n", __func__, db_handle, entry) ;
|
||||
printf ("%s : %p %s\n", __func__, (void *) db_handle, entry) ;
|
||||
return 0 ;
|
||||
} /* db_del_entry */
|
||||
|
||||
|
@ -48,7 +48,7 @@ typedef struct alac_decoder_s
|
||||
{
|
||||
int32_t mPredictor [ALAC_FRAME_LENGTH] ;
|
||||
uint16_t mShiftBuffer [ALAC_FRAME_LENGTH] ;
|
||||
} ;
|
||||
} u ;
|
||||
uint32_t mNumChannels ;
|
||||
} ALAC_DECODER ;
|
||||
|
||||
|
@ -110,7 +110,7 @@ alac_decoder_init (ALAC_DECODER *p, void * inMagicCookie, uint32_t inMagicCookie
|
||||
|
||||
RequireAction (p->mConfig.compatibleVersion <= kALACVersion, return kALAC_IncompatibleVersion ;) ;
|
||||
RequireAction ((p->mConfig.bitDepth >= 8 && p->mConfig.bitDepth <= 32), return kALAC_BadBitWidth ;) ;
|
||||
RequireAction ((p->mMixBufferU != NULL) && (p->mMixBufferV != NULL) && (p->mPredictor != NULL),
|
||||
RequireAction ((p->mMixBufferU != NULL) && (p->mMixBufferV != NULL) && (p->u.mPredictor != NULL),
|
||||
status = kALAC_MemFullError ; goto Exit ;) ;
|
||||
}
|
||||
else
|
||||
@ -247,18 +247,18 @@ alac_decode (ALAC_DECODER *p, struct BitBuffer * bits, int32_t * sampleBuffer, u
|
||||
|
||||
// decompress
|
||||
set_ag_params (&agParams, p->mConfig.mb, (pb * pbFactorU) / 4, p->mConfig.kb, numSamples, numSamples, p->mConfig.maxRun) ;
|
||||
status = dyn_decomp (&agParams, bits, p->mPredictor, numSamples, chanBits, &bits1) ;
|
||||
status = dyn_decomp (&agParams, bits, p->u.mPredictor, numSamples, chanBits, &bits1) ;
|
||||
RequireNoErr (status, goto Exit ;) ;
|
||||
|
||||
if (modeU == 0)
|
||||
{
|
||||
unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the special "numActive == 31" mode can be done in-place
|
||||
unpc_block (p->mPredictor, p->mPredictor, numSamples, NULL, 31, chanBits, 0) ;
|
||||
unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
unpc_block (p->u.mPredictor, p->u.mPredictor, numSamples, NULL, 31, chanBits, 0) ;
|
||||
unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -300,7 +300,7 @@ alac_decode (ALAC_DECODER *p, struct BitBuffer * bits, int32_t * sampleBuffer, u
|
||||
//Assert (shift <= 16) ;
|
||||
|
||||
for (i = 0 ; i < numSamples ; i++)
|
||||
p->mShiftBuffer [i] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
|
||||
p->u.mShiftBuffer [i] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
|
||||
}
|
||||
|
||||
// convert 32-bit integers into output buffer
|
||||
@ -318,14 +318,14 @@ alac_decode (ALAC_DECODER *p, struct BitBuffer * bits, int32_t * sampleBuffer, u
|
||||
case 24:
|
||||
out32 = sampleBuffer + channelIndex ;
|
||||
if (bytesShifted != 0)
|
||||
copyPredictorTo24Shift (p->mMixBufferU, p->mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
|
||||
copyPredictorTo24Shift (p->mMixBufferU, p->u.mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
|
||||
else
|
||||
copyPredictorTo24 (p->mMixBufferU, out32, numChannels, numSamples) ;
|
||||
break ;
|
||||
case 32:
|
||||
out32 = sampleBuffer + channelIndex ;
|
||||
if (bytesShifted != 0)
|
||||
copyPredictorTo32Shift (p->mMixBufferU, p->mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
|
||||
copyPredictorTo32Shift (p->mMixBufferU, p->u.mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
|
||||
else
|
||||
copyPredictorTo32 (p->mMixBufferU, out32, numChannels, numSamples) ;
|
||||
break ;
|
||||
@ -408,34 +408,34 @@ alac_decode (ALAC_DECODER *p, struct BitBuffer * bits, int32_t * sampleBuffer, u
|
||||
|
||||
// decompress and run predictor for "left" channel
|
||||
set_ag_params (&agParams, p->mConfig.mb, (pb * pbFactorU) / 4, p->mConfig.kb, numSamples, numSamples, p->mConfig.maxRun) ;
|
||||
status = dyn_decomp (&agParams, bits, p->mPredictor, numSamples, chanBits, &bits1) ;
|
||||
status = dyn_decomp (&agParams, bits, p->u.mPredictor, numSamples, chanBits, &bits1) ;
|
||||
RequireNoErr (status, goto Exit ;) ;
|
||||
|
||||
if (modeU == 0)
|
||||
{
|
||||
unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the special "numActive == 31" mode can be done in-place
|
||||
unpc_block (p->mPredictor, p->mPredictor, numSamples, NULL, 31, chanBits, 0) ;
|
||||
unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
unpc_block (p->u.mPredictor, p->u.mPredictor, numSamples, NULL, 31, chanBits, 0) ;
|
||||
unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
|
||||
}
|
||||
|
||||
// decompress and run predictor for "right" channel
|
||||
set_ag_params (&agParams, p->mConfig.mb, (pb * pbFactorV) / 4, p->mConfig.kb, numSamples, numSamples, p->mConfig.maxRun) ;
|
||||
status = dyn_decomp (&agParams, bits, p->mPredictor, numSamples, chanBits, &bits2) ;
|
||||
status = dyn_decomp (&agParams, bits, p->u.mPredictor, numSamples, chanBits, &bits2) ;
|
||||
RequireNoErr (status, goto Exit ;) ;
|
||||
|
||||
if (modeV == 0)
|
||||
{
|
||||
unpc_block (p->mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
|
||||
unpc_block (p->u.mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the special "numActive == 31" mode can be done in-place
|
||||
unpc_block (p->mPredictor, p->mPredictor, numSamples, NULL, 31, chanBits, 0) ;
|
||||
unpc_block (p->mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
|
||||
unpc_block (p->u.mPredictor, p->u.mPredictor, numSamples, NULL, 31, chanBits, 0) ;
|
||||
unpc_block (p->u.mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -488,8 +488,8 @@ alac_decode (ALAC_DECODER *p, struct BitBuffer * bits, int32_t * sampleBuffer, u
|
||||
|
||||
for (i = 0 ; i < (numSamples * 2) ; i += 2)
|
||||
{
|
||||
p->mShiftBuffer [i + 0] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
|
||||
p->mShiftBuffer [i + 1] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
|
||||
p->u.mShiftBuffer [i + 0] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
|
||||
p->u.mShiftBuffer [i + 1] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,12 +508,12 @@ alac_decode (ALAC_DECODER *p, struct BitBuffer * bits, int32_t * sampleBuffer, u
|
||||
case 24:
|
||||
out32 = sampleBuffer + channelIndex ;
|
||||
unmix24 (p->mMixBufferU, p->mMixBufferV, out32, numChannels, numSamples,
|
||||
mixBits, mixRes, p->mShiftBuffer, bytesShifted) ;
|
||||
mixBits, mixRes, p->u.mShiftBuffer, bytesShifted) ;
|
||||
break ;
|
||||
case 32:
|
||||
out32 = sampleBuffer + channelIndex ;
|
||||
unmix32 (p->mMixBufferU, p->mMixBufferV, out32, numChannels, numSamples,
|
||||
mixBits, mixRes, p->mShiftBuffer, bytesShifted) ;
|
||||
mixBits, mixRes, p->u.mShiftBuffer, bytesShifted) ;
|
||||
break ;
|
||||
}
|
||||
|
||||
|
18
src/alac.c
18
src/alac.c
@ -51,12 +51,12 @@ typedef struct
|
||||
|
||||
|
||||
/* Can't have a decoder and an encoder at the same time so stick
|
||||
** them in an un-named union.
|
||||
** them in a union.
|
||||
*/
|
||||
union
|
||||
{ ALAC_DECODER decoder ;
|
||||
ALAC_ENCODER encoder ;
|
||||
} ;
|
||||
} u ;
|
||||
|
||||
char enctmpname [512] ;
|
||||
FILE *enctmp ;
|
||||
@ -169,7 +169,7 @@ alac_close (SF_PRIVATE *psf)
|
||||
plac = psf->codec_data ;
|
||||
|
||||
if (psf->file.mode == SFM_WRITE)
|
||||
{ ALAC_ENCODER *penc = &plac->encoder ;
|
||||
{ ALAC_ENCODER *penc = &plac->u.encoder ;
|
||||
SF_CHUNK_INFO chunk_info ;
|
||||
sf_count_t readcount ;
|
||||
uint8_t kuki_data [1024] ;
|
||||
@ -268,14 +268,14 @@ alac_reader_init (SF_PRIVATE *psf, const ALAC_DECODER_INFO * info)
|
||||
/* Read in the ALAC cookie data and pass it to the init function. */
|
||||
kuki_size = alac_kuki_read (psf, info->kuki_offset, u.kuki, sizeof (u.kuki)) ;
|
||||
|
||||
if ((error = alac_decoder_init (&plac->decoder, u.kuki, kuki_size)) != ALAC_noErr)
|
||||
if ((error = alac_decoder_init (&plac->u.decoder, u.kuki, kuki_size)) != ALAC_noErr)
|
||||
{ psf_log_printf (psf, "*** alac_decoder_init() returned %s. ***\n", alac_error_string (error)) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
|
||||
if (plac->decoder.mNumChannels != (unsigned) psf->sf.channels)
|
||||
{ psf_log_printf (psf, "*** Initialized decoder has %u channels, but it should be %d. ***\n", plac->decoder.mNumChannels, psf->sf.channels) ;
|
||||
if (plac->u.decoder.mNumChannels != (unsigned) psf->sf.channels)
|
||||
{ psf_log_printf (psf, "*** Initialized decoder has %u channels, but it should be %d. ***\n", plac->u.decoder.mNumChannels, psf->sf.channels) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
@ -357,7 +357,7 @@ alac_writer_init (SF_PRIVATE *psf)
|
||||
return SFE_ALAC_FAIL_TMPFILE ;
|
||||
} ;
|
||||
|
||||
alac_encoder_init (&plac->encoder, psf->sf.samplerate, psf->sf.channels, alac_format_flags, ALAC_FRAME_LENGTH) ;
|
||||
alac_encoder_init (&plac->u.encoder, psf->sf.samplerate, psf->sf.channels, alac_format_flags, ALAC_FRAME_LENGTH) ;
|
||||
|
||||
return 0 ;
|
||||
} /* alac_writer_init */
|
||||
@ -402,7 +402,7 @@ alac_reader_calc_frames (SF_PRIVATE *psf, ALAC_PRIVATE *plac)
|
||||
|
||||
static int
|
||||
alac_decode_block (SF_PRIVATE *psf, ALAC_PRIVATE *plac)
|
||||
{ ALAC_DECODER *pdec = &plac->decoder ;
|
||||
{ ALAC_DECODER *pdec = &plac->u.decoder ;
|
||||
uint32_t packet_size ;
|
||||
BitBuffer bit_buffer ;
|
||||
|
||||
@ -437,7 +437,7 @@ alac_decode_block (SF_PRIVATE *psf, ALAC_PRIVATE *plac)
|
||||
|
||||
static int
|
||||
alac_encode_block (ALAC_PRIVATE *plac)
|
||||
{ ALAC_ENCODER *penc = &plac->encoder ;
|
||||
{ ALAC_ENCODER *penc = &plac->u.encoder ;
|
||||
uint32_t num_bytes = 0 ;
|
||||
|
||||
alac_encode (penc, plac->partial_block_frames, plac->buffer, plac->byte_buffer, &num_bytes) ;
|
||||
|
@ -1246,7 +1246,7 @@ psf_memset (void *s, int c, sf_count_t len)
|
||||
** bodgy something up instead.
|
||||
*/
|
||||
|
||||
typedef SF_CUES_VAR (0) SF_CUES_0 ;
|
||||
typedef SF_CUES_VAR () SF_CUES_0 ;
|
||||
|
||||
/* calculate size of SF_CUES struct given number of cues */
|
||||
#define SF_CUES_VAR_SIZE(count) (sizeof (SF_CUES_0) + count * sizeof (SF_CUE_POINT))
|
||||
@ -1625,7 +1625,7 @@ psf_f2s_clip_array (const float *src, short *dest, int count, int normalize)
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
|
||||
{ dest [count] = 0x8000 ;
|
||||
{ dest [count] = -0x7FFF - 1 ;
|
||||
continue ;
|
||||
} ;
|
||||
|
||||
@ -1659,7 +1659,7 @@ psf_d2s_clip_array (const double *src, short *dest, int count, int normalize)
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
|
||||
{ dest [count] = 0x8000 ;
|
||||
{ dest [count] = -0x7FFF - 1 ;
|
||||
continue ;
|
||||
} ;
|
||||
|
||||
|
14
src/common.h
14
src/common.h
@ -101,22 +101,8 @@
|
||||
|
||||
#define NOT(x) (! (x))
|
||||
|
||||
#if COMPILER_IS_GCC
|
||||
#define SF_MAX(x, y) ({ \
|
||||
typeof (x) sf_max_x1 = (x) ; \
|
||||
typeof (y) sf_max_y1 = (y) ; \
|
||||
(void) (&sf_max_x1 == &sf_max_y1) ; \
|
||||
sf_max_x1 > sf_max_y1 ? sf_max_x1 : sf_max_y1 ; })
|
||||
|
||||
#define SF_MIN(x, y) ({ \
|
||||
typeof (x) sf_min_x2 = (x) ; \
|
||||
typeof (y) sf_min_y2 = (y) ; \
|
||||
(void) (&sf_min_x2 == &sf_min_y2) ; \
|
||||
sf_min_x2 < sf_min_y2 ? sf_min_x2 : sf_min_y2 ; })
|
||||
#else
|
||||
#define SF_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define SF_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#define COMPILE_TIME_ASSERT(e) (sizeof (struct { int : - !! (e) ; }))
|
||||
|
@ -89,7 +89,7 @@ test_broadcast_var_set (void)
|
||||
static void
|
||||
test_broadcast_var_zero (void)
|
||||
{ SF_PRIVATE sf_private, *psf ;
|
||||
SF_BROADCAST_INFO_VAR (0) bi ;
|
||||
SF_BROADCAST_INFO_VAR () bi ;
|
||||
|
||||
psf = &sf_private ;
|
||||
memset (psf, 0, sizeof (sf_private)) ;
|
||||
|
14
src/wav.c
14
src/wav.c
@ -77,13 +77,13 @@
|
||||
|
||||
|
||||
enum
|
||||
{ HAVE_RIFF = 0x01,
|
||||
HAVE_WAVE = 0x02,
|
||||
HAVE_fmt = 0x04,
|
||||
HAVE_fact = 0x08,
|
||||
HAVE_PEAK = 0x10,
|
||||
HAVE_data = 0x20,
|
||||
HAVE_other = 0x80000000
|
||||
{ HAVE_RIFF = 1 << 0,
|
||||
HAVE_WAVE = 1 << 1,
|
||||
HAVE_fmt = 1 << 2,
|
||||
HAVE_fact = 1 << 3,
|
||||
HAVE_PEAK = 1 << 4,
|
||||
HAVE_data = 1 << 5,
|
||||
HAVE_other = 1 << 6
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -255,7 +255,7 @@ unrecognised_test (void)
|
||||
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
|
||||
exit_if_true (sndfile != NULL,
|
||||
"\n\nLine %d : SNDFILE* pointer (%p) should ne NULL.\n", __LINE__, sndfile
|
||||
"\n\nLine %d : SNDFILE* pointer (%p) should be NULL.\n", __LINE__, (void *) sndfile
|
||||
) ;
|
||||
|
||||
k = sf_error (sndfile) ;
|
||||
|
Loading…
Reference in New Issue
Block a user