WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-234504-20211220152511.patch (text/plain), 6.98 KB, created by
Fujii Hironori
on 2021-12-19 22:25:12 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Fujii Hironori
Created:
2021-12-19 22:25:12 PST
Size:
6.98 KB
patch
obsolete
>Subversion Revision: 287253 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d34dd4610ca43dc029bf6a0b9ce69026b595b58e..802ed57dcb47bd5d4f8f0fc89c2a40d46e921f9a 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,15 @@ >+2021-12-19 Fujii Hironori <Hironori.Fujii@sony.com> >+ >+ [Win] MSVC reports "DownloadBundleWin.cpp(87): error C2362: initialization of 'magic' is skipped by 'goto exit'" with /std:c++20 >+ https://bugs.webkit.org/show_bug.cgi?id=234504 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * platform/network/win/DownloadBundleWin.cpp: >+ (WebCore::DownloadBundle::appendResumeData): >+ (WebCore::DownloadBundle::extractResumeData): >+ Reimplemented without goto statements. >+ > 2021-12-19 Brady Eidson <beidson@apple.com> > > Stub out NotificationEvent and related >diff --git a/Source/WebCore/platform/network/win/DownloadBundleWin.cpp b/Source/WebCore/platform/network/win/DownloadBundleWin.cpp >index d83c3b2a63b22c39e18c129e44bc8f2d38b8b2c8..098f68e833f0e7fed0e63eb3dbc5dfe1b2cb6fe5 100644 >--- a/Source/WebCore/platform/network/win/DownloadBundleWin.cpp >+++ b/Source/WebCore/platform/network/win/DownloadBundleWin.cpp >@@ -59,34 +59,32 @@ bool appendResumeData(const uint8_t* resumeBytes, uint32_t resumeLength, const S > } > > auto nullifiedPath = bundlePath.wideCharacters(); >- FILE* bundle = 0; >- if (_wfopen_s(&bundle, nullifiedPath.data(), TEXT("ab")) || !bundle) { >+ FILE* bundlePtr = 0; >+ if (_wfopen_s(&bundlePtr, nullifiedPath.data(), TEXT("ab")) || !bundlePtr) { > LOG_ERROR("Failed to open file %s to append resume data", bundlePath.ascii().data()); > return false; > } >+ auto closer = [](FILE* file) { >+ fclose(file); >+ }; >+ std::unique_ptr<FILE, decltype(closer)> bundle(bundlePtr); > >- bool result = false; >- >- if (fwrite(resumeBytes, 1, resumeLength, bundle) != resumeLength) { >+ if (fwrite(resumeBytes, 1, resumeLength, bundle.get()) != resumeLength) { > LOG_ERROR("Failed to write resume data to the bundle - errno(%i)", errno); >- goto exit; >+ return false; > } > >- if (fwrite(&resumeLength, 4, 1, bundle) != 1) { >+ if (fwrite(&resumeLength, 4, 1, bundle.get()) != 1) { > LOG_ERROR("Failed to write footer length to the bundle - errno(%i)", errno); >- goto exit; >+ return false; > } > > const uint32_t magic = magicNumber(); >- if (fwrite(&magic, 4, 1, bundle) != 1) { >+ if (fwrite(&magic, 4, 1, bundle.get()) != 1) { > LOG_ERROR("Failed to write footer magic number to the bundle - errno(%i)", errno); >- goto exit; >+ return false; > } >- >- result = true; >-exit: >- fclose(bundle); >- return result; >+ return true; > } > > bool extractResumeData(const String& bundlePath, Vector<uint8_t>& resumeData) >@@ -98,36 +96,38 @@ bool extractResumeData(const String& bundlePath, Vector<uint8_t>& resumeData) > > // Open a handle to the bundle file > auto nullifiedPath = bundlePath.wideCharacters(); >- FILE* bundle = 0; >- if (_wfopen_s(&bundle, nullifiedPath.data(), TEXT("r+b")) || !bundle) { >+ FILE* bundlePtr = 0; >+ if (_wfopen_s(&bundlePtr, nullifiedPath.data(), TEXT("r+b")) || !bundlePtr) { > LOG_ERROR("Failed to open file %s to get resume data", bundlePath.ascii().data()); > return false; > } >- >- bool result = false; >+ auto closer = [](FILE* file) { >+ fclose(file); >+ }; >+ std::unique_ptr<FILE, decltype(closer)> bundle(bundlePtr); > > // Stat the file to get its size > struct _stat64 fileStat; >- if (_fstat64(_fileno(bundle), &fileStat)) >- goto exit; >+ if (_fstat64(_fileno(bundle.get()), &fileStat)) >+ return false; > > // Check for the bundle magic number at the end of the file > fpos_t footerMagicNumberPosition = fileStat.st_size - 4; > ASSERT(footerMagicNumberPosition >= 0); > if (footerMagicNumberPosition < 0) >- goto exit; >- if (fsetpos(bundle, &footerMagicNumberPosition)) >- goto exit; >+ return false; >+ if (fsetpos(bundle.get(), &footerMagicNumberPosition)) >+ return false; > > uint32_t footerMagicNumber = 0; >- if (fread(&footerMagicNumber, 4, 1, bundle) != 1) { >+ if (fread(&footerMagicNumber, 4, 1, bundle.get()) != 1) { > LOG_ERROR("Failed to read footer magic number from the bundle - errno(%i)", errno); >- goto exit; >+ return false; > } > > if (footerMagicNumber != magicNumber()) { > LOG_ERROR("Footer's magic number does not match 0x%X - errno(%i)", magicNumber(), errno); >- goto exit; >+ return false; > } > > // Now we're *reasonably* sure this is a .download bundle we actually wrote. >@@ -135,44 +135,41 @@ bool extractResumeData(const String& bundlePath, Vector<uint8_t>& resumeData) > fpos_t footerLengthPosition = fileStat.st_size - 8; > ASSERT(footerLengthPosition >= 0); > if (footerLengthPosition < 0) >- goto exit; >+ return false; > >- if (fsetpos(bundle, &footerLengthPosition)) >- goto exit; >+ if (fsetpos(bundle.get(), &footerLengthPosition)) >+ return false; > > uint32_t footerLength = 0; >- if (fread(&footerLength, 4, 1, bundle) != 1) { >+ if (fread(&footerLength, 4, 1, bundle.get()) != 1) { > LOG_ERROR("Failed to read ResumeData length from the bundle - errno(%i)", errno); >- goto exit; >+ return false; > } > > // Make sure theres enough bytes to read in for the resume data, and perform the read > fpos_t footerStartPosition = fileStat.st_size - 8 - footerLength; > ASSERT(footerStartPosition >= 0); > if (footerStartPosition < 0) >- goto exit; >- if (fsetpos(bundle, &footerStartPosition)) >- goto exit; >+ return false; >+ if (fsetpos(bundle.get(), &footerStartPosition)) >+ return false; > > resumeData.resize(footerLength); >- if (fread(resumeData.data(), 1, footerLength, bundle) != footerLength) { >+ if (fread(resumeData.data(), 1, footerLength, bundle.get()) != footerLength) { > LOG_ERROR("Failed to read ResumeData from the bundle - errno(%i)", errno); >- goto exit; >+ return false; > } > > // CFURLDownload will seek to the appropriate place in the file (before our footer) and start overwriting from there > // However, say we were within a few hundred bytes of the end of a download when it was paused - > // The additional footer extended the length of the file beyond its final length, and there will be junk data leftover > // at the end. Therefore, now that we've retrieved the footer data, we need to truncate it. >- if (errno_t resizeError = _chsize_s(_fileno(bundle), footerStartPosition)) { >+ if (errno_t resizeError = _chsize_s(_fileno(bundle.get()), footerStartPosition)) { > LOG_ERROR("Failed to truncate the resume footer off the end of the file - errno(%i)", resizeError); >- goto exit; >+ return false; > } > >- result = true; >-exit: >- fclose(bundle); >- return result; >+ return true; > } > > } // namespace DownloadBundle
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 234504
:
447584
|
447624
|
447626
|
447765