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

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

Issue 1529553003: Merge to XFA: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 FX_FLOAT FXSYS_tan(FX_FLOAT a) { 70 FX_FLOAT FXSYS_tan(FX_FLOAT a) {
71 return (FX_FLOAT)tan(a); 71 return (FX_FLOAT)tan(a);
72 } 72 }
73 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) { 73 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) {
74 return FXSYS_log(x) / FXSYS_log(b); 74 return FXSYS_log(x) / FXSYS_log(b);
75 } 75 }
76 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 76 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
77 int32_t iLength, 77 int32_t iLength,
78 int32_t* pUsedLen) { 78 int32_t* pUsedLen) {
79 FXSYS_assert(pcsStr != NULL); 79 FXSYS_assert(pcsStr);
80 if (iLength < 0) { 80 if (iLength < 0) {
81 iLength = (int32_t)FXSYS_strlen(pcsStr); 81 iLength = (int32_t)FXSYS_strlen(pcsStr);
82 } 82 }
83 CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength); 83 CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength);
84 return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen); 84 return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen);
85 } 85 }
86 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, 86 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr,
87 int32_t iLength, 87 int32_t iLength,
88 int32_t* pUsedLen) { 88 int32_t* pUsedLen) {
89 FXSYS_assert(pwsStr != NULL); 89 FXSYS_assert(pwsStr);
90 if (iLength < 0) { 90 if (iLength < 0) {
91 iLength = (int32_t)FXSYS_wcslen(pwsStr); 91 iLength = (int32_t)FXSYS_wcslen(pwsStr);
92 } 92 }
93 if (iLength == 0) { 93 if (iLength == 0) {
94 return 0.0f; 94 return 0.0f;
95 } 95 }
96 int32_t iUsedLen = 0; 96 int32_t iUsedLen = 0;
97 FX_BOOL bNegtive = FALSE; 97 FX_BOOL bNegtive = FALSE;
98 switch (pwsStr[iUsedLen]) { 98 switch (pwsStr[iUsedLen]) {
99 case '-': 99 case '-':
(...skipping 25 matching lines...) Expand all
125 } 125 }
126 } 126 }
127 if (pUsedLen) { 127 if (pUsedLen) {
128 *pUsedLen = iUsedLen; 128 *pUsedLen = iUsedLen;
129 } 129 }
130 return bNegtive ? -fValue : fValue; 130 return bNegtive ? -fValue : fValue;
131 } 131 }
132 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, 132 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr,
133 const FX_WCHAR* srcStr, 133 const FX_WCHAR* srcStr,
134 size_t count) { 134 size_t count) {
135 FXSYS_assert(dstStr != NULL && srcStr != NULL && count > 0); 135 FXSYS_assert(dstStr && srcStr && count > 0);
136 for (size_t i = 0; i < count; ++i) 136 for (size_t i = 0; i < count; ++i)
137 if ((dstStr[i] = srcStr[i]) == L'\0') { 137 if ((dstStr[i] = srcStr[i]) == L'\0') {
138 break; 138 break;
139 } 139 }
140 return dstStr; 140 return dstStr;
141 } 141 }
142 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count) { 142 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count) {
143 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); 143 FXSYS_assert(s1 && s2 && count > 0);
144 FX_WCHAR wch1 = 0, wch2 = 0; 144 FX_WCHAR wch1 = 0, wch2 = 0;
145 while (count-- > 0) { 145 while (count-- > 0) {
146 wch1 = (FX_WCHAR)FXSYS_tolower(*s1++); 146 wch1 = (FX_WCHAR)FXSYS_tolower(*s1++);
147 wch2 = (FX_WCHAR)FXSYS_tolower(*s2++); 147 wch2 = (FX_WCHAR)FXSYS_tolower(*s2++);
148 if (wch1 != wch2) { 148 if (wch1 != wch2) {
149 break; 149 break;
150 } 150 }
151 } 151 }
152 return wch1 - wch2; 152 return wch1 - wch2;
153 } 153 }
154 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count) { 154 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count) {
155 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); 155 FXSYS_assert(s1 && s2 && count > 0);
156 FX_CHAR ch1 = 0, ch2 = 0; 156 FX_CHAR ch1 = 0, ch2 = 0;
157 while (count-- > 0) { 157 while (count-- > 0) {
158 ch1 = (FX_CHAR)FXSYS_tolower(*s1++); 158 ch1 = (FX_CHAR)FXSYS_tolower(*s1++);
159 ch2 = (FX_CHAR)FXSYS_tolower(*s2++); 159 ch2 = (FX_CHAR)FXSYS_tolower(*s2++);
160 if (ch1 != ch2) { 160 if (ch1 != ch2) {
161 break; 161 break;
162 } 162 }
163 } 163 }
164 return ch1 - ch2; 164 return ch1 - ch2;
165 } 165 }
166 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, 166 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr,
167 int32_t iLength, 167 int32_t iLength,
168 FX_BOOL bIgnoreCase) { 168 FX_BOOL bIgnoreCase) {
169 FXSYS_assert(pStr != NULL); 169 FXSYS_assert(pStr);
170 if (iLength < 0) { 170 if (iLength < 0) {
171 iLength = (int32_t)FXSYS_strlen(pStr); 171 iLength = (int32_t)FXSYS_strlen(pStr);
172 } 172 }
173 const FX_CHAR* pStrEnd = pStr + iLength; 173 const FX_CHAR* pStrEnd = pStr + iLength;
174 FX_DWORD dwHashCode = 0; 174 FX_DWORD dwHashCode = 0;
175 if (bIgnoreCase) { 175 if (bIgnoreCase) {
176 while (pStr < pStrEnd) { 176 while (pStr < pStrEnd) {
177 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++); 177 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++);
178 } 178 }
179 } else { 179 } else {
180 while (pStr < pStrEnd) { 180 while (pStr < pStrEnd) {
181 dwHashCode = 31 * dwHashCode + *pStr++; 181 dwHashCode = 31 * dwHashCode + *pStr++;
182 } 182 }
183 } 183 }
184 return dwHashCode; 184 return dwHashCode;
185 } 185 }
186 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, 186 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
187 int32_t iLength, 187 int32_t iLength,
188 FX_BOOL bIgnoreCase) { 188 FX_BOOL bIgnoreCase) {
189 FXSYS_assert(pStr != NULL); 189 FXSYS_assert(pStr);
190 if (iLength < 0) { 190 if (iLength < 0) {
191 iLength = (int32_t)FXSYS_wcslen(pStr); 191 iLength = (int32_t)FXSYS_wcslen(pStr);
192 } 192 }
193 const FX_WCHAR* pStrEnd = pStr + iLength; 193 const FX_WCHAR* pStrEnd = pStr + iLength;
194 FX_DWORD dwHashCode = 0; 194 FX_DWORD dwHashCode = 0;
195 if (bIgnoreCase) { 195 if (bIgnoreCase) {
196 while (pStr < pStrEnd) { 196 while (pStr < pStrEnd) {
197 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++); 197 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++);
198 } 198 }
199 } else { 199 } else {
200 while (pStr < pStrEnd) { 200 while (pStr < pStrEnd) {
201 dwHashCode = 1313 * dwHashCode + *pStr++; 201 dwHashCode = 1313 * dwHashCode + *pStr++;
202 } 202 }
203 } 203 }
204 return dwHashCode; 204 return dwHashCode;
205 } 205 }
206 206
207 void* FX_Random_MT_Start(FX_DWORD dwSeed) { 207 void* FX_Random_MT_Start(FX_DWORD dwSeed) {
208 FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1); 208 FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1);
209 pContext->mt[0] = dwSeed; 209 pContext->mt[0] = dwSeed;
210 FX_DWORD& i = pContext->mti; 210 FX_DWORD& i = pContext->mti;
211 FX_DWORD* pBuf = pContext->mt; 211 FX_DWORD* pBuf = pContext->mt;
212 for (i = 1; i < MT_N; i++) { 212 for (i = 1; i < MT_N; i++) {
213 pBuf[i] = (1812433253UL * (pBuf[i - 1] ^ (pBuf[i - 1] >> 30)) + i); 213 pBuf[i] = (1812433253UL * (pBuf[i - 1] ^ (pBuf[i - 1] >> 30)) + i);
214 } 214 }
215 pContext->bHaveSeed = TRUE; 215 pContext->bHaveSeed = TRUE;
216 return pContext; 216 return pContext;
217 } 217 }
218 FX_DWORD FX_Random_MT_Generate(void* pContext) { 218 FX_DWORD FX_Random_MT_Generate(void* pContext) {
219 FXSYS_assert(pContext != NULL); 219 FXSYS_assert(pContext);
220 FX_LPMTRANDOMCONTEXT pMTC = (FX_LPMTRANDOMCONTEXT)pContext; 220 FX_LPMTRANDOMCONTEXT pMTC = (FX_LPMTRANDOMCONTEXT)pContext;
221 FX_DWORD v; 221 FX_DWORD v;
222 static FX_DWORD mag[2] = {0, MT_Matrix_A}; 222 static FX_DWORD mag[2] = {0, MT_Matrix_A};
223 FX_DWORD& mti = pMTC->mti; 223 FX_DWORD& mti = pMTC->mti;
224 FX_DWORD* pBuf = pMTC->mt; 224 FX_DWORD* pBuf = pMTC->mt;
225 if ((int)mti < 0 || mti >= MT_N) { 225 if ((int)mti < 0 || mti >= MT_N) {
226 if (mti > MT_N && !pMTC->bHaveSeed) { 226 if (mti > MT_N && !pMTC->bHaveSeed) {
227 return 0; 227 return 0;
228 } 228 }
229 FX_DWORD kk; 229 FX_DWORD kk;
(...skipping 10 matching lines...) Expand all
240 mti = 0; 240 mti = 0;
241 } 241 }
242 v = pBuf[mti++]; 242 v = pBuf[mti++];
243 v ^= (v >> 11); 243 v ^= (v >> 11);
244 v ^= (v << 7) & 0x9d2c5680UL; 244 v ^= (v << 7) & 0x9d2c5680UL;
245 v ^= (v << 15) & 0xefc60000UL; 245 v ^= (v << 15) & 0xefc60000UL;
246 v ^= (v >> 18); 246 v ^= (v >> 18);
247 return v; 247 return v;
248 } 248 }
249 void FX_Random_MT_Close(void* pContext) { 249 void FX_Random_MT_Close(void* pContext) {
250 FXSYS_assert(pContext != NULL); 250 FXSYS_assert(pContext);
251 FX_Free(pContext); 251 FX_Free(pContext);
252 } 252 }
253 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount) { 253 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount) {
254 FX_DWORD dwSeed; 254 FX_DWORD dwSeed;
255 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 255 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
256 if (!FX_GenerateCryptoRandom(&dwSeed, 1)) { 256 if (!FX_GenerateCryptoRandom(&dwSeed, 1)) {
257 FX_Random_GenerateBase(&dwSeed, 1); 257 FX_Random_GenerateBase(&dwSeed, 1);
258 } 258 }
259 #else 259 #else
260 FX_Random_GenerateBase(&dwSeed, 1); 260 FX_Random_GenerateBase(&dwSeed, 1);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 b = ((const uint8_t*)pGUID)[i]; 334 b = ((const uint8_t*)pGUID)[i];
335 *pBuf++ = gs_FX_pHexChars[b >> 4]; 335 *pBuf++ = gs_FX_pHexChars[b >> 4];
336 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; 336 *pBuf++ = gs_FX_pHexChars[b & 0x0F];
337 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { 337 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
338 *pBuf++ = L'-'; 338 *pBuf++ = L'-';
339 } 339 }
340 } 340 }
341 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); 341 bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
342 } 342 }
343 #endif // PDF_ENABLE_XFA 343 #endif // PDF_ENABLE_XFA
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698