From: Ken Raeburn Date: Mon, 3 Nov 2008 18:41:33 +0000 (+0000) Subject: If we're not making asn1buf_insert_octet an inline function, then make X-Git-Tag: krb5-1.7-alpha1~237 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b093fb36e64edf461a560926b9cac9c4fc5a07d9;p=krb5.git If we're not making asn1buf_insert_octet an inline function, then make asn1buf_size, asn1buf_ensure_space, and asn1buf_expand static in asn1buf.c, for better optimization. Recode asn1buf_ensure_space to directly return the result of asn1buf_expand. Don't check for NULL before malloc/realloc in asn1buf_expand. Fix a couple minor signedness warnings. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20957 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/asn1_encode.c b/src/lib/krb5/asn.1/asn1_encode.c index d2caefded..eaa40cf3a 100644 --- a/src/lib/krb5/asn.1/asn1_encode.c +++ b/src/lib/krb5/asn.1/asn1_encode.c @@ -421,7 +421,8 @@ encode_a_field(asn1buf *buf, const void *val, { unsigned int length; - retval = asn1_encode_integer(buf, field->dataoff, &length); + retval = asn1_encode_integer(buf, (asn1_intmax) field->dataoff, + &length); if (retval) return retval; sum += length; break; diff --git a/src/lib/krb5/asn.1/asn1_k_encode.c b/src/lib/krb5/asn.1/asn1_k_encode.c index a94ac3c4e..2f48b82b9 100644 --- a/src/lib/krb5/asn.1/asn1_k_encode.c +++ b/src/lib/krb5/asn.1/asn1_k_encode.c @@ -155,7 +155,7 @@ asn1_encode_krb5_flags_at(asn1buf *buf, const krb5_flags *val, unsigned int *retlen) { unsigned char cbuf[4]; - store_32_be(*val, cbuf); + store_32_be((krb5_ui_4) *val, cbuf); return asn1_encode_bitstring(buf, 4, cbuf, retlen); } DEFFNXTYPE(krb5_flags, krb5_flags, asn1_encode_krb5_flags_at); diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c index 0779bfd2f..29a3f5c55 100644 --- a/src/lib/krb5/asn.1/asn1buf.c +++ b/src/lib/krb5/asn.1/asn1buf.c @@ -52,10 +52,17 @@ #define ASN1BUF_OMIT_INLINE_FUNCS #include "asn1buf.h" -#undef ASN1BUF_OMIT_INLINE_FUNCS #include #include "asn1_get.h" +#if !((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS)) || defined(CONFIG_SMALL) +/* Declare private procedures as static if they're not used for inline + expansion of other stuff elsewhere. */ +static unsigned int asn1buf_free(const asn1buf *); +static asn1_error_code asn1buf_ensure_space(asn1buf *, unsigned int); +static asn1_error_code asn1buf_expand(asn1buf *, unsigned int); +#endif + #define asn1_is_eoc(class, num, indef) \ ((class) == UNIVERSAL && !(num) && !(indef)) @@ -318,8 +325,7 @@ asn1_error_code asn1buf_hex_unparse(const asn1buf *buf, char **s) /****************************************************************/ /* Private Procedures */ -#undef asn1buf_size -int asn1buf_size(const asn1buf *buf) +static int asn1buf_size(const asn1buf *buf) { if (buf == NULL || buf->base == NULL) return 0; return buf->bound - buf->base + 1; @@ -336,11 +342,9 @@ unsigned int asn1buf_free(const asn1buf *buf) asn1_error_code asn1buf_ensure_space(asn1buf *buf, const unsigned int amount) { unsigned int avail = asn1buf_free(buf); - if (avail < amount) { - asn1_error_code retval = asn1buf_expand(buf, amount-avail); - if (retval) return retval; - } - return 0; + if (avail >= amount) + return 0; + return asn1buf_expand(buf, amount-avail); } asn1_error_code asn1buf_expand(asn1buf *buf, unsigned int inc) @@ -354,12 +358,9 @@ asn1_error_code asn1buf_expand(asn1buf *buf, unsigned int inc) if (inc < STANDARD_INCREMENT) inc = STANDARD_INCREMENT; - if (buf->base == NULL) - buf->base = malloc((asn1buf_size(buf)+inc) * sizeof(asn1_octet)); - else - buf->base = realloc(buf->base, - (asn1buf_size(buf)+inc) * sizeof(asn1_octet)); - if (buf->base == NULL) return ENOMEM; + buf->base = realloc(buf->base, + (asn1buf_size(buf)+inc) * sizeof(asn1_octet)); + if (buf->base == NULL) return ENOMEM; /* XXX leak */ buf->bound = (buf->base) + bound_offset + inc; buf->next = (buf->base) + next_offset; return 0; diff --git a/src/lib/krb5/asn.1/asn1buf.h b/src/lib/krb5/asn.1/asn1buf.h index 33578f98a..1e40cae7b 100644 --- a/src/lib/krb5/asn.1/asn1buf.h +++ b/src/lib/krb5/asn.1/asn1buf.h @@ -13,16 +13,7 @@ typedef struct code_buffer_rep { /**************** Private Procedures ****************/ -int asn1buf_size - (const asn1buf *buf); -/* requires *buf has been created and not destroyed - effects Returns the total size - (in octets) of buf's octet buffer. */ -#define asn1buf_size(buf) \ - (((buf) == NULL || (buf)->base == NULL) \ - ? 0 \ - : ((buf)->bound - (buf)->base + 1)) - +#if ((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS)) && !defined(CONFIG_SMALL) unsigned int asn1buf_free (const asn1buf *buf); /* requires *buf is allocated @@ -40,13 +31,10 @@ asn1_error_code asn1buf_ensure_space effects If buf has less than amount octets of free space, then it is expanded to have at least amount octets of free space. Returns ENOMEM memory is exhausted. */ -#ifndef CONFIG_SMALL #define asn1buf_ensure_space(buf,amount) \ ((asn1buf_free(buf) < (amount)) \ ? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \ : 0) -#endif - asn1_error_code asn1buf_expand (asn1buf *buf, unsigned int inc); @@ -54,6 +42,7 @@ asn1_error_code asn1buf_expand modifies *buf effects Expands *buf by allocating space for inc more octets. Returns ENOMEM if memory is exhausted. */ +#endif int asn1buf_len (const asn1buf *buf);