]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/lzo.c
configure: Drop weak dependencies on external libraries for webm muxer
[ffmpeg] / libavutil / lzo.c
index c17d32f3625dc488d037073d6e28f03eec58040e..e458165261dbeef2736c3a378a96bbf21cecd52d 100644 (file)
@@ -80,6 +80,10 @@ static inline void copy(LZOContext *c, int cnt)
 {
     register const uint8_t *src = c->in;
     register uint8_t *dst       = c->out;
+    if (cnt < 0) {
+        c->error |= AV_LZO_ERROR;
+        return;
+    }
     if (cnt > c->in_end - src) {
         cnt       = FFMAX(c->in_end - src, 0);
         c->error |= AV_LZO_INPUT_DEPLETED;
@@ -100,21 +104,22 @@ static inline void copy(LZOContext *c, int cnt)
     c->out = dst + cnt;
 }
 
-static inline void memcpy_backptr(uint8_t *dst, int back, int cnt);
-
 /**
  * @brief Copies previously decoded bytes to current position.
  * @param back how many bytes back we start
- * @param cnt number of bytes to copy, must be >= 0
+ * @param cnt number of bytes to copy, must be > 0
  *
  * cnt > back is valid, this will copy the bytes we just copied,
  * thus creating a repeating pattern with a period length of back.
  */
 static inline void copy_backptr(LZOContext *c, int back, int cnt)
 {
-    register const uint8_t *src = &c->out[-back];
     register uint8_t *dst       = c->out;
-    if (src < c->out_start || src > dst) {
+    if (cnt <= 0) {
+        c->error |= AV_LZO_ERROR;
+        return;
+    }
+    if (dst - c->out_start < back) {
         c->error |= AV_LZO_INVALID_BACKPTR;
         return;
     }
@@ -122,50 +127,10 @@ static inline void copy_backptr(LZOContext *c, int back, int cnt)
         cnt       = FFMAX(c->out_end - dst, 0);
         c->error |= AV_LZO_OUTPUT_FULL;
     }
-    memcpy_backptr(dst, back, cnt);
+    av_memcpy_backptr(dst, back, cnt);
     c->out = dst + cnt;
 }
 
-static inline void memcpy_backptr(uint8_t *dst, int back, int cnt)
-{
-    const uint8_t *src = &dst[-back];
-    if (back == 1) {
-        memset(dst, *src, cnt);
-    } else {
-        if (cnt >= 4) {
-            AV_COPY16U(dst,     src);
-            AV_COPY16U(dst + 2, src + 2);
-            src += 4;
-            dst += 4;
-            cnt -= 4;
-        }
-        if (cnt >= 8) {
-            AV_COPY16U(dst,     src);
-            AV_COPY16U(dst + 2, src + 2);
-            AV_COPY16U(dst + 4, src + 4);
-            AV_COPY16U(dst + 6, src + 6);
-            src += 8;
-            dst += 8;
-            cnt -= 8;
-        }
-        if (cnt > 0) {
-            int blocklen = back;
-            while (cnt > blocklen) {
-                memcpy(dst, src, blocklen);
-                dst       += blocklen;
-                cnt       -= blocklen;
-                blocklen <<= 1;
-            }
-            memcpy(dst, src, cnt);
-        }
-    }
-}
-
-void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
-{
-    memcpy_backptr(dst, back, cnt);
-}
-
 int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen)
 {
     int state = 0;