Bug 1272203 (part 3) - Use NotNull in nsContentUtils::GetSurfaceData(). r=froydnj.

This might not look compelling in isolation, but this use of NotNull would have
prevented the null dereference crash in bug 1268721.
This commit is contained in:
Nicholas Nethercote 2016-05-27 09:49:25 +10:00
Родитель 19c16a645a
Коммит 62f0bd3e33
4 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -7424,7 +7424,8 @@ nsContentUtils::TransferableToIPCTransferable(nsITransferable* aTransferable,
size_t length; size_t length;
int32_t stride; int32_t stride;
mozilla::UniquePtr<char[]> surfaceData = mozilla::UniquePtr<char[]> surfaceData =
nsContentUtils::GetSurfaceData(dataSurface, &length, &stride); nsContentUtils::GetSurfaceData(WrapNotNull(dataSurface), &length,
&stride);
IPCDataTransferItem* item = aIPCDataTransfer->items().AppendElement(); IPCDataTransferItem* item = aIPCDataTransfer->items().AppendElement();
item->flavor() = flavorStr; item->flavor() = flavorStr;
@ -7528,8 +7529,9 @@ nsContentUtils::TransferableToIPCTransferable(nsITransferable* aTransferable,
} }
mozilla::UniquePtr<char[]> mozilla::UniquePtr<char[]>
nsContentUtils::GetSurfaceData(mozilla::gfx::DataSourceSurface* aSurface, nsContentUtils::GetSurfaceData(
size_t* aLength, int32_t* aStride) NotNull<mozilla::gfx::DataSourceSurface*> aSurface,
size_t* aLength, int32_t* aStride)
{ {
mozilla::gfx::DataSourceSurface::MappedSurface map; mozilla::gfx::DataSourceSurface::MappedSurface map;
if (NS_WARN_IF(!aSurface->Map(mozilla::gfx::DataSourceSurface::MapType::READ, &map))) { if (NS_WARN_IF(!aSurface->Map(mozilla::gfx::DataSourceSurface::MapType::READ, &map))) {

Просмотреть файл

@ -32,6 +32,7 @@
#include "mozilla/FloatingPoint.h" #include "mozilla/FloatingPoint.h"
#include "mozilla/net/ReferrerPolicy.h" #include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/Logging.h" #include "mozilla/Logging.h"
#include "mozilla/NotNull.h"
#include "nsIContentPolicy.h" #include "nsIContentPolicy.h"
#if defined(XP_WIN) #if defined(XP_WIN)
@ -2432,8 +2433,9 @@ public:
* Get the pixel data from the given source surface and return it as a buffer. * Get the pixel data from the given source surface and return it as a buffer.
* The length and stride will be assigned from the surface. * The length and stride will be assigned from the surface.
*/ */
static mozilla::UniquePtr<char[]> GetSurfaceData(mozilla::gfx::DataSourceSurface* aSurface, static mozilla::UniquePtr<char[]> GetSurfaceData(
size_t* aLength, int32_t* aStride); mozilla::NotNull<mozilla::gfx::DataSourceSurface*> aSurface,
size_t* aLength, int32_t* aStride);
// Helpers shared by the implementations of nsContentUtils methods and // Helpers shared by the implementations of nsContentUtils methods and
// nsIDOMWindowUtils methods. // nsIDOMWindowUtils methods.

Просмотреть файл

@ -990,7 +990,7 @@ PuppetWidget::SetCursor(imgIContainer* aCursor,
size_t length; size_t length;
int32_t stride; int32_t stride;
mozilla::UniquePtr<char[]> surfaceData = mozilla::UniquePtr<char[]> surfaceData =
nsContentUtils::GetSurfaceData(dataSurface, &length, &stride); nsContentUtils::GetSurfaceData(WrapNotNull(dataSurface), &length, &stride);
nsDependentCString cursorData(surfaceData.get(), length); nsDependentCString cursorData(surfaceData.get(), length);
mozilla::gfx::IntSize size = dataSurface->GetSize(); mozilla::gfx::IntSize size = dataSurface->GetSize();

Просмотреть файл

@ -55,7 +55,8 @@ nsDragServiceProxy::InvokeDragSessionImpl(nsISupportsArray* aArrayTransferables,
size_t length; size_t length;
int32_t stride; int32_t stride;
mozilla::UniquePtr<char[]> surfaceData = mozilla::UniquePtr<char[]> surfaceData =
nsContentUtils::GetSurfaceData(dataSurface, &length, &stride); nsContentUtils::GetSurfaceData(WrapNotNull(dataSurface), &length,
&stride);
nsDependentCString dragImage(surfaceData.get(), length); nsDependentCString dragImage(surfaceData.get(), length);
mozilla::Unused << mozilla::Unused <<