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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: self review Created 5 years 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
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 "core/include/fpdfapi/fpdf_parser.h" 7 #include "core/include/fpdfapi/fpdf_parser.h"
8 8
9 #include "core/include/fxcrt/fx_string.h" 9 #include "core/include/fxcrt/fx_string.h"
10 10
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 while (pos) { 576 while (pos) {
577 if (CPDF_Object* value = static_cast<CPDF_Object*>(m_Map.GetNextValue(pos))) 577 if (CPDF_Object* value = static_cast<CPDF_Object*>(m_Map.GetNextValue(pos)))
578 value->Release(); 578 value->Release();
579 } 579 }
580 } 580 }
581 FX_POSITION CPDF_Dictionary::GetStartPos() const { 581 FX_POSITION CPDF_Dictionary::GetStartPos() const {
582 return m_Map.GetStartPosition(); 582 return m_Map.GetStartPosition();
583 } 583 }
584 CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, 584 CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos,
585 CFX_ByteString& key) const { 585 CFX_ByteString& key) const {
586 if (pos == NULL) { 586 if (!pos) {
587 return NULL; 587 return NULL;
588 } 588 }
589 CPDF_Object* p; 589 CPDF_Object* p;
590 m_Map.GetNextAssoc(pos, key, (void*&)p); 590 m_Map.GetNextAssoc(pos, key, (void*&)p);
591 return p; 591 return p;
592 } 592 }
593 CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const { 593 CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const {
594 CPDF_Object* p = NULL; 594 CPDF_Object* p = NULL;
595 m_Map.Lookup(key, (void*&)p); 595 m_Map.Lookup(key, (void*&)p);
596 return p; 596 return p;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 730 }
731 731
732 void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) { 732 void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) {
733 ASSERT(m_Type == PDFOBJ_DICTIONARY); 733 ASSERT(m_Type == PDFOBJ_DICTIONARY);
734 m_Map.AddValue(key, pObj); 734 m_Map.AddValue(key, pObj);
735 } 735 }
736 void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) { 736 void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) {
737 ASSERT(m_Type == PDFOBJ_DICTIONARY); 737 ASSERT(m_Type == PDFOBJ_DICTIONARY);
738 CPDF_Object* p = NULL; 738 CPDF_Object* p = NULL;
739 m_Map.Lookup(key, (void*&)p); 739 m_Map.Lookup(key, (void*&)p);
740 if (p == NULL) { 740 if (!p) {
741 return; 741 return;
742 } 742 }
743 p->Release(); 743 p->Release();
744 m_Map.RemoveKey(key); 744 m_Map.RemoveKey(key);
745 } 745 }
746 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, 746 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey,
747 const CFX_ByteStringC& newkey) { 747 const CFX_ByteStringC& newkey) {
748 ASSERT(m_Type == PDFOBJ_DICTIONARY); 748 ASSERT(m_Type == PDFOBJ_DICTIONARY);
749 CPDF_Object* p = NULL; 749 CPDF_Object* p = NULL;
750 m_Map.Lookup(oldkey, (void*&)p); 750 m_Map.Lookup(oldkey, (void*&)p);
751 if (p == NULL) { 751 if (!p) {
752 return; 752 return;
753 } 753 }
754 m_Map.RemoveKey(oldkey); 754 m_Map.RemoveKey(oldkey);
755 m_Map.SetAt(newkey, p); 755 m_Map.SetAt(newkey, p);
756 } 756 }
757 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const { 757 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const {
758 if (pOther == NULL) { 758 if (!pOther) {
759 return FALSE; 759 return FALSE;
760 } 760 }
761 if (m_Map.GetCount() != pOther->m_Map.GetCount()) { 761 if (m_Map.GetCount() != pOther->m_Map.GetCount()) {
762 return FALSE; 762 return FALSE;
763 } 763 }
764 FX_POSITION pos = m_Map.GetStartPosition(); 764 FX_POSITION pos = m_Map.GetStartPosition();
765 while (pos) { 765 while (pos) {
766 CFX_ByteString key; 766 CFX_ByteString key;
767 void* value; 767 void* value;
768 m_Map.GetNextAssoc(pos, key, value); 768 m_Map.GetNextAssoc(pos, key, value);
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) 1149 if (!m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value))
1150 return; 1150 return;
1151 CPDF_Object* pValue = static_cast<CPDF_Object*>(value); 1151 CPDF_Object* pValue = static_cast<CPDF_Object*>(value);
1152 if (pValue->GetObjNum() == -1) 1152 if (pValue->GetObjNum() == -1)
1153 return; 1153 return;
1154 pValue->Destroy(); 1154 pValue->Destroy();
1155 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum); 1155 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum);
1156 } 1156 }
1157 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, 1157 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum,
1158 CPDF_Object* pObj) { 1158 CPDF_Object* pObj) {
1159 if (objnum == 0 || pObj == NULL) { 1159 if (objnum == 0 || !pObj) {
1160 return; 1160 return;
1161 } 1161 }
1162 void* value = NULL; 1162 void* value = NULL;
1163 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { 1163 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) {
1164 if (value) { 1164 if (value) {
1165 CPDF_Object* pValue = static_cast<CPDF_Object*>(value); 1165 CPDF_Object* pValue = static_cast<CPDF_Object*>(value);
1166 if (pObj->GetGenNum() <= pValue->GetGenNum()) 1166 if (pObj->GetGenNum() <= pValue->GetGenNum())
1167 return; 1167 return;
1168 pValue->Destroy(); 1168 pValue->Destroy();
1169 } 1169 }
1170 } 1170 }
1171 pObj->m_ObjNum = objnum; 1171 pObj->m_ObjNum = objnum;
1172 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); 1172 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj);
1173 if (m_LastObjNum < objnum) { 1173 if (m_LastObjNum < objnum) {
1174 m_LastObjNum = objnum; 1174 m_LastObjNum = objnum;
1175 } 1175 }
1176 } 1176 }
1177 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { 1177 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const {
1178 return m_LastObjNum; 1178 return m_LastObjNum;
1179 } 1179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698