Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: core/src/fxcrt/fx_xml_parser.cpp

Issue 1052553006: Remove checks in fxcrt now that FX_NEW can't return 0. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fxcrt/fx_xml.h" 7 #include "../../include/fxcrt/fx_xml.h"
8 #include "xml_int.h" 8 #include "xml_int.h"
9 CXML_Parser::~CXML_Parser() 9 CXML_Parser::~CXML_Parser()
10 { 10 {
11 if (m_bOwnedStream) { 11 if (m_bOwnedStream) {
12 m_pDataAcc->Release(); 12 m_pDataAcc->Release();
13 } 13 }
14 } 14 }
15 FX_BOOL CXML_Parser::Init(FX_LPBYTE pBuffer, size_t size) 15 FX_BOOL CXML_Parser::Init(FX_LPBYTE pBuffer, size_t size)
16 { 16 {
17 m_pDataAcc = FX_NEW CXML_DataBufAcc(pBuffer, size); 17 m_pDataAcc = new CXML_DataBufAcc(pBuffer, size);
18 if (!m_pDataAcc) {
19 return FALSE;
20 }
21 return Init(TRUE); 18 return Init(TRUE);
22 } 19 }
23 FX_BOOL CXML_Parser::Init(IFX_FileRead *pFileRead) 20 FX_BOOL CXML_Parser::Init(IFX_FileRead *pFileRead)
24 { 21 {
25 m_pDataAcc = FX_NEW CXML_DataStmAcc(pFileRead); 22 m_pDataAcc = new CXML_DataStmAcc(pFileRead);
26 if (!m_pDataAcc) {
27 return FALSE;
28 }
29 return Init(TRUE); 23 return Init(TRUE);
30 } 24 }
31 FX_BOOL CXML_Parser::Init(IFX_BufferRead *pBuffer) 25 FX_BOOL CXML_Parser::Init(IFX_BufferRead *pBuffer)
32 { 26 {
33 if (!pBuffer) { 27 if (!pBuffer) {
34 return FALSE; 28 return FALSE;
35 } 29 }
36 m_pDataAcc = pBuffer; 30 m_pDataAcc = pBuffer;
37 return Init(FALSE); 31 return Init(FALSE);
38 } 32 }
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 364 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
371 if (IsEOF()) { 365 if (IsEOF()) {
372 return NULL; 366 return NULL;
373 } 367 }
374 CFX_ByteString tag_name, tag_space; 368 CFX_ByteString tag_name, tag_space;
375 FX_BOOL bEndTag; 369 FX_BOOL bEndTag;
376 GetTagName(tag_space, tag_name, bEndTag, bStartTag); 370 GetTagName(tag_space, tag_name, bEndTag, bStartTag);
377 if (tag_name.IsEmpty() || bEndTag) { 371 if (tag_name.IsEmpty() || bEndTag) {
378 return NULL; 372 return NULL;
379 } 373 }
380 CXML_Element* pElement; 374 CXML_Element* pElement = new CXML_Element;
381 pElement = FX_NEW CXML_Element; 375 pElement->m_pParent = pParent;
382 if (pElement) { 376 pElement->SetTag(tag_space, tag_name);
383 pElement->m_pParent = pParent;
384 pElement->SetTag(tag_space, tag_name);
385 }
386 if (!pElement) {
387 return NULL;
388 }
389 do { 377 do {
390 CFX_ByteString attr_space, attr_name; 378 CFX_ByteString attr_space, attr_name;
391 while (m_dwIndex < m_dwBufferSize) { 379 while (m_dwIndex < m_dwBufferSize) {
392 SkipWhiteSpaces(); 380 SkipWhiteSpaces();
393 if (IsEOF()) { 381 if (IsEOF()) {
394 break; 382 break;
395 } 383 }
396 if (!g_FXCRT_XML_IsNameIntro(m_pBuffer[m_dwIndex])) { 384 if (!g_FXCRT_XML_IsNameIntro(m_pBuffer[m_dwIndex])) {
397 break; 385 break;
398 } 386 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 content.Clear(); 510 content.Clear();
523 decoder.Clear(); 511 decoder.Clear();
524 bCDATA = FALSE; 512 bCDATA = FALSE;
525 return pElement; 513 return pElement;
526 } 514 }
527 void CXML_Parser::InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Ele ment* pElement) 515 void CXML_Parser::InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Ele ment* pElement)
528 { 516 {
529 if (content.IsEmpty()) { 517 if (content.IsEmpty()) {
530 return; 518 return;
531 } 519 }
532 CXML_Content* pContent; 520 CXML_Content* pContent = new CXML_Content;
533 pContent = FX_NEW CXML_Content;
534 if (!pContent) {
535 return;
536 }
537 pContent->Set(bCDATA, content); 521 pContent->Set(bCDATA, content);
538 pElement->m_Children.Add((FX_LPVOID)CXML_Element::Content); 522 pElement->m_Children.Add((FX_LPVOID)CXML_Element::Content);
539 pElement->m_Children.Add(pContent); 523 pElement->m_Children.Add(pContent);
540 } 524 }
541 static CXML_Element* XML_ContinueParse(CXML_Parser &parser, FX_BOOL bSaveSpaceCh ars, FX_FILESIZE* pParsedSize) 525 static CXML_Element* XML_ContinueParse(CXML_Parser &parser, FX_BOOL bSaveSpaceCh ars, FX_FILESIZE* pParsedSize)
542 { 526 {
543 parser.m_bSaveSpaceChars = bSaveSpaceChars; 527 parser.m_bSaveSpaceChars = bSaveSpaceChars;
544 CXML_Element* pElement = parser.ParseElement(NULL, FALSE); 528 CXML_Element* pElement = parser.ParseElement(NULL, FALSE);
545 if (pParsedSize) { 529 if (pParsedSize) {
546 *pParsedSize = parser.m_nOffset; 530 *pParsedSize = parser.m_nOffset;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value) 795 void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value)
812 { 796 {
813 for (int i = 0; i < GetSize(); i++) { 797 for (int i = 0; i < GetSize(); i++) {
814 CXML_AttrItem& item = GetAt(i); 798 CXML_AttrItem& item = GetAt(i);
815 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) { 799 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) {
816 item.m_Value = value; 800 item.m_Value = value;
817 return; 801 return;
818 } 802 }
819 } 803 }
820 if (!m_pMap) { 804 if (!m_pMap) {
821 m_pMap = FX_NEW CFX_ObjectArray < CXML_AttrItem > ; 805 m_pMap = new CFX_ObjectArray<CXML_AttrItem>;
822 }
823 if (!m_pMap) {
824 return;
825 } 806 }
826 CXML_AttrItem* pItem = (CXML_AttrItem*)m_pMap->AddSpace(); 807 CXML_AttrItem* pItem = (CXML_AttrItem*)m_pMap->AddSpace();
827 if (!pItem) { 808 if (!pItem) {
828 return; 809 return;
829 } 810 }
830 pItem->m_QSpaceName = space; 811 pItem->m_QSpaceName = space;
831 pItem->m_AttrName = name; 812 pItem->m_AttrName = name;
832 pItem->m_Value = value; 813 pItem->m_Value = value;
833 } 814 }
834 void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name) 815 void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name)
(...skipping 20 matching lines...) Expand all
855 } 836 }
856 void CXML_AttrMap::RemoveAll() 837 void CXML_AttrMap::RemoveAll()
857 { 838 {
858 if (!m_pMap) { 839 if (!m_pMap) {
859 return; 840 return;
860 } 841 }
861 m_pMap->RemoveAll(); 842 m_pMap->RemoveAll();
862 delete m_pMap; 843 delete m_pMap;
863 m_pMap = NULL; 844 m_pMap = NULL;
864 } 845 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698