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

Side by Side Diff: core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase 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 "editint.h" 7 #include "editint.h"
8 8
9 #include "core/include/fxcrt/fx_ext.h" 9 #include "core/include/fxcrt/fx_ext.h"
10 #include "core/include/fpdfapi/fpdf_serial.h" 10 #include "core/include/fpdfapi/fpdf_serial.h"
11 #include "core/include/fpdfapi/fpdf_parser.h" 11 #include "core/include/fpdfapi/fpdf_parser.h"
12 12
13 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) 13 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024)
14 #define PDF_XREFSTREAM_MAXSIZE 10000 14 #define PDF_XREFSTREAM_MAXSIZE 10000
15 15
16 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, 16 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj,
17 CFX_FileBufferArchive* pFile, 17 CFX_FileBufferArchive* pFile,
18 FX_FILESIZE& offset) { 18 FX_FILESIZE& offset) {
19 int32_t len = 0; 19 int32_t len = 0;
20 if (pObj == NULL) { 20 if (!pObj) {
21 if (pFile->AppendString(" null") < 0) { 21 if (pFile->AppendString(" null") < 0) {
22 return -1; 22 return -1;
23 } 23 }
24 offset += 5; 24 offset += 5;
25 return 1; 25 return 1;
26 } 26 }
27 switch (pObj->GetType()) { 27 switch (pObj->GetType()) {
28 case PDFOBJ_NULL: 28 case PDFOBJ_NULL:
29 if (pFile->AppendString(" null") < 0) { 29 if (pFile->AppendString(" null") < 0) {
30 return -1; 30 return -1;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 m_dwSize = 0; 409 m_dwSize = 0;
410 m_bNewBuf = FALSE; 410 m_bNewBuf = FALSE;
411 } 411 }
412 FX_BOOL CPDF_Encryptor::Initialize(CPDF_CryptoHandler* pHandler, 412 FX_BOOL CPDF_Encryptor::Initialize(CPDF_CryptoHandler* pHandler,
413 int objnum, 413 int objnum,
414 uint8_t* src_data, 414 uint8_t* src_data,
415 FX_DWORD src_size) { 415 FX_DWORD src_size) {
416 if (src_size == 0) { 416 if (src_size == 0) {
417 return TRUE; 417 return TRUE;
418 } 418 }
419 if (pHandler == NULL) { 419 if (!pHandler) {
420 m_pData = (uint8_t*)src_data; 420 m_pData = (uint8_t*)src_data;
421 m_dwSize = src_size; 421 m_dwSize = src_size;
422 m_bNewBuf = FALSE; 422 m_bNewBuf = FALSE;
423 return TRUE; 423 return TRUE;
424 } 424 }
425 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size); 425 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size);
426 m_pData = FX_Alloc(uint8_t, m_dwSize); 426 m_pData = FX_Alloc(uint8_t, m_dwSize);
427 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); 427 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize);
428 m_bNewBuf = TRUE; 428 m_bNewBuf = TRUE;
429 return TRUE; 429 return TRUE;
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 int32_t iRet = WriteIndirectObjectToStream(pObj); 1064 int32_t iRet = WriteIndirectObjectToStream(pObj);
1065 if (iRet < 1) { 1065 if (iRet < 1) {
1066 return iRet; 1066 return iRet;
1067 } 1067 }
1068 return WriteIndirectObj(pObj->GetObjNum(), pObj); 1068 return WriteIndirectObj(pObj->GetObjNum(), pObj);
1069 } 1069 }
1070 int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum, 1070 int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum,
1071 const CPDF_Object* pObj, 1071 const CPDF_Object* pObj,
1072 FX_BOOL bEncrypt) { 1072 FX_BOOL bEncrypt) {
1073 int32_t len = 0; 1073 int32_t len = 0;
1074 if (pObj == NULL) { 1074 if (!pObj) {
1075 if (m_File.AppendString(" null") < 0) { 1075 if (m_File.AppendString(" null") < 0) {
1076 return -1; 1076 return -1;
1077 } 1077 }
1078 m_Offset += 5; 1078 m_Offset += 5;
1079 return 1; 1079 return 1;
1080 } 1080 }
1081 switch (pObj->GetType()) { 1081 switch (pObj->GetType()) {
1082 case PDFOBJ_NULL: 1082 case PDFOBJ_NULL:
1083 if (m_File.AppendString(" null") < 0) { 1083 if (m_File.AppendString(" null") < 0) {
1084 return -1; 1084 return -1;
1085 } 1085 }
1086 m_Offset += 5; 1086 m_Offset += 5;
1087 break; 1087 break;
1088 case PDFOBJ_BOOLEAN: 1088 case PDFOBJ_BOOLEAN:
1089 case PDFOBJ_NUMBER: 1089 case PDFOBJ_NUMBER:
1090 if (m_File.AppendString(" ") < 0) { 1090 if (m_File.AppendString(" ") < 0) {
1091 return -1; 1091 return -1;
1092 } 1092 }
1093 if ((len = m_File.AppendString(pObj->GetString())) < 0) { 1093 if ((len = m_File.AppendString(pObj->GetString())) < 0) {
1094 return -1; 1094 return -1;
1095 } 1095 }
1096 m_Offset += len + 1; 1096 m_Offset += len + 1;
1097 break; 1097 break;
1098 case PDFOBJ_STRING: { 1098 case PDFOBJ_STRING: {
1099 CFX_ByteString str = pObj->GetString(); 1099 CFX_ByteString str = pObj->GetString();
1100 FX_BOOL bHex = pObj->AsString()->IsHex(); 1100 FX_BOOL bHex = pObj->AsString()->IsHex();
1101 if (m_pCryptoHandler == NULL || !bEncrypt) { 1101 if (!m_pCryptoHandler || !bEncrypt) {
1102 CFX_ByteString content = PDF_EncodeString(str, bHex); 1102 CFX_ByteString content = PDF_EncodeString(str, bHex);
1103 if ((len = m_File.AppendString(content)) < 0) { 1103 if ((len = m_File.AppendString(content)) < 0) {
1104 return -1; 1104 return -1;
1105 } 1105 }
1106 m_Offset += len; 1106 m_Offset += len;
1107 break; 1107 break;
1108 } 1108 }
1109 CPDF_Encryptor encryptor; 1109 CPDF_Encryptor encryptor;
1110 encryptor.Initialize(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(), 1110 encryptor.Initialize(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(),
1111 str.GetLength()); 1111 str.GetLength());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 } 1193 }
1194 } 1194 }
1195 } 1195 }
1196 if (m_File.AppendString("]") < 0) { 1196 if (m_File.AppendString("]") < 0) {
1197 return -1; 1197 return -1;
1198 } 1198 }
1199 m_Offset += 1; 1199 m_Offset += 1;
1200 break; 1200 break;
1201 } 1201 }
1202 case PDFOBJ_DICTIONARY: { 1202 case PDFOBJ_DICTIONARY: {
1203 if (m_pCryptoHandler == NULL || pObj == m_pEncryptDict) { 1203 if (!m_pCryptoHandler || pObj == m_pEncryptDict) {
1204 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); 1204 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset);
1205 } 1205 }
1206 if (m_File.AppendString("<<") < 0) { 1206 if (m_File.AppendString("<<") < 0) {
1207 return -1; 1207 return -1;
1208 } 1208 }
1209 m_Offset += 2; 1209 m_Offset += 2;
1210 const CPDF_Dictionary* p = pObj->AsDictionary(); 1210 const CPDF_Dictionary* p = pObj->AsDictionary();
1211 FX_BOOL bSignDict = IsSignatureDict(p); 1211 FX_BOOL bSignDict = IsSignatureDict(p);
1212 FX_POSITION pos = p->GetStartPos(); 1212 FX_POSITION pos = p->GetStartPos();
1213 while (pos) { 1213 while (pos) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1256 }
1257 m_ObjectOffset[objnum] = m_Offset; 1257 m_ObjectOffset[objnum] = m_Offset;
1258 void* valuetemp = NULL; 1258 void* valuetemp = NULL;
1259 FX_BOOL bExistInMap = 1259 FX_BOOL bExistInMap =
1260 m_pDocument->m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, valuetemp); 1260 m_pDocument->m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, valuetemp);
1261 FX_BOOL bObjStm = 1261 FX_BOOL bObjStm =
1262 (m_pParser->m_V5Type[objnum] == 2) && m_pEncryptDict && !m_pXRefStream; 1262 (m_pParser->m_V5Type[objnum] == 2) && m_pEncryptDict && !m_pXRefStream;
1263 if (m_pParser->m_bVersionUpdated || m_bSecurityChanged || bExistInMap || 1263 if (m_pParser->m_bVersionUpdated || m_bSecurityChanged || bExistInMap ||
1264 bObjStm) { 1264 bObjStm) {
1265 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); 1265 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum);
1266 if (pObj == NULL) { 1266 if (!pObj) {
1267 m_ObjectOffset[objnum] = 0; 1267 m_ObjectOffset[objnum] = 0;
1268 m_ObjectSize[objnum] = 0; 1268 m_ObjectSize[objnum] = 0;
1269 return 0; 1269 return 0;
1270 } 1270 }
1271 if (WriteIndirectObj(pObj)) { 1271 if (WriteIndirectObj(pObj)) {
1272 return -1; 1272 return -1;
1273 } 1273 }
1274 if (!bExistInMap) { 1274 if (!bExistInMap) {
1275 m_pDocument->ReleaseIndirectObject(objnum); 1275 m_pDocument->ReleaseIndirectObject(objnum);
1276 } 1276 }
1277 } else { 1277 } else {
1278 uint8_t* pBuffer; 1278 uint8_t* pBuffer;
1279 FX_DWORD size; 1279 FX_DWORD size;
1280 m_pParser->GetIndirectBinary(objnum, pBuffer, size); 1280 m_pParser->GetIndirectBinary(objnum, pBuffer, size);
1281 if (pBuffer == NULL) { 1281 if (!pBuffer) {
1282 return 0; 1282 return 0;
1283 } 1283 }
1284 if (m_pParser->m_V5Type[objnum] == 2) { 1284 if (m_pParser->m_V5Type[objnum] == 2) {
1285 if (m_pXRefStream) { 1285 if (m_pXRefStream) {
1286 if (WriteIndirectObjectToStream(objnum, pBuffer, size) < 0) { 1286 if (WriteIndirectObjectToStream(objnum, pBuffer, size) < 0) {
1287 FX_Free(pBuffer); 1287 FX_Free(pBuffer);
1288 return -1; 1288 return -1;
1289 } 1289 }
1290 } else { 1290 } else {
1291 int32_t len = m_File.AppendDWord(objnum); 1291 int32_t len = m_File.AppendDWord(objnum);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 break; 1470 break;
1471 } 1471 }
1472 iStart = iMid + 1; 1472 iStart = iMid + 1;
1473 } 1473 }
1474 } 1474 }
1475 m_NewObjNumArray.InsertAt(iFind, objbum); 1475 m_NewObjNumArray.InsertAt(iFind, objbum);
1476 } 1476 }
1477 int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) { 1477 int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) {
1478 FXSYS_assert(m_iStage > -1 || m_iStage < 20); 1478 FXSYS_assert(m_iStage > -1 || m_iStage < 20);
1479 if (m_iStage == 0) { 1479 if (m_iStage == 0) {
1480 if (m_pParser == NULL) { 1480 if (!m_pParser) {
1481 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; 1481 m_dwFlags &= ~FPDFCREATE_INCREMENTAL;
1482 } 1482 }
1483 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { 1483 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) {
1484 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; 1484 m_dwFlags &= ~FPDFCREATE_INCREMENTAL;
1485 } 1485 }
1486 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); 1486 CPDF_Dictionary* pDict = m_pDocument->GetRoot();
1487 m_pMetadata = pDict ? pDict->GetElementValue("Metadata") : NULL; 1487 m_pMetadata = pDict ? pDict->GetElementValue("Metadata") : NULL;
1488 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { 1488 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) {
1489 m_pXRefStream = new CPDF_XRefStream; 1489 m_pXRefStream = new CPDF_XRefStream;
1490 m_pXRefStream->Start(); 1490 m_pXRefStream->Start();
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 m_bNewCrypto = FALSE; 2103 m_bNewCrypto = FALSE;
2104 if (!m_bStandardSecurity) { 2104 if (!m_bStandardSecurity) {
2105 return; 2105 return;
2106 } 2106 }
2107 if (m_pEncryptDict) { 2107 if (m_pEncryptDict) {
2108 m_pEncryptDict->Release(); 2108 m_pEncryptDict->Release();
2109 m_pEncryptDict = NULL; 2109 m_pEncryptDict = NULL;
2110 } 2110 }
2111 m_bStandardSecurity = FALSE; 2111 m_bStandardSecurity = FALSE;
2112 } 2112 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp ('k') | core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698