From 03c094a42bcf9d6d7a0198eadc758b9fc32e38fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Fri, 6 Dec 2019 09:18:16 +0100 Subject: [PATCH] Fix `fseek()`/`ftell()` issue --- rtengine/canon_cr3_decoder.cc | 8 ++++---- rtengine/dcraw.h | 2 +- rtengine/myfile.h | 10 ++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/rtengine/canon_cr3_decoder.cc b/rtengine/canon_cr3_decoder.cc index 3912af6b4..14a7f0e14 100644 --- a/rtengine/canon_cr3_decoder.cc +++ b/rtengine/canon_cr3_decoder.cc @@ -449,9 +449,9 @@ int DCraw::parseCR3( goto fin; } - const std::int64_t off = ftell(ifp); // FIXME: ftell() returns int + const long off = ftell(ifp); parse_gps(oAtomContent); - fseek(ifp, off, SEEK_SET); // FIXME: fseek() takes int offset + fseek(ifp, off, SEEK_SET); // parse_gps_libraw(oAtomContent); order = q_order; } else if (!strcmp(AtomNameStack, "moovtrakmdiahdlr")) { @@ -468,7 +468,7 @@ int DCraw::parseCR3( } } else if (!strcmp(AtomNameStack, "moovtrakmdiaminfstblstsd")) { if (szAtomContent >= 16) { - fseek(ifp, 12L, SEEK_CUR); + fseek(ifp, 12, SEEK_CUR); lHdr = 8; } else { err = -7; @@ -670,7 +670,7 @@ struct LibRaw_abstract_datastream { void unlock() { } - void seek(int p, int how) + void seek(long p, int how) { fseek(ifp, p, how); } diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h index a47d1c88a..89c1fcaff 100644 --- a/rtengine/dcraw.h +++ b/rtengine/dcraw.h @@ -184,7 +184,7 @@ public: int32_t mdatHdrSize; // Not from header, but from datastream uint32_t MediaSize; - INT64 MediaOffset; + int64_t MediaOffset; uint32_t MediaType; /* 1 -> /C/RAW, 2-> JPEG */ }; static constexpr size_t CRXTRACKS_MAXCOUNT = 16; diff --git a/rtengine/myfile.h b/rtengine/myfile.h index 7c498e556..423edea9a 100644 --- a/rtengine/myfile.h +++ b/rtengine/myfile.h @@ -56,28 +56,26 @@ IMFILE* fopen (const char* fname); IMFILE* gfopen (const char* fname); IMFILE* fopen (unsigned* buf, int size); void fclose (IMFILE* f); -inline int ftell (IMFILE* f) +inline long ftell (IMFILE* f) { - return f->pos; } inline int feof (IMFILE* f) { - return f->eof; } -inline void fseek (IMFILE* f, int p, int how) +inline void fseek (IMFILE* f, long p, int how) { - int fpos = f->pos; + ssize_t fpos = f->pos; if (how == SEEK_SET) { f->pos = p; } else if (how == SEEK_CUR) { f->pos += p; } else if (how == SEEK_END) { - if(p <= 0 && -p <= f->size) { + if (p <= 0 && -p <= f->size) { f->pos = f->size + p; } return;