mirror of https://gerrit.osmocom.org/asn1c
tighten code according to tag invariant
This commit is contained in:
parent
aed43c8bcc
commit
30520ab335
|
@ -143,20 +143,26 @@ struct xdp_arg_s {
|
|||
int want_more;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Since some kinds of primitive values can be encoded using value-specific
|
||||
* tags (<MINUS-INFINITY>, <enum-element>, etc), the primitive decoder must
|
||||
* be supplied with such tags to parse them as needed.
|
||||
*/
|
||||
static int
|
||||
xer_decode__unexpected_tag(void *key, const void *chunk_buf, size_t chunk_size) {
|
||||
struct xdp_arg_s *arg = (struct xdp_arg_s *)key;
|
||||
enum xer_pbd_rval bret;
|
||||
|
||||
if(arg->decoded_something) {
|
||||
if(xer_is_whitespace(chunk_buf, chunk_size))
|
||||
return 0; /* Skip it. */
|
||||
/*
|
||||
* Decoding was done once already. Prohibit doing it again.
|
||||
*/
|
||||
/*
|
||||
* The chunk_buf is guaranteed to start at '<'.
|
||||
*/
|
||||
assert(chunk_size && ((const char *)chunk_buf)[0] == 0x3c);
|
||||
|
||||
/*
|
||||
* Decoding was performed once already. Prohibit doing it again.
|
||||
*/
|
||||
if(arg->decoded_something)
|
||||
return -1;
|
||||
}
|
||||
|
||||
bret = arg->prim_body_decoder(arg->type_descriptor,
|
||||
arg->struct_key, chunk_buf, chunk_size);
|
||||
|
@ -177,13 +183,19 @@ xer_decode__unexpected_tag(void *key, const void *chunk_buf, size_t chunk_size)
|
|||
}
|
||||
|
||||
static ssize_t
|
||||
xer_decode__body(void *key, const void *chunk_buf, size_t chunk_size, int have_more) {
|
||||
xer_decode__primitive_body(void *key, const void *chunk_buf, size_t chunk_size, int have_more) {
|
||||
struct xdp_arg_s *arg = (struct xdp_arg_s *)key;
|
||||
enum xer_pbd_rval bret;
|
||||
|
||||
if(arg->decoded_something) {
|
||||
if(xer_is_whitespace(chunk_buf, chunk_size))
|
||||
if(xer_is_whitespace(chunk_buf, chunk_size)) {
|
||||
/*
|
||||
* Example:
|
||||
* "<INTEGER>123<!--/--> </INTEGER>"
|
||||
* ^- chunk_buf position.
|
||||
*/
|
||||
return chunk_size;
|
||||
}
|
||||
/*
|
||||
* Decoding was done once already. Prohibit doing it again.
|
||||
*/
|
||||
|
@ -253,7 +265,7 @@ xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx,
|
|||
|
||||
rc = xer_decode_general(opt_codec_ctx, &s_ctx, &s_arg,
|
||||
xml_tag, buf_ptr, size,
|
||||
xer_decode__unexpected_tag, xer_decode__body);
|
||||
xer_decode__unexpected_tag, xer_decode__primitive_body);
|
||||
switch(rc.code) {
|
||||
case RC_OK:
|
||||
if(!s_arg.decoded_something) {
|
||||
|
|
Loading…
Reference in New Issue