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

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

Issue 1512763013: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits 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
« no previous file with comments | « core/src/fxcrt/fx_basic_wstring.cpp ('k') | core/src/fxcrt/fx_xml_parser.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 "core/include/fxcrt/fx_basic.h" 7 #include "core/include/fxcrt/fx_basic.h"
8 #include "core/include/fxcrt/fx_ext.h" 8 #include "core/include/fxcrt/fx_ext.h"
9 #include "extension.h" 9 #include "extension.h"
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 FX_FLOAT FXSYS_tan(FX_FLOAT a) { 55 FX_FLOAT FXSYS_tan(FX_FLOAT a) {
56 return (FX_FLOAT)tan(a); 56 return (FX_FLOAT)tan(a);
57 } 57 }
58 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) { 58 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) {
59 return FXSYS_log(x) / FXSYS_log(b); 59 return FXSYS_log(x) / FXSYS_log(b);
60 } 60 }
61 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 61 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
62 int32_t iLength, 62 int32_t iLength,
63 int32_t* pUsedLen) { 63 int32_t* pUsedLen) {
64 FXSYS_assert(pcsStr != NULL); 64 FXSYS_assert(pcsStr);
65 if (iLength < 0) { 65 if (iLength < 0) {
66 iLength = (int32_t)FXSYS_strlen(pcsStr); 66 iLength = (int32_t)FXSYS_strlen(pcsStr);
67 } 67 }
68 CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength); 68 CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength);
69 return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen); 69 return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen);
70 } 70 }
71 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, 71 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr,
72 int32_t iLength, 72 int32_t iLength,
73 int32_t* pUsedLen) { 73 int32_t* pUsedLen) {
74 FXSYS_assert(pwsStr != NULL); 74 FXSYS_assert(pwsStr);
75 if (iLength < 0) { 75 if (iLength < 0) {
76 iLength = (int32_t)FXSYS_wcslen(pwsStr); 76 iLength = (int32_t)FXSYS_wcslen(pwsStr);
77 } 77 }
78 if (iLength == 0) { 78 if (iLength == 0) {
79 return 0.0f; 79 return 0.0f;
80 } 80 }
81 int32_t iUsedLen = 0; 81 int32_t iUsedLen = 0;
82 FX_BOOL bNegtive = FALSE; 82 FX_BOOL bNegtive = FALSE;
83 switch (pwsStr[iUsedLen]) { 83 switch (pwsStr[iUsedLen]) {
84 case '-': 84 case '-':
(...skipping 25 matching lines...) Expand all
110 } 110 }
111 } 111 }
112 if (pUsedLen) { 112 if (pUsedLen) {
113 *pUsedLen = iUsedLen; 113 *pUsedLen = iUsedLen;
114 } 114 }
115 return bNegtive ? -fValue : fValue; 115 return bNegtive ? -fValue : fValue;
116 } 116 }
117 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, 117 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr,
118 const FX_WCHAR* srcStr, 118 const FX_WCHAR* srcStr,
119 size_t count) { 119 size_t count) {
120 FXSYS_assert(dstStr != NULL && srcStr != NULL && count > 0); 120 FXSYS_assert(dstStr && srcStr && count > 0);
121 for (size_t i = 0; i < count; ++i) 121 for (size_t i = 0; i < count; ++i)
122 if ((dstStr[i] = srcStr[i]) == L'\0') { 122 if ((dstStr[i] = srcStr[i]) == L'\0') {
123 break; 123 break;
124 } 124 }
125 return dstStr; 125 return dstStr;
126 } 126 }
127 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count) { 127 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count) {
128 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); 128 FXSYS_assert(s1 && s2 && count > 0);
129 FX_WCHAR wch1 = 0, wch2 = 0; 129 FX_WCHAR wch1 = 0, wch2 = 0;
130 while (count-- > 0) { 130 while (count-- > 0) {
131 wch1 = (FX_WCHAR)FXSYS_tolower(*s1++); 131 wch1 = (FX_WCHAR)FXSYS_tolower(*s1++);
132 wch2 = (FX_WCHAR)FXSYS_tolower(*s2++); 132 wch2 = (FX_WCHAR)FXSYS_tolower(*s2++);
133 if (wch1 != wch2) { 133 if (wch1 != wch2) {
134 break; 134 break;
135 } 135 }
136 } 136 }
137 return wch1 - wch2; 137 return wch1 - wch2;
138 } 138 }
139 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count) { 139 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count) {
140 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); 140 FXSYS_assert(s1 && s2 && count > 0);
141 FX_CHAR ch1 = 0, ch2 = 0; 141 FX_CHAR ch1 = 0, ch2 = 0;
142 while (count-- > 0) { 142 while (count-- > 0) {
143 ch1 = (FX_CHAR)FXSYS_tolower(*s1++); 143 ch1 = (FX_CHAR)FXSYS_tolower(*s1++);
144 ch2 = (FX_CHAR)FXSYS_tolower(*s2++); 144 ch2 = (FX_CHAR)FXSYS_tolower(*s2++);
145 if (ch1 != ch2) { 145 if (ch1 != ch2) {
146 break; 146 break;
147 } 147 }
148 } 148 }
149 return ch1 - ch2; 149 return ch1 - ch2;
150 } 150 }
151 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, 151 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr,
152 int32_t iLength, 152 int32_t iLength,
153 FX_BOOL bIgnoreCase) { 153 FX_BOOL bIgnoreCase) {
154 FXSYS_assert(pStr != NULL); 154 FXSYS_assert(pStr);
155 if (iLength < 0) { 155 if (iLength < 0) {
156 iLength = (int32_t)FXSYS_strlen(pStr); 156 iLength = (int32_t)FXSYS_strlen(pStr);
157 } 157 }
158 const FX_CHAR* pStrEnd = pStr + iLength; 158 const FX_CHAR* pStrEnd = pStr + iLength;
159 FX_DWORD dwHashCode = 0; 159 FX_DWORD dwHashCode = 0;
160 if (bIgnoreCase) { 160 if (bIgnoreCase) {
161 while (pStr < pStrEnd) { 161 while (pStr < pStrEnd) {
162 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++); 162 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++);
163 } 163 }
164 } else { 164 } else {
165 while (pStr < pStrEnd) { 165 while (pStr < pStrEnd) {
166 dwHashCode = 31 * dwHashCode + *pStr++; 166 dwHashCode = 31 * dwHashCode + *pStr++;
167 } 167 }
168 } 168 }
169 return dwHashCode; 169 return dwHashCode;
170 } 170 }
171 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, 171 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
172 int32_t iLength, 172 int32_t iLength,
173 FX_BOOL bIgnoreCase) { 173 FX_BOOL bIgnoreCase) {
174 FXSYS_assert(pStr != NULL); 174 FXSYS_assert(pStr);
175 if (iLength < 0) { 175 if (iLength < 0) {
176 iLength = (int32_t)FXSYS_wcslen(pStr); 176 iLength = (int32_t)FXSYS_wcslen(pStr);
177 } 177 }
178 const FX_WCHAR* pStrEnd = pStr + iLength; 178 const FX_WCHAR* pStrEnd = pStr + iLength;
179 FX_DWORD dwHashCode = 0; 179 FX_DWORD dwHashCode = 0;
180 if (bIgnoreCase) { 180 if (bIgnoreCase) {
181 while (pStr < pStrEnd) { 181 while (pStr < pStrEnd) {
182 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++); 182 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++);
183 } 183 }
184 } else { 184 } else {
185 while (pStr < pStrEnd) { 185 while (pStr < pStrEnd) {
186 dwHashCode = 1313 * dwHashCode + *pStr++; 186 dwHashCode = 1313 * dwHashCode + *pStr++;
187 } 187 }
188 } 188 }
189 return dwHashCode; 189 return dwHashCode;
190 } 190 }
191 191
192 void* FX_Random_MT_Start(FX_DWORD dwSeed) { 192 void* FX_Random_MT_Start(FX_DWORD dwSeed) {
193 FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1); 193 FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1);
194 pContext->mt[0] = dwSeed; 194 pContext->mt[0] = dwSeed;
195 FX_DWORD& i = pContext->mti; 195 FX_DWORD& i = pContext->mti;
196 FX_DWORD* pBuf = pContext->mt; 196 FX_DWORD* pBuf = pContext->mt;
197 for (i = 1; i < MT_N; i++) { 197 for (i = 1; i < MT_N; i++) {
198 pBuf[i] = (1812433253UL * (pBuf[i - 1] ^ (pBuf[i - 1] >> 30)) + i); 198 pBuf[i] = (1812433253UL * (pBuf[i - 1] ^ (pBuf[i - 1] >> 30)) + i);
199 } 199 }
200 pContext->bHaveSeed = TRUE; 200 pContext->bHaveSeed = TRUE;
201 return pContext; 201 return pContext;
202 } 202 }
203 FX_DWORD FX_Random_MT_Generate(void* pContext) { 203 FX_DWORD FX_Random_MT_Generate(void* pContext) {
204 FXSYS_assert(pContext != NULL); 204 FXSYS_assert(pContext);
205 FX_LPMTRANDOMCONTEXT pMTC = (FX_LPMTRANDOMCONTEXT)pContext; 205 FX_LPMTRANDOMCONTEXT pMTC = (FX_LPMTRANDOMCONTEXT)pContext;
206 FX_DWORD v; 206 FX_DWORD v;
207 static FX_DWORD mag[2] = {0, MT_Matrix_A}; 207 static FX_DWORD mag[2] = {0, MT_Matrix_A};
208 FX_DWORD& mti = pMTC->mti; 208 FX_DWORD& mti = pMTC->mti;
209 FX_DWORD* pBuf = pMTC->mt; 209 FX_DWORD* pBuf = pMTC->mt;
210 if ((int)mti < 0 || mti >= MT_N) { 210 if ((int)mti < 0 || mti >= MT_N) {
211 if (mti > MT_N && !pMTC->bHaveSeed) { 211 if (mti > MT_N && !pMTC->bHaveSeed) {
212 return 0; 212 return 0;
213 } 213 }
214 FX_DWORD kk; 214 FX_DWORD kk;
(...skipping 10 matching lines...) Expand all
225 mti = 0; 225 mti = 0;
226 } 226 }
227 v = pBuf[mti++]; 227 v = pBuf[mti++];
228 v ^= (v >> 11); 228 v ^= (v >> 11);
229 v ^= (v << 7) & 0x9d2c5680UL; 229 v ^= (v << 7) & 0x9d2c5680UL;
230 v ^= (v << 15) & 0xefc60000UL; 230 v ^= (v << 15) & 0xefc60000UL;
231 v ^= (v >> 18); 231 v ^= (v >> 18);
232 return v; 232 return v;
233 } 233 }
234 void FX_Random_MT_Close(void* pContext) { 234 void FX_Random_MT_Close(void* pContext) {
235 FXSYS_assert(pContext != NULL); 235 FXSYS_assert(pContext);
236 FX_Free(pContext); 236 FX_Free(pContext);
237 } 237 }
238 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount) { 238 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount) {
239 FX_DWORD dwSeed; 239 FX_DWORD dwSeed;
240 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 240 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
241 if (!FX_GenerateCryptoRandom(&dwSeed, 1)) { 241 if (!FX_GenerateCryptoRandom(&dwSeed, 1)) {
242 FX_Random_GenerateBase(&dwSeed, 1); 242 FX_Random_GenerateBase(&dwSeed, 1);
243 } 243 }
244 #else 244 #else
245 FX_Random_GenerateBase(&dwSeed, 1); 245 FX_Random_GenerateBase(&dwSeed, 1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 return TRUE; 284 return TRUE;
285 } 285 }
286 #endif 286 #endif
287 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) { 287 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) {
288 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 288 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
289 FX_GenerateCryptoRandom(pBuffer, iCount); 289 FX_GenerateCryptoRandom(pBuffer, iCount);
290 #else 290 #else
291 FX_Random_GenerateBase(pBuffer, iCount); 291 FX_Random_GenerateBase(pBuffer, iCount);
292 #endif 292 #endif
293 } 293 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_wstring.cpp ('k') | core/src/fxcrt/fx_xml_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698