From cb16dff992c3844936bf5829f19e5a5247458503 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 12 Apr 2014 15:26:34 -0700 Subject: Get rid of more tvb_get_nstringz* calls. Add an FT_STRINGZPAD type, for null-padded strings (typically fixed-length fields, where the string can be up to the length of the field, and is null-padded if it's shorter than that), and use it. Use IS_FT_STRING() in more cases, so that less code needs to know what types are string types. Add a tvb_get_stringzpad() routine, which gets null-padded strings. Currently, it does the same thing that tvb_get_string_enc() does, but that might change if we don't store string values as null-terminated strings. Change-Id: I46f56e130de8f419a19b56ded914e24cc7518a66 Reviewed-on: https://code.wireshark.org/review/1082 Reviewed-by: Guy Harris --- epan/tvbuff.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'epan/tvbuff.c') diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 91e2202be2..fcdb0e22c9 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -2532,6 +2532,24 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, return strbuf; } +/* + * This is like tvb_get_string_enc(), except that it handles null-padded + * strings. + * + * Currently, string values are stored as UTF-8 null-terminated strings, + * so nothing needs to be done differently for null-padded strings; we + * could save a little memory by not storing the null padding. + * + * If we ever store string values differently, in a fashion that doesn't + * involve null termination, that might change. + */ +guint8 * +tvb_get_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, + const gint length, const guint encoding) +{ + return tvb_get_string_enc(scope, tvb, offset, length, encoding); +} + /* * These routines are like the above routines, except that they handle * null-terminated strings. They find the length of that string (and -- cgit v1.2.3