summaryrefslogtreecommitdiff
path: root/nss/lib/util/secitem.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-01-04 14:24:24 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-01-04 14:24:24 +0000
commitdc1565216a5d20ae0d75872151523252309a1292 (patch)
treed57454ba9a40386552179eddf60d28bd1e8f3d54 /nss/lib/util/secitem.c
parent26c046fbc57d53136b4fb3b5e0d18298318125d4 (diff)
downloadnss-dc1565216a5d20ae0d75872151523252309a1292.tar.gz
nss-3.28.1nss-3.28.1
Diffstat (limited to 'nss/lib/util/secitem.c')
-rw-r--r--nss/lib/util/secitem.c326
1 files changed, 164 insertions, 162 deletions
diff --git a/nss/lib/util/secitem.c b/nss/lib/util/secitem.c
index 49364c7..22c5b1f 100644
--- a/nss/lib/util/secitem.c
+++ b/nss/lib/util/secitem.c
@@ -18,98 +18,98 @@ SECITEM_AllocItem(PLArenaPool *arena, SECItem *item, unsigned int len)
void *mark = NULL;
if (arena != NULL) {
- mark = PORT_ArenaMark(arena);
+ mark = PORT_ArenaMark(arena);
}
if (item == NULL) {
- if (arena != NULL) {
- result = PORT_ArenaZAlloc(arena, sizeof(SECItem));
- } else {
- result = PORT_ZAlloc(sizeof(SECItem));
- }
- if (result == NULL) {
- goto loser;
- }
+ if (arena != NULL) {
+ result = PORT_ArenaZAlloc(arena, sizeof(SECItem));
+ } else {
+ result = PORT_ZAlloc(sizeof(SECItem));
+ }
+ if (result == NULL) {
+ goto loser;
+ }
} else {
- PORT_Assert(item->data == NULL);
- result = item;
+ PORT_Assert(item->data == NULL);
+ result = item;
}
result->len = len;
if (len) {
- if (arena != NULL) {
- result->data = PORT_ArenaAlloc(arena, len);
- } else {
- result->data = PORT_Alloc(len);
- }
- if (result->data == NULL) {
- goto loser;
- }
+ if (arena != NULL) {
+ result->data = PORT_ArenaAlloc(arena, len);
+ } else {
+ result->data = PORT_Alloc(len);
+ }
+ if (result->data == NULL) {
+ goto loser;
+ }
} else {
- result->data = NULL;
+ result->data = NULL;
}
if (mark) {
- PORT_ArenaUnmark(arena, mark);
+ PORT_ArenaUnmark(arena, mark);
}
- return(result);
+ return (result);
loser:
- if ( arena != NULL ) {
- if (mark) {
- PORT_ArenaRelease(arena, mark);
- }
- if (item != NULL) {
- item->data = NULL;
- item->len = 0;
- }
+ if (arena != NULL) {
+ if (mark) {
+ PORT_ArenaRelease(arena, mark);
+ }
+ if (item != NULL) {
+ item->data = NULL;
+ item->len = 0;
+ }
} else {
- if (result != NULL) {
- SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE);
- }
- /*
- * If item is not NULL, the above has set item->data and
- * item->len to 0.
- */
- }
- return(NULL);
+ if (result != NULL) {
+ SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE);
+ }
+ /*
+ * If item is not NULL, the above has set item->data and
+ * item->len to 0.
+ */
+ }
+ return (NULL);
}
SECStatus
SECITEM_ReallocItem(PLArenaPool *arena, SECItem *item, unsigned int oldlen,
- unsigned int newlen)
+ unsigned int newlen)
{
PORT_Assert(item != NULL);
if (item == NULL) {
- /* XXX Set error. But to what? */
- return SECFailure;
+ /* XXX Set error. But to what? */
+ return SECFailure;
}
/*
* If no old length, degenerate to just plain alloc.
*/
if (oldlen == 0) {
- PORT_Assert(item->data == NULL || item->len == 0);
- if (newlen == 0) {
- /* Nothing to do. Weird, but not a failure. */
- return SECSuccess;
- }
- item->len = newlen;
- if (arena != NULL) {
- item->data = PORT_ArenaAlloc(arena, newlen);
- } else {
- item->data = PORT_Alloc(newlen);
- }
+ PORT_Assert(item->data == NULL || item->len == 0);
+ if (newlen == 0) {
+ /* Nothing to do. Weird, but not a failure. */
+ return SECSuccess;
+ }
+ item->len = newlen;
+ if (arena != NULL) {
+ item->data = PORT_ArenaAlloc(arena, newlen);
+ } else {
+ item->data = PORT_Alloc(newlen);
+ }
} else {
- if (arena != NULL) {
- item->data = PORT_ArenaGrow(arena, item->data, oldlen, newlen);
- } else {
- item->data = PORT_Realloc(item->data, newlen);
- }
+ if (arena != NULL) {
+ item->data = PORT_ArenaGrow(arena, item->data, oldlen, newlen);
+ } else {
+ item->data = PORT_Realloc(item->data, newlen);
+ }
}
if (item->data == NULL) {
- return SECFailure;
+ return SECFailure;
}
return SECSuccess;
@@ -122,52 +122,52 @@ SECITEM_ReallocItemV2(PLArenaPool *arena, SECItem *item, unsigned int newlen)
PORT_Assert(item);
if (!item) {
- PORT_SetError(SEC_ERROR_INVALID_ARGS);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_INVALID_ARGS);
+ return SECFailure;
}
-
+
if (item->len == newlen) {
- return SECSuccess;
+ return SECSuccess;
}
if (!newlen) {
- if (!arena) {
- PORT_Free(item->data);
- }
- item->data = NULL;
- item->len = 0;
- return SECSuccess;
- }
-
+ if (!arena) {
+ PORT_Free(item->data);
+ }
+ item->data = NULL;
+ item->len = 0;
+ return SECSuccess;
+ }
+
if (!item->data) {
- /* allocate fresh block of memory */
- PORT_Assert(!item->len);
- if (arena) {
- newdata = PORT_ArenaAlloc(arena, newlen);
- } else {
- newdata = PORT_Alloc(newlen);
- }
+ /* allocate fresh block of memory */
+ PORT_Assert(!item->len);
+ if (arena) {
+ newdata = PORT_ArenaAlloc(arena, newlen);
+ } else {
+ newdata = PORT_Alloc(newlen);
+ }
} else {
- /* reallocate or adjust existing block of memory */
- if (arena) {
- if (item->len > newlen) {
- /* There's no need to realloc a shorter block from the arena,
- * because it would result in using even more memory!
- * Therefore we'll continue to use the old block and
- * set the item to the shorter size.
- */
- item->len = newlen;
- return SECSuccess;
- }
- newdata = PORT_ArenaGrow(arena, item->data, item->len, newlen);
- } else {
- newdata = PORT_Realloc(item->data, newlen);
- }
+ /* reallocate or adjust existing block of memory */
+ if (arena) {
+ if (item->len > newlen) {
+ /* There's no need to realloc a shorter block from the arena,
+ * because it would result in using even more memory!
+ * Therefore we'll continue to use the old block and
+ * set the item to the shorter size.
+ */
+ item->len = newlen;
+ return SECSuccess;
+ }
+ newdata = PORT_ArenaGrow(arena, item->data, item->len, newlen);
+ } else {
+ newdata = PORT_Realloc(item->data, newlen);
+ }
}
if (!newdata) {
- PORT_SetError(SEC_ERROR_NO_MEMORY);
- return SECFailure;
+ PORT_SetError(SEC_ERROR_NO_MEMORY);
+ return SECFailure;
}
item->len = newlen;
@@ -182,23 +182,23 @@ SECITEM_CompareItem(const SECItem *a, const SECItem *b)
int rv;
if (a == b)
- return SECEqual;
- if (!a || !a->len || !a->data)
+ return SECEqual;
+ if (!a || !a->len || !a->data)
return (!b || !b->len || !b->data) ? SECEqual : SECLessThan;
- if (!b || !b->len || !b->data)
- return SECGreaterThan;
+ if (!b || !b->len || !b->data)
+ return SECGreaterThan;
+
+ m = ((a->len < b->len) ? a->len : b->len);
- m = ( ( a->len < b->len ) ? a->len : b->len );
-
rv = PORT_Memcmp(a->data, b->data, m);
if (rv) {
- return rv < 0 ? SECLessThan : SECGreaterThan;
+ return rv < 0 ? SECLessThan : SECGreaterThan;
}
if (a->len < b->len) {
- return SECLessThan;
+ return SECLessThan;
}
if (a->len == b->len) {
- return SECEqual;
+ return SECEqual;
}
return SECGreaterThan;
}
@@ -209,10 +209,10 @@ SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b)
if (a->len != b->len)
return PR_FALSE;
if (!a->len)
- return PR_TRUE;
+ return PR_TRUE;
if (!a->data || !b->data) {
/* avoid null pointer crash. */
- return (PRBool)(a->data == b->data);
+ return (PRBool)(a->data == b->data);
}
return (PRBool)!PORT_Memcmp(a->data, b->data, a->len);
}
@@ -227,37 +227,37 @@ SECItem *
SECITEM_ArenaDupItem(PLArenaPool *arena, const SECItem *from)
{
SECItem *to;
-
- if ( from == NULL ) {
- return(NULL);
+
+ if (from == NULL) {
+ return (NULL);
}
-
- if ( arena != NULL ) {
- to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem));
+
+ if (arena != NULL) {
+ to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem));
} else {
- to = (SECItem *)PORT_Alloc(sizeof(SECItem));
+ to = (SECItem *)PORT_Alloc(sizeof(SECItem));
}
- if ( to == NULL ) {
- return(NULL);
+ if (to == NULL) {
+ return (NULL);
}
- if ( arena != NULL ) {
- to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len);
+ if (arena != NULL) {
+ to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len);
} else {
- to->data = (unsigned char *)PORT_Alloc(from->len);
+ to->data = (unsigned char *)PORT_Alloc(from->len);
}
- if ( to->data == NULL ) {
- PORT_Free(to);
- return(NULL);
+ if (to->data == NULL) {
+ PORT_Free(to);
+ return (NULL);
}
to->len = from->len;
to->type = from->type;
- if ( to->len ) {
- PORT_Memcpy(to->data, from->data, to->len);
+ if (to->len) {
+ PORT_Memcpy(to->data, from->data, to->len);
}
-
- return(to);
+
+ return (to);
}
SECStatus
@@ -265,24 +265,24 @@ SECITEM_CopyItem(PLArenaPool *arena, SECItem *to, const SECItem *from)
{
to->type = from->type;
if (from->data && from->len) {
- if ( arena ) {
- to->data = (unsigned char*) PORT_ArenaAlloc(arena, from->len);
- } else {
- to->data = (unsigned char*) PORT_Alloc(from->len);
- }
-
- if (!to->data) {
- return SECFailure;
- }
- PORT_Memcpy(to->data, from->data, from->len);
- to->len = from->len;
+ if (arena) {
+ to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len);
+ } else {
+ to->data = (unsigned char *)PORT_Alloc(from->len);
+ }
+
+ if (!to->data) {
+ return SECFailure;
+ }
+ PORT_Memcpy(to->data, from->data, from->len);
+ to->len = from->len;
} else {
- /*
- * If from->data is NULL but from->len is nonzero, this function
- * will succeed. Is this right?
- */
- to->data = 0;
- to->len = 0;
+ /*
+ * If from->data is NULL but from->len is nonzero, this function
+ * will succeed. Is this right?
+ */
+ to->data = 0;
+ to->len = 0;
}
return SECSuccess;
}
@@ -291,12 +291,12 @@ void
SECITEM_FreeItem(SECItem *zap, PRBool freeit)
{
if (zap) {
- PORT_Free(zap->data);
- zap->data = 0;
- zap->len = 0;
- if (freeit) {
- PORT_Free(zap);
- }
+ PORT_Free(zap->data);
+ zap->data = 0;
+ zap->len = 0;
+ if (freeit) {
+ PORT_Free(zap);
+ }
}
}
@@ -304,12 +304,12 @@ void
SECITEM_ZfreeItem(SECItem *zap, PRBool freeit)
{
if (zap) {
- PORT_ZFree(zap->data, zap->len);
- zap->data = 0;
- zap->len = 0;
- if (freeit) {
- PORT_ZFree(zap, sizeof(SECItem));
- }
+ PORT_ZFree(zap->data, zap->len);
+ zap->data = 0;
+ zap->len = 0;
+ if (freeit) {
+ PORT_ZFree(zap, sizeof(SECItem));
+ }
}
}
/* these reroutines were taken from pkix oid.c, which is supposed to
@@ -321,7 +321,7 @@ SECITEM_ZfreeItem(SECItem *zap, PRBool freeit)
* inclined student.
*/
PLHashNumber PR_CALLBACK
-SECITEM_Hash ( const void *key)
+SECITEM_Hash(const void *key)
{
const SECItem *item = (const SECItem *)key;
PLHashNumber rv = 0;
@@ -330,8 +330,8 @@ SECITEM_Hash ( const void *key)
PRUint32 i;
PRUint8 *rvc = (PRUint8 *)&rv;
- for( i = 0; i < item->len; i++ ) {
- rvc[ i % sizeof(rv) ] ^= *data;
+ for (i = 0; i < item->len; i++) {
+ rvc[i % sizeof(rv)] ^= *data;
data++;
}
@@ -345,12 +345,12 @@ SECITEM_Hash ( const void *key)
* but heck it's only used internally by the hash table anyway.
*/
PRIntn PR_CALLBACK
-SECITEM_HashCompare ( const void *k1, const void *k2)
+SECITEM_HashCompare(const void *k1, const void *k2)
{
const SECItem *i1 = (const SECItem *)k1;
const SECItem *i2 = (const SECItem *)k2;
- return SECITEM_ItemsAreEqual(i1,i2);
+ return SECITEM_ItemsAreEqual(i1, i2);
}
SECItemArray *
@@ -402,7 +402,7 @@ SECITEM_AllocArray(PLArenaPool *arena, SECItemArray *array, unsigned int len)
return result;
loser:
- if ( arena != NULL ) {
+ if (arena != NULL) {
if (mark) {
PORT_ArenaRelease(arena, mark);
}
@@ -445,12 +445,14 @@ secitem_FreeArray(SECItemArray *array, PRBool zero_items, PRBool freeit)
PORT_Free(array);
}
-void SECITEM_FreeArray(SECItemArray *array, PRBool freeit)
+void
+SECITEM_FreeArray(SECItemArray *array, PRBool freeit)
{
secitem_FreeArray(array, PR_FALSE, freeit);
}
-void SECITEM_ZfreeArray(SECItemArray *array, PRBool freeit)
+void
+SECITEM_ZfreeArray(SECItemArray *array, PRBool freeit)
{
secitem_FreeArray(array, PR_TRUE, freeit);
}