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

Side by Side Diff: core/fxcrt/fx_extension.cpp

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 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/fxcrt/fx_basic_maps.cpp ('k') | core/fxcrt/fxcrt_windows.cpp » ('j') | 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 <utility> 7 #include <utility>
8 8
9 #include "core/fxcrt/extension.h" 9 #include "core/fxcrt/extension.h"
10 #include "core/fxcrt/include/fx_basic.h" 10 #include "core/fxcrt/include/fx_basic.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); 61 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
62 } 62 }
63 63
64 FX_BOOL CFX_CRTFileStream::Flush() { 64 FX_BOOL CFX_CRTFileStream::Flush() {
65 return m_pFile->Flush(); 65 return m_pFile->Flush();
66 } 66 }
67 67
68 #ifdef PDF_ENABLE_XFA 68 #ifdef PDF_ENABLE_XFA
69 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { 69 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) {
70 if (wsPath.GetLength() == 0) 70 if (wsPath.GetLength() == 0)
71 return NULL; 71 return nullptr;
72 72
73 CFX_CRTFileAccess* pFA = NULL; 73 CFX_CRTFileAccess* pFA = new CFX_CRTFileAccess;
74 pFA = new CFX_CRTFileAccess;
75 if (NULL == pFA)
76 return NULL;
77
78 pFA->Init(wsPath); 74 pFA->Init(wsPath);
79 return pFA; 75 return pFA;
80 } 76 }
81 #endif // PDF_ENABLE_XFA 77 #endif // PDF_ENABLE_XFA
82 78
83 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { 79 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) {
84 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); 80 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
85 if (!pFA->Open(filename, dwModes)) 81 if (!pFA->Open(filename, dwModes))
86 return nullptr; 82 return nullptr;
87 return new CFX_CRTFileStream(std::move(pFA)); 83 return new CFX_CRTFileStream(std::move(pFA));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 ::GetSystemTime(&st1); 294 ::GetSystemTime(&st1);
299 do { 295 do {
300 ::GetSystemTime(&st2); 296 ::GetSystemTime(&st2);
301 } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0); 297 } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0);
302 uint32_t dwHash1 = 298 uint32_t dwHash1 =
303 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true); 299 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true);
304 uint32_t dwHash2 = 300 uint32_t dwHash2 =
305 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true); 301 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true);
306 ::srand((dwHash1 << 16) | (uint32_t)dwHash2); 302 ::srand((dwHash1 << 16) | (uint32_t)dwHash2);
307 #else 303 #else
308 time_t tmLast = time(NULL); 304 time_t tmLast = time(nullptr);
309 time_t tmCur; 305 time_t tmCur;
310 while ((tmCur = time(NULL)) == tmLast) { 306 while ((tmCur = time(nullptr)) == tmLast) {
311 continue; 307 continue;
312 } 308 }
313 309
314 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); 310 ::srand((tmCur << 16) | (tmLast & 0xFFFF));
315 #endif 311 #endif
316 while (iCount-- > 0) { 312 while (iCount-- > 0) {
317 *pBuffer++ = (uint32_t)((::rand() << 16) | (::rand() & 0xFFFF)); 313 *pBuffer++ = (uint32_t)((::rand() << 16) | (::rand() & 0xFFFF));
318 } 314 }
319 } 315 }
320 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 316 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
321 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount) { 317 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount) {
322 HCRYPTPROV hCP = NULL; 318 HCRYPTPROV hCP = 0;
323 if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || !hCP) { 319 if (!::CryptAcquireContext(&hCP, nullptr, nullptr, PROV_RSA_FULL, 0) ||
320 !hCP) {
324 return FALSE; 321 return FALSE;
325 } 322 }
326 ::CryptGenRandom(hCP, iCount * sizeof(uint32_t), (uint8_t*)pBuffer); 323 ::CryptGenRandom(hCP, iCount * sizeof(uint32_t), (uint8_t*)pBuffer);
327 ::CryptReleaseContext(hCP, 0); 324 ::CryptReleaseContext(hCP, 0);
328 return TRUE; 325 return TRUE;
329 } 326 }
330 #endif 327 #endif
331 void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount) { 328 void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount) {
332 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 329 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
333 FX_GenerateCryptoRandom(pBuffer, iCount); 330 FX_GenerateCryptoRandom(pBuffer, iCount);
(...skipping 18 matching lines...) Expand all
352 b = ((const uint8_t*)pGUID)[i]; 349 b = ((const uint8_t*)pGUID)[i];
353 *pBuf++ = gs_FX_pHexChars[b >> 4]; 350 *pBuf++ = gs_FX_pHexChars[b >> 4];
354 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; 351 *pBuf++ = gs_FX_pHexChars[b & 0x0F];
355 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { 352 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
356 *pBuf++ = L'-'; 353 *pBuf++ = L'-';
357 } 354 }
358 } 355 }
359 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); 356 bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
360 } 357 }
361 #endif // PDF_ENABLE_XFA 358 #endif // PDF_ENABLE_XFA
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_maps.cpp ('k') | core/fxcrt/fxcrt_windows.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698