diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-04-12 15:26:34 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-04-12 22:27:22 +0000 |
commit | cb16dff992c3844936bf5829f19e5a5247458503 (patch) | |
tree | 901b7be3379f5b94f150de71d1c0f3e2fa2d12e4 /epan/dissectors/packet-quakeworld.c | |
parent | ef8a0a2ce172810d48371eb65c73b1bd4a6303ca (diff) |
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 <guy@alum.mit.edu>
Diffstat (limited to 'epan/dissectors/packet-quakeworld.c')
-rw-r--r-- | epan/dissectors/packet-quakeworld.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/epan/dissectors/packet-quakeworld.c b/epan/dissectors/packet-quakeworld.c index 16ac74a911..4ceb8a4fad 100644 --- a/epan/dissectors/packet-quakeworld.c +++ b/epan/dissectors/packet-quakeworld.c @@ -90,8 +90,8 @@ static char com_token[MAX_TEXT_SIZE+1]; static int com_token_start; static int com_token_length; -static char * -COM_Parse (char *data) +static const char * +COM_Parse (const char *data) { int c; int len; @@ -198,7 +198,7 @@ Cmd_Argv_length(int arg) static void -Cmd_TokenizeString(char* text) +Cmd_TokenizeString(const char* text) { int start; @@ -349,7 +349,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo, { proto_tree *cl_tree = NULL; proto_tree *text_tree = NULL; - guint8 text[MAX_TEXT_SIZE+1]; + guint8 *text; int len; int offset; guint32 marker; @@ -370,13 +370,13 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo, /* all the rest of the packet is just text */ offset = 4; - len = tvb_get_nstringz0(tvb, offset, sizeof(text), text); + text = tvb_get_stringz_enc(wmem_packet_scope(), tvb, offset, &len, ENC_ASCII|ENC_NA); /* actually, we should look for a eol char and stop already there */ if (cl_tree) { proto_item *text_item; text_item = proto_tree_add_string(cl_tree, hf_quakeworld_connectionless_text, - tvb, offset, len + 1, text); + tvb, offset, len, text); text_tree = proto_item_add_subtree(text_item, ett_quakeworld_connectionless_text); } @@ -469,7 +469,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo, tvb, offset, command_len, command); argument_item = proto_tree_add_string(text_tree, hf_quakeworld_connectionless_arguments, - tvb, offset + Cmd_Argv_start(1), len + 1 - Cmd_Argv_start(1), + tvb, offset + Cmd_Argv_start(1), len - Cmd_Argv_start(1), text + Cmd_Argv_start(1)); argument_tree = proto_item_add_subtree(argument_item, ett_quakeworld_connectionless_arguments); @@ -504,7 +504,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo, command_len = 1; } else { command = "Unknown"; - command_len = len; + command_len = len - 1; } } else { @@ -529,7 +529,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo, /* string, atoi */ } else { command = "Unknown"; - command_len = len; + command_len = len - 1; } } @@ -539,7 +539,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo, proto_tree_add_string(text_tree, hf_quakeworld_connectionless_command, tvb, offset, command_len, command); } - /*offset += len + 1;*/ + /*offset += len;*/ } |