mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 01:49:53 +00:00
ALAC/ : Replace all un-aligned accesses with safe alternatives.
This commit is contained in:
parent
3c812eb4b3
commit
34f1fe1c12
@ -4,9 +4,12 @@
|
||||
Add tests for psf_put_be32() and psf_put_be64().
|
||||
|
||||
* src/sfendian.h src/test_endswap.(def|tpl)
|
||||
Add functions psf_get_be32() and psf_gett_be64() with tests.
|
||||
Add functions psf_get_be(16|32|64) with tests.
|
||||
These are needed for platforms where un-aligned accesses cause bus faults.
|
||||
|
||||
* src/ALAC/ag_enc.c src/ALAC/alac_decoder.c
|
||||
Replace all un-aligned accesses with safe alternatives.
|
||||
|
||||
2013-02-12 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/sfendian.h
|
||||
|
@ -180,16 +180,13 @@ codeasescape:
|
||||
|
||||
static inline void ALWAYS_INLINE dyn_jam_noDeref(unsigned char *out, uint32_t bitPos, uint32_t numBits, uint32_t value)
|
||||
{
|
||||
/* FIXME: Cast-align warning when compiling on armhf. */
|
||||
uint32_t *i = (uint32_t *)(out + (bitPos >> 3));
|
||||
uint32_t mask;
|
||||
uint32_t curr;
|
||||
uint32_t shift;
|
||||
|
||||
//Assert( numBits <= 32 );
|
||||
|
||||
curr = *i;
|
||||
curr = Swap32NtoB( curr );
|
||||
curr = psf_get_be32 (out, bitPos >> 3);
|
||||
|
||||
shift = 32 - (bitPos & 7) - numBits;
|
||||
|
||||
@ -199,23 +196,20 @@ static inline void ALWAYS_INLINE dyn_jam_noDeref(unsigned char *out, uint32_t bi
|
||||
value = (value << shift) & mask;
|
||||
value |= curr & ~mask;
|
||||
|
||||
*i = Swap32BtoN( value );
|
||||
psf_put_be32 (out, bitPos >> 3, value) ;
|
||||
}
|
||||
|
||||
|
||||
static inline void ALWAYS_INLINE dyn_jam_noDeref_large(unsigned char *out, uint32_t bitPos, uint32_t numBits, uint32_t value)
|
||||
{
|
||||
/* FIXME: Cast-align warning when compiling on armhf. */
|
||||
uint32_t * i = (uint32_t *)(out + (bitPos>>3));
|
||||
uint32_t w;
|
||||
uint32_t curr;
|
||||
uint32_t mask;
|
||||
int32_t shiftvalue = (32 - (bitPos&7) - numBits);
|
||||
int32_t shiftvalue = (32 - (bitPos&7) - numBits);
|
||||
|
||||
//Assert(numBits <= 32);
|
||||
|
||||
curr = *i;
|
||||
curr = Swap32NtoB( curr );
|
||||
curr = psf_get_be32 (out, bitPos >> 3);
|
||||
|
||||
if (shiftvalue < 0)
|
||||
{
|
||||
@ -226,7 +220,7 @@ static inline void ALWAYS_INLINE dyn_jam_noDeref_large(unsigned char *out, uint3
|
||||
mask = ~0u >> -shiftvalue;
|
||||
w |= (curr & ~mask);
|
||||
|
||||
tailptr = ((uint8_t *)i) + 4;
|
||||
tailptr = out + (bitPos>>3) + 4;
|
||||
tailbyte = (value << ((8+shiftvalue))) & 0xff;
|
||||
*tailptr = (uint8_t)tailbyte;
|
||||
}
|
||||
@ -239,7 +233,7 @@ static inline void ALWAYS_INLINE dyn_jam_noDeref_large(unsigned char *out, uint3
|
||||
w |= curr & ~mask;
|
||||
}
|
||||
|
||||
*i = Swap32BtoN( w );
|
||||
psf_put_be32 (out, bitPos >> 3, w) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alac_codec.h"
|
||||
@ -87,21 +88,21 @@ alac_decoder_init (ALAC_DECODER *p, void * inMagicCookie, uint32_t inMagicCookie
|
||||
if (theCookieBytesRemaining >= sizeof(ALACSpecificConfig))
|
||||
{
|
||||
/* FIXME: Cast-align warning when compiling on armhf. */
|
||||
theConfig.frameLength = Swap32BtoN(((ALACSpecificConfig *)theActualCookie)->frameLength);
|
||||
theConfig.frameLength = psf_get_be32 (theActualCookie, offsetof (ALACSpecificConfig, frameLength)) ;
|
||||
|
||||
if (theConfig.frameLength > ALAC_FRAME_LENGTH)
|
||||
return fALAC_FrameLengthError ;
|
||||
|
||||
theConfig.compatibleVersion = ((ALACSpecificConfig *)theActualCookie)->compatibleVersion;
|
||||
theConfig.bitDepth = ((ALACSpecificConfig *)theActualCookie)->bitDepth;
|
||||
theConfig.pb = ((ALACSpecificConfig *)theActualCookie)->pb;
|
||||
theConfig.mb = ((ALACSpecificConfig *)theActualCookie)->mb;
|
||||
theConfig.kb = ((ALACSpecificConfig *)theActualCookie)->kb;
|
||||
theConfig.numChannels = ((ALACSpecificConfig *)theActualCookie)->numChannels;
|
||||
theConfig.maxRun = Swap16BtoN(((ALACSpecificConfig *)theActualCookie)->maxRun);
|
||||
theConfig.maxFrameBytes = Swap32BtoN(((ALACSpecificConfig *)theActualCookie)->maxFrameBytes);
|
||||
theConfig.avgBitRate = Swap32BtoN(((ALACSpecificConfig *)theActualCookie)->avgBitRate);
|
||||
theConfig.sampleRate = Swap32BtoN(((ALACSpecificConfig *)theActualCookie)->sampleRate);
|
||||
theConfig.compatibleVersion = theActualCookie [offsetof (ALACSpecificConfig, compatibleVersion)] ;
|
||||
theConfig.bitDepth = theActualCookie [offsetof (ALACSpecificConfig, bitDepth)] ;
|
||||
theConfig.pb = theActualCookie [offsetof (ALACSpecificConfig, pb)] ;
|
||||
theConfig.mb = theActualCookie [offsetof (ALACSpecificConfig, mb)] ;
|
||||
theConfig.kb = theActualCookie [offsetof (ALACSpecificConfig, kb)] ;
|
||||
theConfig.numChannels = theActualCookie [offsetof (ALACSpecificConfig, numChannels)] ;
|
||||
theConfig.maxRun = psf_get_be16 (theActualCookie, offsetof (ALACSpecificConfig, maxRun)) ;
|
||||
theConfig.maxFrameBytes = psf_get_be32 (theActualCookie, offsetof (ALACSpecificConfig, maxFrameBytes)) ;
|
||||
theConfig.avgBitRate = psf_get_be32 (theActualCookie, offsetof (ALACSpecificConfig, avgBitRate)) ;
|
||||
theConfig.sampleRate = psf_get_be32 (theActualCookie, offsetof (ALACSpecificConfig, sampleRate)) ;
|
||||
|
||||
p->mConfig = theConfig;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user