shithub: dav1d

Download patch

ref: 3cf4d32e74e38b99036c21b7d2d0fb2108223221
parent: 0d18b15aa084d180aa41f3c4b2cff7bf8cb68fdc
author: Henrik Gramner <gramner@twoorioles.com>
date: Mon Feb 11 14:53:01 EST 2019

Use 64-bit versions of fseek and ftell

--- a/meson.build
+++ b/meson.build
@@ -89,6 +89,12 @@
     cdata.set('UNICODE',                1) # Define to 1 for Unicode (Wide Chars) APIs
     cdata.set('_UNICODE',               1) # Define to 1 for Unicode (Wide Chars) APIs
     cdata.set('__USE_MINGW_ANSI_STDIO', 1) # Define to force use of MinGW printf
+    if cc.has_function('fseeko', prefix : '#include <stdio.h>', args : test_args)
+        cdata.set('_FILE_OFFSET_BITS', 64) # Not set by default by Meson on Windows
+    else
+        cdata.set('fseeko', '_fseeki64')
+        cdata.set('ftello', '_ftelli64')
+    endif
 endif
 
 # On Windows, we use a compatibility layer to emulate pthread
--- a/src/arm/cpu.c
+++ b/src/arm/cpu.c
@@ -62,7 +62,7 @@
         // if line is incomplete seek back to avoid splitting the search
         // string into two buffers
         if (!strchr(line, '\n') && strlen(line) > strlen(flag)) {
-            if (fseek(file, -strlen(flag), SEEK_CUR))
+            if (fseeko(file, -strlen(flag), SEEK_CUR))
                 break;
         }
     }
--- a/tests/libfuzzer/main.c
+++ b/tests/libfuzzer/main.c
@@ -25,7 +25,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "config.h"
+
 #include <errno.h>
+#include <inttypes.h>
 #include <limits.h>
 #include <stddef.h>
 #include <stdint.h>
@@ -40,7 +43,7 @@
 int main(const int argc, char *const *const argv) {
     int ret = -1;
     FILE *f = NULL;
-    long fsize;
+    int64_t fsize;
     const char *filename = NULL;
     uint8_t *data = NULL;
     size_t size = 0;
@@ -56,12 +59,12 @@
         goto error;
     }
 
-    if (fseek(f, 0L, SEEK_END) == -1) {
+    if (fseeko(f, 0, SEEK_END) == -1) {
         fprintf(stderr, "fseek(%s, 0, SEEK_END) failed: %s\n", filename,
                 strerror(errno));
         goto error;
     }
-    if ((fsize = ftell(f)) == -1) {
+    if ((fsize = ftello(f)) == -1) {
         fprintf(stderr, "ftell(%s) failed: %s\n", filename, strerror(errno));
         goto error;
     }
@@ -68,10 +71,10 @@
     rewind(f);
 
     if (fsize < 0 || fsize > INT_MAX) {
-        fprintf(stderr, "%s is too large: %ld\n", filename, fsize);
+        fprintf(stderr, "%s is too large: %"PRId64"\n", filename, fsize);
         goto error;
     }
-    size = fsize;
+    size = (size_t)fsize;
 
     if (!(data = malloc(size))) {
         fprintf(stderr, "failed to allocate: %zu bytes\n", size);
--- a/tools/input/annexb.c
+++ b/tools/input/annexb.c
@@ -77,9 +77,9 @@
         res = leb128(c, &len);
         if (res < 0)
             break;
-        fseek(c->f, len, SEEK_CUR);
+        fseeko(c->f, len, SEEK_CUR);
     }
-    fseek(c->f, 0, SEEK_SET);
+    fseeko(c->f, 0, SEEK_SET);
 
     return 0;
 }
--- a/tools/input/ivf.c
+++ b/tools/input/ivf.c
@@ -36,10 +36,6 @@
 
 #include "input/demuxer.h"
 
-#ifdef _MSC_VER
-#define ftello _ftelli64
-#endif
-
 typedef struct DemuxerPriv {
     FILE *f;
 } IvfInputContext;
@@ -85,11 +81,11 @@
     for (*num_frames = 0;; (*num_frames)++) {
         if ((res = fread(data, 4, 1, c->f)) != 1)
             break; // EOF
-        fseek(c->f, rl32(data) + 8, SEEK_CUR);
+        fseeko(c->f, rl32(data) + 8, SEEK_CUR);
     }
     fps[0] *= *num_frames;
     fps[1] *= duration;
-    fseek(c->f, 32, SEEK_SET);
+    fseeko(c->f, 32, SEEK_SET);
 
     return 0;
 }