mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1222575 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in modules/libjar/; r=aklotz
This commit is contained in:
parent
86cc3c6cfb
commit
4a22000c62
@ -21,6 +21,7 @@
|
|||||||
#include "prio.h"
|
#include "prio.h"
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
#include "mozilla/Logging.h"
|
#include "mozilla/Logging.h"
|
||||||
|
#include "mozilla/UniquePtrExtensions.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "nsWildCard.h"
|
#include "nsWildCard.h"
|
||||||
#include "nsZipArchive.h"
|
#include "nsZipArchive.h"
|
||||||
@ -1194,13 +1195,13 @@ nsZipItemPtr_base::nsZipItemPtr_base(nsZipArchive *aZip,
|
|||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
if (item->Compression() == DEFLATED) {
|
if (item->Compression() == DEFLATED) {
|
||||||
size = item->RealSize();
|
size = item->RealSize();
|
||||||
mAutoBuf = new (fallible) uint8_t[size];
|
mAutoBuf = MakeUniqueFallible<uint8_t[]>(size);
|
||||||
if (!mAutoBuf) {
|
if (!mAutoBuf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsZipCursor cursor(item, aZip, mAutoBuf, size, doCRC);
|
nsZipCursor cursor(item, aZip, mAutoBuf.get(), size, doCRC);
|
||||||
mReturnBuf = cursor.Read(&mReadlen);
|
mReturnBuf = cursor.Read(&mReadlen);
|
||||||
if (!mReturnBuf) {
|
if (!mReturnBuf) {
|
||||||
return;
|
return;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "nsISupportsImpl.h" // For mozilla::ThreadSafeAutoRefCnt
|
#include "nsISupportsImpl.h" // For mozilla::ThreadSafeAutoRefCnt
|
||||||
#include "mozilla/FileUtils.h"
|
#include "mozilla/FileUtils.h"
|
||||||
#include "mozilla/FileLocation.h"
|
#include "mozilla/FileLocation.h"
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
#ifdef HAVE_SEH_EXCEPTIONS
|
#ifdef HAVE_SEH_EXCEPTIONS
|
||||||
#define MOZ_WIN_MEM_TRY_BEGIN __try {
|
#define MOZ_WIN_MEM_TRY_BEGIN __try {
|
||||||
@ -339,7 +340,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
RefPtr<nsZipHandle> mZipHandle;
|
RefPtr<nsZipHandle> mZipHandle;
|
||||||
nsAutoArrayPtr<uint8_t> mAutoBuf;
|
mozilla::UniquePtr<uint8_t[]> mAutoBuf;
|
||||||
uint8_t *mReturnBuf;
|
uint8_t *mReturnBuf;
|
||||||
uint32_t mReadlen;
|
uint32_t mReadlen;
|
||||||
};
|
};
|
||||||
@ -372,7 +373,7 @@ public:
|
|||||||
// In uncompressed mmap case, give up buffer
|
// In uncompressed mmap case, give up buffer
|
||||||
if (mAutoBuf.get() == mReturnBuf) {
|
if (mAutoBuf.get() == mReturnBuf) {
|
||||||
mReturnBuf = nullptr;
|
mReturnBuf = nullptr;
|
||||||
return (T*) mAutoBuf.forget();
|
return (T*) mAutoBuf.release();
|
||||||
}
|
}
|
||||||
T *ret = (T*) malloc(Length());
|
T *ret = (T*) malloc(Length());
|
||||||
memcpy(ret, mReturnBuf, Length());
|
memcpy(ret, mReturnBuf, Length());
|
||||||
|
@ -9,13 +9,15 @@
|
|||||||
#include "nsIInputStreamPump.h"
|
#include "nsIInputStreamPump.h"
|
||||||
#include "nsComponentManagerUtils.h"
|
#include "nsComponentManagerUtils.h"
|
||||||
#include "nsMemory.h"
|
#include "nsMemory.h"
|
||||||
#include "nsAutoPtr.h"
|
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
#define ZLIB_TYPE "deflate"
|
#define ZLIB_TYPE "deflate"
|
||||||
#define GZIP_TYPE "gzip"
|
#define GZIP_TYPE "gzip"
|
||||||
#define X_GZIP_TYPE "x-gzip"
|
#define X_GZIP_TYPE "x-gzip"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nsDeflateConverter is a stream converter applies the deflate compression
|
* nsDeflateConverter is a stream converter applies the deflate compression
|
||||||
* method to the data.
|
* method to the data.
|
||||||
@ -104,7 +106,7 @@ NS_IMETHODIMP nsDeflateConverter::OnDataAvailable(nsIRequest *aRequest,
|
|||||||
if (!mListener)
|
if (!mListener)
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
nsAutoArrayPtr<char> buffer(new char[aCount]);
|
auto buffer = MakeUnique<char[]>(aCount);
|
||||||
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
nsresult rv = ZW_ReadData(aInputStream, buffer.get(), aCount);
|
nsresult rv = ZW_ReadData(aInputStream, buffer.get(), aCount);
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#define ZIP_METHOD_STORE 0
|
#define ZIP_METHOD_STORE 0
|
||||||
#define ZIP_METHOD_DEFLATE 8
|
#define ZIP_METHOD_DEFLATE 8
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nsZipDataStream handles the writing an entry's into the zip file.
|
* nsZipDataStream handles the writing an entry's into the zip file.
|
||||||
* It is set up to wither write the data as is, or in the event that compression
|
* It is set up to wither write the data as is, or in the event that compression
|
||||||
@ -68,7 +70,7 @@ NS_IMETHODIMP nsZipDataStream::OnDataAvailable(nsIRequest *aRequest,
|
|||||||
if (!mOutput)
|
if (!mOutput)
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
nsAutoArrayPtr<char> buffer(new char[aCount]);
|
auto buffer = MakeUnique<char[]>(aCount);
|
||||||
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
nsresult rv = ZW_ReadData(aInputStream, buffer.get(), aCount);
|
nsresult rv = ZW_ReadData(aInputStream, buffer.get(), aCount);
|
||||||
@ -152,7 +154,7 @@ nsresult nsZipDataStream::ReadStream(nsIInputStream *aStream)
|
|||||||
nsresult rv = OnStartRequest(nullptr, nullptr);
|
nsresult rv = OnStartRequest(nullptr, nullptr);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsAutoArrayPtr<char> buffer(new char[4096]);
|
auto buffer = MakeUnique<char[]>(4096);
|
||||||
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
uint32_t read = 0;
|
uint32_t read = 0;
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#define ZIP_EXTENDED_TIMESTAMP_FIELD 0x5455
|
#define ZIP_EXTENDED_TIMESTAMP_FIELD 0x5455
|
||||||
#define ZIP_EXTENDED_TIMESTAMP_MODTIME 0x01
|
#define ZIP_EXTENDED_TIMESTAMP_MODTIME 0x01
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nsZipHeader represents an entry from a zip file.
|
* nsZipHeader represents an entry from a zip file.
|
||||||
*/
|
*/
|
||||||
@ -144,7 +146,7 @@ void nsZipHeader::Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr,
|
|||||||
// Store modification timestamp as extra field
|
// Store modification timestamp as extra field
|
||||||
// First fill CDS extra field
|
// First fill CDS extra field
|
||||||
mFieldLength = 9;
|
mFieldLength = 9;
|
||||||
mExtraField = new uint8_t[mFieldLength];
|
mExtraField = MakeUnique<uint8_t[]>(mFieldLength);
|
||||||
if (!mExtraField) {
|
if (!mExtraField) {
|
||||||
mFieldLength = 0;
|
mFieldLength = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -155,7 +157,7 @@ void nsZipHeader::Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr,
|
|||||||
WRITE32(mExtraField.get(), &pos, aDate / PR_USEC_PER_SEC);
|
WRITE32(mExtraField.get(), &pos, aDate / PR_USEC_PER_SEC);
|
||||||
|
|
||||||
// Fill local extra field
|
// Fill local extra field
|
||||||
mLocalExtraField = new uint8_t[mFieldLength];
|
mLocalExtraField = MakeUnique<uint8_t[]>(mFieldLength);
|
||||||
if (mLocalExtraField) {
|
if (mLocalExtraField) {
|
||||||
mLocalFieldLength = mFieldLength;
|
mLocalFieldLength = mFieldLength;
|
||||||
memcpy(mLocalExtraField.get(), mExtraField.get(), mLocalFieldLength);
|
memcpy(mLocalExtraField.get(), mExtraField.get(), mLocalFieldLength);
|
||||||
@ -283,28 +285,28 @@ nsresult nsZipHeader::ReadCDSHeader(nsIInputStream *stream)
|
|||||||
mOffset = READ32(buf, &pos);
|
mOffset = READ32(buf, &pos);
|
||||||
|
|
||||||
if (namelength > 0) {
|
if (namelength > 0) {
|
||||||
nsAutoArrayPtr<char> field(new char[namelength]);
|
auto field = MakeUnique<char[]>(namelength);
|
||||||
NS_ENSURE_TRUE(field, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(field, NS_ERROR_OUT_OF_MEMORY);
|
||||||
rv = ZW_ReadData(stream, field.get(), namelength);
|
rv = ZW_ReadData(stream, field.get(), namelength);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
mName.Assign(field, namelength);
|
mName.Assign(field.get(), namelength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mName = NS_LITERAL_CSTRING("");
|
mName = NS_LITERAL_CSTRING("");
|
||||||
|
|
||||||
if (mFieldLength > 0) {
|
if (mFieldLength > 0) {
|
||||||
mExtraField = new uint8_t[mFieldLength];
|
mExtraField = MakeUnique<uint8_t[]>(mFieldLength);
|
||||||
NS_ENSURE_TRUE(mExtraField, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(mExtraField, NS_ERROR_OUT_OF_MEMORY);
|
||||||
rv = ZW_ReadData(stream, (char *)mExtraField.get(), mFieldLength);
|
rv = ZW_ReadData(stream, (char *)mExtraField.get(), mFieldLength);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commentlength > 0) {
|
if (commentlength > 0) {
|
||||||
nsAutoArrayPtr<char> field(new char[commentlength]);
|
auto field = MakeUnique<char[]>(commentlength);
|
||||||
NS_ENSURE_TRUE(field, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(field, NS_ERROR_OUT_OF_MEMORY);
|
||||||
rv = ZW_ReadData(stream, field.get(), commentlength);
|
rv = ZW_ReadData(stream, field.get(), commentlength);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
mComment.Assign(field, commentlength);
|
mComment.Assign(field.get(), commentlength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mComment = NS_LITERAL_CSTRING("");
|
mComment = NS_LITERAL_CSTRING("");
|
||||||
@ -315,7 +317,7 @@ nsresult nsZipHeader::ReadCDSHeader(nsIInputStream *stream)
|
|||||||
|
|
||||||
const uint8_t * nsZipHeader::GetExtraField(uint16_t aTag, bool aLocal, uint16_t *aBlockSize)
|
const uint8_t * nsZipHeader::GetExtraField(uint16_t aTag, bool aLocal, uint16_t *aBlockSize)
|
||||||
{
|
{
|
||||||
const uint8_t *buf = aLocal ? mLocalExtraField : mExtraField;
|
const uint8_t *buf = aLocal ? mLocalExtraField.get() : mExtraField.get();
|
||||||
uint32_t buflen = aLocal ? mLocalFieldLength : mFieldLength;
|
uint32_t buflen = aLocal ? mLocalFieldLength : mFieldLength;
|
||||||
uint32_t pos = 0;
|
uint32_t pos = 0;
|
||||||
uint16_t tag, blocksize;
|
uint16_t tag, blocksize;
|
||||||
@ -370,11 +372,11 @@ nsresult nsZipHeader::PadExtraField(uint32_t aOffset, uint16_t aAlignSize)
|
|||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoArrayPtr<uint8_t> field = mLocalExtraField;
|
UniquePtr<uint8_t[]> field = Move(mLocalExtraField);
|
||||||
uint32_t pos = mLocalFieldLength;
|
uint32_t pos = mLocalFieldLength;
|
||||||
|
|
||||||
mLocalExtraField = new uint8_t[mLocalFieldLength + pad_size];
|
mLocalExtraField = MakeUnique<uint8_t[]>(mLocalFieldLength + pad_size);
|
||||||
memcpy(mLocalExtraField.get(), field, mLocalFieldLength);
|
memcpy(mLocalExtraField.get(), field.get(), mLocalFieldLength);
|
||||||
// Use 0xFFFF as tag ID to avoid conflict with other IDs.
|
// Use 0xFFFF as tag ID to avoid conflict with other IDs.
|
||||||
// For more information, please read "Extensible data fields" section in:
|
// For more information, please read "Extensible data fields" section in:
|
||||||
// http://www.pkware.com/documents/casestudies/APPNOTE.TXT
|
// http://www.pkware.com/documents/casestudies/APPNOTE.TXT
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
#include "nsIOutputStream.h"
|
#include "nsIOutputStream.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
#include "nsIZipReader.h"
|
#include "nsIZipReader.h"
|
||||||
#include "nsAutoPtr.h"
|
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
// High word is S_IFREG, low word is DOS file attribute
|
// High word is S_IFREG, low word is DOS file attribute
|
||||||
#define ZIP_ATTRS_FILE 0x80000000
|
#define ZIP_ATTRS_FILE 0x80000000
|
||||||
@ -77,8 +77,8 @@ public:
|
|||||||
bool mWriteOnClose;
|
bool mWriteOnClose;
|
||||||
nsCString mName;
|
nsCString mName;
|
||||||
nsCString mComment;
|
nsCString mComment;
|
||||||
nsAutoArrayPtr<uint8_t> mExtraField;
|
mozilla::UniquePtr<uint8_t[]> mExtraField;
|
||||||
nsAutoArrayPtr<uint8_t> mLocalExtraField;
|
mozilla::UniquePtr<uint8_t[]> mLocalExtraField;
|
||||||
|
|
||||||
void Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr,
|
void Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr,
|
||||||
uint32_t aOffset);
|
uint32_t aOffset);
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#define ZIP_EOCDR_HEADER_SIZE 22
|
#define ZIP_EOCDR_HEADER_SIZE 22
|
||||||
#define ZIP_EOCDR_HEADER_SIGNATURE 0x06054b50
|
#define ZIP_EOCDR_HEADER_SIGNATURE 0x06054b50
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nsZipWriter is used to create and add to zip files.
|
* nsZipWriter is used to create and add to zip files.
|
||||||
* It is based on the spec available at
|
* It is based on the spec available at
|
||||||
@ -164,7 +166,7 @@ nsresult nsZipWriter::ReadFile(nsIFile *aFile)
|
|||||||
inputStream->Close();
|
inputStream->Close();
|
||||||
return NS_ERROR_FILE_CORRUPTED;
|
return NS_ERROR_FILE_CORRUPTED;
|
||||||
}
|
}
|
||||||
nsAutoArrayPtr<char> field(new char[commentlen]);
|
auto field = MakeUnique<char[]>(commentlen);
|
||||||
NS_ENSURE_TRUE(field, NS_ERROR_OUT_OF_MEMORY);
|
NS_ENSURE_TRUE(field, NS_ERROR_OUT_OF_MEMORY);
|
||||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET,
|
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET,
|
||||||
seek + pos);
|
seek + pos);
|
||||||
|
Loading…
Reference in New Issue
Block a user