In packet-enttec.c and packet-fw1.c, replace string pointer tracking with a

string buffer. In packet-ftp.c and packet-gift.c, cast some size_t's.

svn path=/trunk/; revision=27896
This commit is contained in:
Gerald Combs 2009-03-30 17:53:41 +00:00
parent 92ade75cd0
commit c5f52b8fa0
4 changed files with 18 additions and 30 deletions

View File

@ -197,14 +197,13 @@ dissect_enttec_dmx_data(tvbuff_t *tvb, guint offset, proto_tree *tree)
static guint8 dmx_data[512];
static guint16 dmx_data_offset[513]; /* 1 extra for last offset */
static char string[255];
emem_strbuf_t *dmx_epstr;
proto_tree *hi,*si;
proto_item *item;
guint16 length,r,c,row_count;
guint8 v,type,count;
guint16 ci,ui,i,start_offset,end_offset;
char* ptr;
proto_tree_add_item(tree, hf_enttec_dmx_data_universe, tvb,
offset, 1, FALSE);
@ -279,29 +278,22 @@ dissect_enttec_dmx_data(tvbuff_t *tvb, guint offset, proto_tree *tree)
si = proto_item_add_subtree(hi, ett_enttec);
row_count = (ui/global_disp_col_count) + ((ui%global_disp_col_count) == 0 ? 0 : 1);
ptr = string;
/* XX: In theory the g_snprintf statements below could store '\0' bytes off the end of the */
/* 'string' buffer'. This is so since g_snprint returns the number of characters which */
/* "would have been written" (whether or not there was room) and since ptr is always */
/* incremented by this amount. In practice the string buffer is large enough such that the */
/* string buffer size is not exceeded even with the maximum number of columns which might */
/* be displayed. */
/* ToDo: consider recoding slightly ... */
dmx_epstr = ep_strbuf_new_label("");
for (r=0; r < row_count;r++) {
for (c=0;(c < global_disp_col_count) && (((r*global_disp_col_count)+c) < ui);c++) {
if ((c % (global_disp_col_count/2)) == 0) {
ptr += g_snprintf(ptr, sizeof string - strlen(string), " ");
ep_strbuf_append(dmx_epstr, " ");
}
v = dmx_data[(r*global_disp_col_count)+c];
if (global_disp_chan_val_type == 0) {
v = (v * 100) / 255;
if (v == 100) {
ptr += g_snprintf(ptr, sizeof string - strlen(string), "FL ");
ep_strbuf_append(dmx_epstr, "FL ");
} else {
ptr += g_snprintf(ptr, sizeof string - strlen(string), chan_format[global_disp_chan_val_type], v);
ep_strbuf_append_printf(dmx_epstr, chan_format[global_disp_chan_val_type], v);
}
} else {
ptr += g_snprintf(ptr, sizeof string - strlen(string), chan_format[global_disp_chan_val_type], v);
ep_strbuf_append_printf(dmx_epstr, chan_format[global_disp_chan_val_type], v);
}
}
@ -311,8 +303,8 @@ dissect_enttec_dmx_data(tvbuff_t *tvb, guint offset, proto_tree *tree)
proto_tree_add_none_format(si,hf_enttec_dmx_data_dmx_data, tvb,
offset+start_offset,
end_offset-start_offset,
string_format[global_disp_chan_nr_type], (r*global_disp_col_count)+1, string);
ptr = string;
string_format[global_disp_chan_nr_type], (r*global_disp_col_count)+1, dmx_epstr->str);
ep_strbuf_truncate(dmx_epstr, 0);
}
item = proto_tree_add_item(si, hf_enttec_dmx_data_data_filter, tvb,

View File

@ -451,8 +451,8 @@ dissect_ftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
next_token = line;
}
}
offset += next_token - line;
linelen -= next_token - line;
offset += (gint) (next_token - line);
linelen -= (int) (next_token - line);
line = next_token;
if (tree) {

View File

@ -139,15 +139,12 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
char *interface_name;
guint32 iface_len = 10;
guint16 etype;
char *header;
char *p_header;
emem_strbuf_t *header;
int i;
gboolean found;
static const char fw1_header[] = "FW1 Monitor";
#define MAX_HEADER_LEN 1000
header=ep_alloc(MAX_HEADER_LEN);
g_snprintf(header, MAX_HEADER_LEN, "FW1 Monitor");
header = ep_strbuf_new_label(fw1_header);
/* Make entries in Protocol column and Info column on summary display */
if (check_col(pinfo->cinfo, COL_PROTOCOL))
@ -187,9 +184,8 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* display all interfaces always in the same order */
for (i=0; i<interface_anzahl; i++) {
p_header = header + strlen(header);
if ( strcmp(p_interfaces[i], interface_name) == 0 ) {
g_snprintf(p_header, MAX_HEADER_LEN-(p_header-header), " %c%c %s %c%c",
ep_strbuf_append_printf(header, " %c%c %s %c%c",
direction == 'i' ? 'i' : (direction == 'O' ? 'O' : ' '),
(direction == 'i' || direction == 'O') ? chain : ' ',
p_interfaces[i],
@ -197,19 +193,19 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
(direction == 'I' || direction == 'o') ? chain : ' '
);
} else {
g_snprintf(p_header, MAX_HEADER_LEN-(p_header-header), " %s ", p_interfaces[i]);
ep_strbuf_append_printf(header, " %s ", p_interfaces[i]);
}
}
if (check_col(pinfo->cinfo, COL_IF_DIR))
col_add_str(pinfo->cinfo, COL_IF_DIR, header + sizeof(fw1_header) + 1);
col_add_str(pinfo->cinfo, COL_IF_DIR, header->str + sizeof(fw1_header) + 1);
if (tree) {
if (!fw1_summary_in_tree)
/* Do not show the summary in Protocol Tree */
ti = proto_tree_add_protocol_format(tree, proto_fw1, tvb, 0, ETH_HEADER_SIZE, "%s", fw1_header);
else
ti = proto_tree_add_protocol_format(tree, proto_fw1, tvb, 0, ETH_HEADER_SIZE, "%s", header);
ti = proto_tree_add_protocol_format(tree, proto_fw1, tvb, 0, ETH_HEADER_SIZE, "%s", header->str);
/* create display subtree for the protocol */
fh_tree = proto_item_add_subtree(ti, ett_fw1);

View File

@ -108,8 +108,8 @@ dissect_gift(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
tokenlen, "Response Command: %s",
format_text(line, tokenlen));
}
offset += next_token - line;
linelen -= next_token - line;
offset += (gint) (next_token - line);
linelen -= (int) (next_token - line);
line = next_token;
}