Provide better error messages for field type mismatches.

Don't just report an assertion failure with a line in proto.c; give the
name of the field with the wrong type, and a list of the types that are
valid for the routine in question.

Change-Id: Id3ed7c376fdc72bf6cff69c647833946cfa99ee6
Reviewed-on: https://code.wireshark.org/review/20824
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2017-03-31 19:41:47 -07:00
parent d967d71d98
commit 19bb1b128b
1 changed files with 18 additions and 6 deletions

View File

@ -2610,7 +2610,9 @@ proto_tree_add_item_ret_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
case FT_UINT32:
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32",
hfinfo->abbrev));
}
/* length validation for native number encoding caught by get_uint_value() */
@ -2679,7 +2681,9 @@ proto_tree_add_item_ret_string_and_length(proto_tree *tree, int hfindex,
value = get_stringzpad_value(scope, tvb, start, length, lenretval, encoding);
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, or FT_STRINGZPAD",
hfinfo->abbrev));
}
if (retval)
@ -4223,7 +4227,9 @@ proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, or FT_FRAMENUM",
hfinfo->abbrev));
}
return pi;
@ -4311,7 +4317,9 @@ proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64, or FT_FRAMENUM",
hfinfo->abbrev));
}
return pi;
@ -4398,7 +4406,9 @@ proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32",
hfinfo->abbrev));
}
return pi;
@ -4489,7 +4499,9 @@ proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(),
"field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64",
hfinfo->abbrev));
}
return pi;