diff --git a/source/core/StarFile_windows.cpp b/source/core/StarFile_windows.cpp index 0b5c286..d9719b1 100644 --- a/source/core/StarFile_windows.cpp +++ b/source/core/StarFile_windows.cpp @@ -377,7 +377,12 @@ size_t File::pread(void* f, char* data, size_t len, StreamOffset position) { HANDLE file = (HANDLE)f; DWORD numRead = 0; OVERLAPPED overlapped = makeOverlapped(position); + + StreamOffset pos = ftell(f); + if (pos != 0) fseek(f, 0, IOSeek::Absolute); int ret = ReadFile(file, data, len, &numRead, &overlapped); + if (pos != 0) fseek(f, pos, IOSeek::Absolute); + if (ret == 0) { auto err = GetLastError(); if (err != ERROR_IO_PENDING) @@ -391,7 +396,12 @@ size_t File::pwrite(void* f, char const* data, size_t len, StreamOffset position HANDLE file = (HANDLE)f; DWORD numWritten = 0; OVERLAPPED overlapped = makeOverlapped(position); + + StreamOffset pos = ftell(f); + if (pos != 0) fseek(f, 0, IOSeek::Absolute); int ret = WriteFile(file, data, len, &numWritten, &overlapped); + if (pos != 0) fseek(f, pos, IOSeek::Absolute); + if (ret == 0) { auto err = GetLastError(); if (err != ERROR_IO_PENDING) diff --git a/source/core/StarImage.cpp b/source/core/StarImage.cpp index 52c2370..c7d4962 100644 --- a/source/core/StarImage.cpp +++ b/source/core/StarImage.cpp @@ -18,13 +18,12 @@ void readPngData(png_structp pngPtr, png_bytep data, png_size_t length) { }; bool Image::isPng(IODevicePtr device) { - png_byte header[8]; - device->readAbsolute(0, (char*)header, sizeof(header)); - return !png_sig_cmp(header, 0, sizeof(header)); + png_byte header[8]{}; + return !png_sig_cmp(header, 0, device->readAbsolute(0, (char*)header, sizeof(header))); } Image Image::readPng(IODevicePtr device) { - png_byte header[8]; + png_byte header[8]{}; device->readFull((char*)header, sizeof(header)); if (png_sig_cmp(header, 0, sizeof(header)))