Commit 4d9528c7 authored by Lev Walkin's avatar Lev Walkin
Browse files

portability

parent 90fcd44d
......@@ -59,7 +59,7 @@ BIT_STRING_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
int
BIT_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
static char h2c[16] = "0123456789ABCDEF";
static const char *h2c = "0123456789ABCDEF";
char scratch[64];
const BIT_STRING_t *st = sptr;
uint8_t *buf;
......
......@@ -60,7 +60,7 @@ BOOLEAN_decode_ber(asn1_TYPE_descriptor_t *td,
ASN_DEBUG("Boolean length is %d bytes", (int)length);
buf_ptr += rval.consumed;
(char *)buf_ptr += rval.consumed;
size -= rval.consumed;
if(length > (ber_tlv_len_t)size) {
rval.code = RC_WMORE;
......
......@@ -437,7 +437,7 @@ asn_time2GT(GeneralizedTime_t *opt_gt, const struct tm *tm, int force_gmt) {
if(!opt_gt) { free(buf); return 0; }
}
opt_gt->buf = buf;
opt_gt->buf = (unsigned char *)buf;
opt_gt->size = size;
return opt_gt;
......
......@@ -66,7 +66,7 @@ INTEGER_decode_ber(asn1_TYPE_descriptor_t *td,
/*
* Make sure we have this length.
*/
buf_ptr += rval.consumed;
(char *)buf_ptr += rval.consumed;
size -= rval.consumed;
if(length > (ber_tlv_len_t)size) {
rval.code = RC_WMORE;
......@@ -230,7 +230,7 @@ INTEGER_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
/* Output in the long xx:yy:zz... format */
/* TODO: replace with generic algorithm (Knuth TAOCP Vol 2, 4.3.1) */
for(p = scratch; buf < buf_end; buf++) {
static char h2c[16] = "0123456789ABCDEF";
static const char *h2c = "0123456789ABCDEF";
if((p - scratch) >= (ssize_t)(sizeof(scratch) - 4)) {
/* Flush buffer */
if(cb(scratch, p - scratch, app_key))
......
......@@ -73,7 +73,7 @@ NativeInteger_decode_ber(asn1_TYPE_descriptor_t *td,
/*
* Make sure we have this length.
*/
buf_ptr += rval.consumed;
(char *)buf_ptr += rval.consumed;
size -= rval.consumed;
if(length > (ber_tlv_len_t)size) {
rval.code = RC_WMORE;
......
......@@ -154,7 +154,7 @@ OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed in
#ifndef WORDS_BIGENDIAN
if(*(unsigned char *)&LE) { /* Little endian (x86) */
/* "Convert" to big endian */
rvbuf += rvsize / CHAR_BIT - 1;
(unsigned char *)rvbuf += rvsize / CHAR_BIT - 1;
((unsigned char *)rvstart)--;
inc = -1; /* Descending */
} else
......@@ -167,7 +167,7 @@ OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed in
/* Clear the high unused bits */
for(bits = rvsize - arclen;
bits > CHAR_BIT;
rvbuf += inc, bits -= CHAR_BIT)
(unsigned char *)rvbuf += inc, bits -= CHAR_BIT)
*(unsigned char *)rvbuf = 0;
/* Fill the body of a value */
......@@ -177,17 +177,17 @@ OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed in
if(bits >= CHAR_BIT) {
bits -= CHAR_BIT;
*(unsigned char *)rvbuf = (cache >> bits);
rvbuf += inc;
(unsigned char *)rvbuf += inc;
}
}
if(bits) {
*(unsigned char *)rvbuf = cache;
rvbuf += inc;
(unsigned char *)rvbuf += inc;
}
}
if(add) {
for(rvbuf -= inc; rvbuf != rvstart; rvbuf -= inc) {
for((unsigned char *)rvbuf -= inc; rvbuf != rvstart; (unsigned char *)rvbuf -= inc) {
int v = add + *(unsigned char *)rvbuf;
if(v & (-1 << CHAR_BIT)) {
*(unsigned char *)rvbuf
......@@ -287,7 +287,7 @@ OBJECT_IDENTIFIER_print(asn1_TYPE_descriptor_t *td, const void *sptr,
int
OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs,
unsigned int arc_type_size, unsigned int arc_slots) {
void *arcs_end = arcs + (arc_type_size * arc_slots);
void *arcs_end = (char *)arcs + (arc_type_size * arc_slots);
int num_arcs = 0;
int startn = 0;
int add = 0;
......@@ -319,10 +319,10 @@ OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs,
add = -40 * first_arc;
memset(arcs, 0, arc_type_size);
*(unsigned char *)(arcs
*(unsigned char *)((char *)arcs
+ ((*(char *)&LE)?0:(arc_type_size - 1)))
= first_arc;
arcs += arc_type_size;
(char *)arcs += arc_type_size;
}
/* Decode, if has space */
......@@ -332,7 +332,7 @@ OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs,
arcs, arc_type_size))
return -1;
startn = i + 1;
arcs += arc_type_size;
(char *)arcs += arc_type_size;
add = 0;
}
num_arcs++;
......@@ -371,7 +371,7 @@ OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, void *arcval, unsigned int arc
#endif
if(isLittleEndian && !prepared_order) {
uint8_t *a = arcval + arcval_size - 1;
uint8_t *a = (unsigned char *)arcval + arcval_size - 1;
uint8_t *aend = arcval;
uint8_t *msb = buffer + arcval_size - 1;
for(tp = buffer; a >= aend; tp++, a--)
......@@ -381,7 +381,7 @@ OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, void *arcval, unsigned int arc
tp = msb; /* Most significant non-zero byte */
} else {
/* Look for most significant non-zero byte */
tend = arcval + arcval_size;
tend = (unsigned char *)arcval + arcval_size;
for(tp = arcval; tp < tend - 1; tp++)
if(*tp) break;
}
......@@ -451,7 +451,8 @@ OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs, unsigned int ar
unsigned char *ps, *pe;
/* If more significant bytes are present,
* make them > 255 quick */
for(ps = arcs + 1, pe = ps+arc_type_size; ps < pe; ps++)
for(ps = (unsigned char *)arcs + 1, pe = ps+arc_type_size;
ps < pe; ps++)
arc0 |= *ps, arc1 |= *(ps + arc_type_size);
arc0 <<= CHAR_BIT, arc1 <<= CHAR_BIT;
arc0 = *((unsigned char *)arcs + 0);
......@@ -512,10 +513,15 @@ OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs, unsigned int ar
uint8_t *tp;
#ifdef __GNUC__
uint8_t first_value[1 + arc_type_size]; /* of two arcs */
uint8_t *fv = first_value;
#else
uint8_t *first_value = alloca(1 + arc_type_size);
#endif
uint8_t *fv = first_value;
if(!first_value) {
errno = ENOMEM;
return -1;
}
#endif
/*
* Simulate first_value = arc0 * 40 + arc1;
......@@ -524,8 +530,8 @@ OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs, unsigned int ar
*fv++ = 0;
(char *)arcs += arc_type_size;
if(isLittleEndian) {
uint8_t *aend = arcs - 1;
uint8_t *a1 = arcs + arc_type_size - 1;
uint8_t *aend = (unsigned char *)arcs - 1;
uint8_t *a1 = (unsigned char *)arcs + arc_type_size - 1;
for(; a1 > aend; fv++, a1--) *fv = *a1;
} else {
uint8_t *a1 = arcs;
......
......@@ -38,7 +38,7 @@ asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING = {
#define ADVANCE(num_bytes) do { \
size_t num = num_bytes; \
buf_ptr += num; \
(char *)buf_ptr += num; \
size -= num; \
consumed_myself += num; \
} while(0)
......@@ -239,7 +239,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
tlv_constr = BER_TLV_CONSTRUCTED(buf_ptr);
ll = ber_fetch_length(tlv_constr,
buf_ptr + tl, size - tl, &tlv_len);
(char *)buf_ptr + tl, size - tl, &tlv_len);
ASN_DEBUG("Got tag=%s, tl=%d, len=%d, ll=%d, {%d, %d}",
ber_tlv_tag_string(tlv_tag), tl, tlv_len, ll,
((uint8_t *)buf_ptr)[0],
......@@ -325,7 +325,7 @@ OCTET_STRING_decode_ber(asn1_TYPE_descriptor_t *td,
*/
st->buf[st->size-1] &= 0xff << st->buf[0];
APPEND((buf_ptr+1), (len - 1));
APPEND(((char *)buf_ptr+1), (len - 1));
st->buf[0] = *(uint8_t *)buf_ptr;
sel->bits_chopped = 1;
} else {
......@@ -457,7 +457,7 @@ OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
int
OCTET_STRING_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
asn_app_consume_bytes_f *cb, void *app_key) {
static char h2c[16] = "0123456789ABCDEF";
static const char *h2c = "0123456789ABCDEF";
const OCTET_STRING_t *st = sptr;
char scratch[16 * 3 + 4];
char *p = scratch;
......
......@@ -65,7 +65,7 @@ RELATIVE_OID_print(asn1_TYPE_descriptor_t *td, const void *sptr, int ilevel,
int
RELATIVE_OID_get_arcs(RELATIVE_OID_t *roid,
void *arcs, unsigned int arc_type_size, unsigned int arc_slots) {
void *arcs_end = arcs + (arc_slots * arc_type_size);
void *arcs_end = (char *)arcs + (arc_slots * arc_type_size);
int num_arcs = 0;
int startn = 0;
int i;
......@@ -86,7 +86,7 @@ RELATIVE_OID_get_arcs(RELATIVE_OID_t *roid,
i - startn + 1, 0,
arcs, arc_type_size))
return -1;
arcs += arc_type_size;
(char *)arcs += arc_type_size;
num_arcs++;
}
......
......@@ -93,7 +93,7 @@ asn_UT2time(const UTCTime_t *st, struct tm *_tm, int as_gmt) {
return -1;
}
gt.buf = buf;
gt.buf = (unsigned char *)buf;
gt.size = st->size + 2;
memcpy(gt.buf + 2, st->buf, st->size);
if(st->buf[0] > 0x35) {
......
......@@ -7,7 +7,7 @@
#define ADVANCE(num_bytes) do { \
size_t num = num_bytes; \
ptr += num; \
(char *)ptr += num; \
size -= num; \
consumed_myself += num; \
} while(0)
......@@ -162,7 +162,7 @@ ber_check_tags(asn1_TYPE_descriptor_t *td, ber_dec_ctx_t *ctx,
* Fetch and process L from TLV.
*/
len_len = ber_fetch_length(tlv_constr,
ptr + tag_len, size - tag_len, &tlv_len);
(char *)ptr + tag_len, size - tag_len, &tlv_len);
switch(len_len) {
case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE);
......
......@@ -18,14 +18,14 @@ struct asn1_TYPE_descriptor_s; /* Forward declaration */
* decoded bytes, hence provide a possibility, to fail with more diagnostics
* (i.e., print the offending remainder of the buffer).
*/
enum ber_dec_rval_code_e {
RC_OK, /* Decoded successfully */
RC_WMORE, /* More data expected, call again */
RC_FAIL, /* Failure to decode data */
};
typedef struct ber_dec_rval_s {
enum {
RC_OK, /* Decoded successfully */
RC_WMORE, /* More data expected, call again */
RC_FAIL, /* Failure to decode data */
} code;
size_t consumed; /* Number of bytes consumed */
enum ber_dec_rval_code_e code; /* Result code */
size_t consumed; /* Number of bytes consumed */
} ber_dec_rval_t;
/*
......
......@@ -87,7 +87,7 @@ ber_skip_length(int _is_constructed, void *ptr, size_t size) {
* Indefinite length!
*/
ASN_DEBUG("Skipping indefinite length");
for(skip = ll, ptr += ll, size -= ll;;) {
for(skip = ll, (char *)ptr += ll, size -= ll;;) {
ber_tlv_tag_t tag;
/* Fetch the tag */
......@@ -95,7 +95,7 @@ ber_skip_length(int _is_constructed, void *ptr, size_t size) {
if(tl <= 0) return tl;
ll = ber_skip_length(BER_TLV_CONSTRUCTED(ptr),
ptr + tl, size - tl);
(char *)ptr + tl, size - tl);
if(ll <= 0) return ll;
skip += tl + ll;
......@@ -109,7 +109,7 @@ ber_skip_length(int _is_constructed, void *ptr, size_t size) {
&& ((uint8_t *)ptr)[1] == 0)
return skip;
ptr += tl + ll;
(char *)ptr += tl + ll;
size -= tl + ll;
}
......
......@@ -30,7 +30,8 @@ ber_fetch_tag(void *ptr, size_t size, ber_tlv_tag_t *tag_r) {
* Each octet contains 7 bits of useful information.
* The MSB is 0 if it is the last octet of the tag.
*/
for(val = 0, ptr++, skipped = 2; skipped < size; ptr++, skipped++) {
for(val = 0, ((char *)ptr)++, skipped = 2;
skipped < size; ((char *)ptr)++, skipped++) {
unsigned oct = *(uint8_t *)ptr;
if(oct & 0x80) {
val = (val << 7) | (oct & 0x7F);
......
......@@ -31,7 +31,7 @@
*/
#define ADVANCE(num_bytes) do { \
size_t num = num_bytes; \
ptr += num; \
(char *)ptr += num; \
size -= num; \
if(ctx->left >= 0) \
ctx->left -= num; \
......@@ -128,7 +128,7 @@ CHOICE_decode_ber(asn1_TYPE_descriptor_t *sd,
/*
* Restore parsing context.
*/
ctx = (st + specs->ctx_offset);
ctx = (ber_dec_ctx_t *)((char *)st + specs->ctx_offset);
/*
* Start to parse where left previously
......@@ -206,7 +206,7 @@ CHOICE_decode_ber(asn1_TYPE_descriptor_t *sd,
skip = ber_skip_length(
BER_TLV_CONSTRUCTED(ptr),
ptr + tag_len, LEFT - tag_len);
(char *)ptr + tag_len, LEFT - tag_len);
switch(skip) {
case 0: if(!SIZE_VIOLATION) RETURN(RC_WMORE);
......@@ -468,7 +468,7 @@ CHOICE_outmost_tag(asn1_TYPE_descriptor_t *td, const void *ptr, int tag_mode, be
return asn1_TYPE_outmost_tag(elm->type, memb_ptr,
elm->tag_mode, elm->tag);
} else {
return -1;
return (ber_tlv_tag_t)-1;
}
}
......
......@@ -31,7 +31,7 @@
*/
#define ADVANCE(num_bytes) do { \
size_t num = num_bytes; \
ptr += num; \
(char *)ptr += num; \
size -= num; \
if(ctx->left >= 0) \
ctx->left -= num; \
......@@ -138,7 +138,7 @@ SEQUENCE_decode_ber(asn1_TYPE_descriptor_t *sd,
/*
* Restore parsing context.
*/
ctx = (st + specs->ctx_offset);
ctx = (ber_dec_ctx_t *)((char *)st + specs->ctx_offset);
/*
* Start to parse where left previously
......@@ -336,7 +336,7 @@ SEQUENCE_decode_ber(asn1_TYPE_descriptor_t *sd,
skip = ber_skip_length(
BER_TLV_CONSTRUCTED(ptr),
ptr + tag_len, LEFT - tag_len);
(char *)ptr + tag_len, LEFT - tag_len);
ASN_DEBUG("Skip length %d in %s",
(int)skip, sd->name);
switch(skip) {
......@@ -455,7 +455,7 @@ SEQUENCE_decode_ber(asn1_TYPE_descriptor_t *sd,
ll = ber_skip_length(
BER_TLV_CONSTRUCTED(ptr),
ptr + tl, LEFT - tl);
(char *)ptr + tl, LEFT - tl);
switch(ll) {
case 0: if(!SIZE_VIOLATION) RETURN(RC_WMORE);
/* Fall through */
......
......@@ -37,7 +37,7 @@
*/
#define ADVANCE(num_bytes) do { \
size_t num = num_bytes; \
ptr += num; \
(char *)ptr += num; \
size -= num; \
if(ctx->left >= 0) \
ctx->left -= num; \
......@@ -128,7 +128,7 @@ SET_decode_ber(asn1_TYPE_descriptor_t *sd,
/*
* Restore parsing context.
*/
ctx = (st + specs->ctx_offset);
ctx = (ber_dec_ctx_t *)((char *)st + specs->ctx_offset);
/*
* Start to parse where left previously
......@@ -256,7 +256,7 @@ SET_decode_ber(asn1_TYPE_descriptor_t *sd,
skip = ber_skip_length(
BER_TLV_CONSTRUCTED(ptr),
ptr + tag_len, LEFT - tag_len);
(char *)ptr + tag_len, LEFT - tag_len);
switch(skip) {
case 0: if(!SIZE_VIOLATION) RETURN(RC_WMORE);
......@@ -281,7 +281,7 @@ SET_decode_ber(asn1_TYPE_descriptor_t *sd,
* Check for duplications: must not overwrite
* already decoded elements.
*/
if(ASN_SET_ISPRESENT2(st + specs->pres_offset, edx)) {
if(ASN_SET_ISPRESENT2((char *)st + specs->pres_offset, edx)) {
ASN_DEBUG("SET %s: Duplicate element %s (%d)",
sd->name, elements[edx].name, edx);
RETURN(RC_FAIL);
......@@ -312,7 +312,7 @@ SET_decode_ber(asn1_TYPE_descriptor_t *sd,
elements[edx].tag_mode);
switch(rval.code) {
case RC_OK:
ASN_SET_MKPRESENT(st + specs->pres_offset, edx);
ASN_SET_MKPRESENT((char *)st + specs->pres_offset, edx);
break;
case RC_WMORE: /* More data expected */
if(!SIZE_VIOLATION) {
......@@ -378,7 +378,7 @@ SET_decode_ber(asn1_TYPE_descriptor_t *sd,
ll = ber_skip_length(
BER_TLV_CONSTRUCTED(ptr),
ptr + tl, LEFT - tl);
(char *)ptr + tl, LEFT - tl);
switch(ll) {
case 0: if(!SIZE_VIOLATION) RETURN(RC_WMORE);
/* Fall through */
......@@ -398,7 +398,7 @@ SET_decode_ber(asn1_TYPE_descriptor_t *sd,
unsigned int midx, pres, must;
midx = edx/(8 * sizeof(specs->_mandatory_elements[0]));
pres = ((unsigned int *)(st+specs->pres_offset))[midx];
pres = ((unsigned int *)((char *)st+specs->pres_offset))[midx];
must = ntohl(specs->_mandatory_elements[midx]);
if((pres & must) == must) {
......
......@@ -31,7 +31,7 @@
*/
#define ADVANCE(num_bytes) do { \
size_t num = num_bytes; \
ptr += num; \
(char *)ptr += num; \
size -= num; \
if(ctx->left >= 0) \
ctx->left -= num; \
......@@ -95,7 +95,7 @@ SET_OF_decode_ber(asn1_TYPE_descriptor_t *sd,
/*
* Restore parsing context.
*/
ctx = (st + specs->ctx_offset);
ctx = (ber_dec_ctx_t *)((char *)st + specs->ctx_offset);
/*
* Start to parse where left previously
......
......@@ -4,6 +4,7 @@
*/
#include <constr_TYPE.h>
#include <assert.h>
#include <errno.h>
static ssize_t der_write_TL(ber_tlv_tag_t tag, ber_tlv_len_t len,
asn_app_consume_bytes_f *cb, void *app_key, int constructed);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment