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

Side by Side Diff: nss/lib/util/secitem.c

Issue 13898013: Update NSS to NSS_3_15_BETA2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Update NSS versions and tag in README.chromium Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 /* 5 /*
6 * Support routines for SECItem data structure. 6 * Support routines for SECItem data structure.
7 * 7 *
8 * $Id: secitem.c,v 1.18 2012/04/25 14:50:16 gerv%gerv.net Exp $ 8 * $Id$
9 */ 9 */
10 10
11 #include "seccomon.h" 11 #include "seccomon.h"
12 #include "secitem.h" 12 #include "secitem.h"
13 #include "base64.h" 13 #include "base64.h"
14 #include "secerr.h" 14 #include "secerr.h"
15 #include "secport.h"
15 16
16 SECItem * 17 SECItem *
17 SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len) 18 SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len)
18 { 19 {
19 SECItem *result = NULL; 20 SECItem *result = NULL;
20 void *mark = NULL; 21 void *mark = NULL;
21 22
22 if (arena != NULL) { 23 if (arena != NULL) {
23 mark = PORT_ArenaMark(arena); 24 mark = PORT_ArenaMark(arena);
24 } 25 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 * but heck it's only used internally by the hash table anyway. 288 * but heck it's only used internally by the hash table anyway.
288 */ 289 */
289 PRIntn PR_CALLBACK 290 PRIntn PR_CALLBACK
290 SECITEM_HashCompare ( const void *k1, const void *k2) 291 SECITEM_HashCompare ( const void *k1, const void *k2)
291 { 292 {
292 const SECItem *i1 = (const SECItem *)k1; 293 const SECItem *i1 = (const SECItem *)k1;
293 const SECItem *i2 = (const SECItem *)k2; 294 const SECItem *i2 = (const SECItem *)k2;
294 295
295 return SECITEM_ItemsAreEqual(i1,i2); 296 return SECITEM_ItemsAreEqual(i1,i2);
296 } 297 }
298
299 SECItemArray *
300 SECITEM_AllocArray(PLArenaPool *arena, SECItemArray *array, unsigned int len)
301 {
302 SECItemArray *result = NULL;
303 void *mark = NULL;
304
305 if (arena != NULL) {
306 mark = PORT_ArenaMark(arena);
307 }
308
309 if (array == NULL) {
310 if (arena != NULL) {
311 result = PORT_ArenaZAlloc(arena, sizeof(SECItemArray));
312 } else {
313 result = PORT_ZAlloc(sizeof(SECItemArray));
314 }
315 if (result == NULL) {
316 goto loser;
317 }
318 } else {
319 PORT_Assert(array->items == NULL);
320 result = array;
321 }
322
323 result->len = len;
324 if (len) {
325 if (arena != NULL) {
326 result->items = PORT_ArenaZNewArray(arena, SECItem, len);
327 } else {
328 result->items = PORT_ZNewArray(SECItem, len);
329 }
330 if (result->items == NULL) {
331 goto loser;
332 }
333 } else {
334 result->items = NULL;
335 }
336
337 if (mark) {
338 PORT_ArenaUnmark(arena, mark);
339 }
340 return(result);
341
342 loser:
343 if ( arena != NULL ) {
344 if (mark) {
345 PORT_ArenaRelease(arena, mark);
346 }
347 if (array != NULL) {
348 array->items = NULL;
349 array->len = 0;
350 }
351 } else {
352 if (result != NULL && array == NULL) {
353 PORT_Free(result);
354 }
355 /*
356 * If array is not NULL, the above has set array->data and
wtc 2013/04/24 22:49:45 This comment needs to be updated to say array->ite
357 * array->len to 0.
358 */
359 }
360 return(NULL);
361 }
362
363 void secitem_FreeArray(SECItemArray *array, PRBool zero_items, PRBool freeit)
wtc 2013/04/24 22:49:45 Mark this static.
364 {
365 unsigned int i;
366
367 if (!array || !array->len || !array->items)
368 return;
369
370 for (i=0; i<array->len; ++i) {
wtc 2013/04/24 22:49:45 Add spaces around operators.
371 SECItem *item = &array->items[i];
372
373 if (item->data) {
374 if (zero_items) {
375 SECITEM_ZfreeItem(item, PR_FALSE);
376 } else {
377 SECITEM_FreeItem(item, PR_FALSE);
378 }
379 }
380 }
381
wtc 2013/04/24 22:49:45 BUG: array->items also needs to be freed.
382 if (freeit)
383 PORT_Free(array);
384 }
385
386 void SECITEM_FreeArray(SECItemArray *array, PRBool freeit)
387 {
388 secitem_FreeArray(array, PR_FALSE, freeit);
389 }
390
391 void SECITEM_ZfreeArray(SECItemArray *array, PRBool freeit)
392 {
393 secitem_FreeArray(array, PR_TRUE, freeit);
394 }
395
396 SECItemArray *
397 SECITEM_DupArray(PLArenaPool *arena, const SECItemArray *from)
398 {
399 SECItemArray *result;
400 unsigned int i;
401
402 if (!from || !from->items || !from->len)
wtc 2013/04/24 22:49:45 I think it is legal for from->items to be NULL.
403 return NULL;
404
405 result = SECITEM_AllocArray(arena, NULL, from->len);
406 if (!result)
407 return NULL;
408
409 for (i=0; i<from->len; ++i) {
wtc 2013/04/24 22:49:45 Add spaces around operators.
410 SECStatus rv = SECITEM_CopyItem(arena,
411 &result->items[i], &from->items[i]);
412 if (rv != SECSuccess) {
413 SECITEM_ZfreeArray(result, PR_TRUE);
414 return NULL;
415 }
416 }
417
418 return result;
419 }
OLDNEW
« nss/lib/util/secitem.h ('K') | « nss/lib/util/secitem.h ('k') | nss/lib/util/secoid.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698