diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-05-16 15:33:20 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-16 23:26:47 +0000 |
commit | fe91c6c8211cec39f871d9202556e1957bf81983 (patch) | |
tree | b7e763f7affe4c71de67393fbd320c1fed477e0f /fpdfsdk/fpdfeditpath.cpp | |
parent | 365333552cf67b7c97c4093177e7ed7b43f540ab (diff) | |
download | pdfium-fe91c6c8211cec39f871d9202556e1957bf81983.tar.xz |
Be skeptical of bare |new|s.
In particular, prefer an explicit .release() call when handing
ownership of an object to a caller across a C-API.
Change-Id: Ic3784e9d0b2d378a08d388989eaea7c9166bacd1
Reviewed-on: https://pdfium-review.googlesource.com/5470
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfeditpath.cpp')
-rw-r--r-- | fpdfsdk/fpdfeditpath.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp index 155dda5c7d..a26ca5186e 100644 --- a/fpdfsdk/fpdfeditpath.cpp +++ b/fpdfsdk/fpdfeditpath.cpp @@ -7,22 +7,23 @@ #include "core/fpdfapi/page/cpdf_path.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fxcrt/fx_system.h" +#include "third_party/base/ptr_util.h" DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewPath(float x, float y) { - CPDF_PathObject* pPathObj = new CPDF_PathObject; + auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); pPathObj->DefaultStates(); - return pPathObj; + return pPathObj.release(); // Caller takes ownership. } DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewRect(float x, float y, float w, float h) { - CPDF_PathObject* pPathObj = new CPDF_PathObject; + auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); pPathObj->m_Path.AppendRect(x, y, x + w, y + h); pPathObj->DefaultStates(); - return pPathObj; + return pPathObj.release(); // Caller takes ownership. } DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, @@ -33,9 +34,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, if (!path || R > 255 || G > 255 || B > 255 || A > 255) return false; + float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; auto* pPathObj = reinterpret_cast<CPDF_PathObject*>(path); pPathObj->m_GeneralState.SetStrokeAlpha(A / 255.f); - float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; pPathObj->m_ColorState.SetStrokeColor( CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); return true; @@ -58,9 +59,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, if (!path || R > 255 || G > 255 || B > 255 || A > 255) return false; + float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; auto* pPathObj = reinterpret_cast<CPDF_PathObject*>(path); pPathObj->m_GeneralState.SetFillAlpha(A / 255.f); - float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; pPathObj->m_ColorState.SetFillColor( CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); return true; |