#include <malloc.h>
#endif
+#include "avassert.h"
#include "avutil.h"
#include "intreadwrite.h"
#include "mem.h"
if (!ptr)
return av_malloc(size);
diff = ((char *)ptr)[-1];
+ av_assert0(diff>0 && diff<=ALIGN);
ptr = realloc((char *)ptr - diff, size + diff);
if (ptr)
ptr = (char *)ptr + diff;
void av_free(void *ptr)
{
#if CONFIG_MEMALIGN_HACK
- if (ptr)
- free((char *)ptr - ((char *)ptr)[-1]);
+ if (ptr) {
+ int v= ((char *)ptr)[-1];
+ av_assert0(v>0 && v<=ALIGN);
+ free((char *)ptr - v);
+ }
#elif HAVE_ALIGNED_MALLOC
_aligned_free(ptr);
#else
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
{
const uint8_t *src = &dst[-back];
- if (back <= 1) {
+ if (!back)
+ return;
+
+ if (back == 1) {
memset(dst, *src, cnt);
} else if (back == 2) {
fill16(dst, cnt);