sprintf removal

svn path=/trunk/; revision=15550
This commit is contained in:
Ronnie Sahlberg 2005-08-27 00:25:32 +00:00
parent 30263a1d0b
commit 44db2c5665
2 changed files with 23 additions and 14 deletions

View File

@ -503,7 +503,7 @@ dcm_setSyntax(dcmItem_t *di, char *name)
static char *
dcm_tag2str(guint16 grp, guint16 elm, guint8 syntax, tvbuff_t *tvb, int offset, guint32 len, int vr, int tr)
{
static char buf[512+1]; /* bad form ??? */
char *buf;
const guint8 *vval;
size_t vval_len;
char *p;
@ -513,21 +513,23 @@ dcm_tag2str(guint16 grp, guint16 elm, guint8 syntax, tvbuff_t *tvb, int offset,
size_t pl;
static dcmTag_t utag = { 0, 0, "(unknown)" };
#define MAX_BUF_LEN 1024
buf=ep_alloc(MAX_BUF_LEN);
*buf = 0;
if (0 == elm) {
if (DCM_ILE & syntax)
val32 = tvb_get_letohl(tvb, offset);
else val32 = tvb_get_ntohl(tvb, offset);
g_snprintf(buf, sizeof(buf), "Group Length 0x%x (%d)", val32, val32);
g_snprintf(buf, MAX_BUF_LEN, "Group Length 0x%x (%d)", val32, val32);
return buf;
}
tag = (grp << 16) | elm;
if (NULL == (dtag = g_hash_table_lookup(dcm_tagTable, GUINT_TO_POINTER(tag))))
dtag = &utag;
DISSECTOR_ASSERT(sizeof(buf) > strlen(dtag->desc));
DISSECTOR_ASSERT(MAX_BUF_LEN > strlen(dtag->desc));
strcpy(buf, dtag->desc);
pl = sizeof(buf) - strlen(buf);
pl = MAX_BUF_LEN - strlen(buf);
p = buf + strlen(buf);
if (vr > 0) {
vval = tvb_format_text(tvb, vr, 2);
@ -560,39 +562,39 @@ dcm_tag2str(guint16 grp, guint16 elm, guint8 syntax, tvbuff_t *tvb, int offset,
if (DCM_ILE & syntax)
val16 = tvb_get_letohs(tvb, offset);
else val16 = tvb_get_ntohs(tvb, offset);
sprintf(p, " 0x%x (%d)", val16, val16);
g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x (%d)", val16, val16);
break;
case DCM_TINT4:
if (DCM_ILE & syntax)
val32 = tvb_get_letohl(tvb, offset);
else val32 = tvb_get_ntohl(tvb, offset);
sprintf(p, " 0x%x (%d)", val32, val32);
g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x (%d)", val32, val32);
break;
case DCM_TFLT: {
gfloat valf;
if (DCM_ILE & syntax)
valf = tvb_get_letohieee_float(tvb, offset);
else valf = tvb_get_ntohieee_float(tvb, offset);
sprintf(p, " (%f)", valf);
g_snprintf(p, MAX_BUF_LEN-(p-buf), " (%f)", valf);
} break;
case DCM_TDBL: {
gdouble vald;
if (DCM_ILE & syntax)
vald = tvb_get_letohieee_double(tvb, offset);
else vald = tvb_get_ntohieee_double(tvb, offset);
sprintf(p, " (%f)", vald);
g_snprintf(p, MAX_BUF_LEN-(p-buf), " (%f)", vald);
} break;
case DCM_TSTAT: /* call dcm_rsp2str() on TINT2 */
if (DCM_ILE & syntax)
val16 = tvb_get_letohs(tvb, offset);
else val16 = tvb_get_ntohs(tvb, offset);
sprintf(p, " 0x%x '%s'", val16, dcm_rsp2str(val16));
g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x '%s'", val16, dcm_rsp2str(val16));
break;
case DCM_TCMD: /* call dcm_cmd2str() on TINT2 */
if (DCM_ILE & syntax)
val16 = tvb_get_letohs(tvb, offset);
else val16 = tvb_get_ntohs(tvb, offset);
sprintf(p, " 0x%x '%s'", val16, dcm_cmd2str(val16));
g_snprintf(p, MAX_BUF_LEN-(p-buf), " 0x%x '%s'", val16, dcm_cmd2str(val16));
break;
case DCM_SQ: /* Sequence */
case DCM_OTH: /* Other BYTE, WORD, ... */

View File

@ -91,6 +91,7 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/emem.h>
#include "etypes.h"
/* Place FW1 summary in proto tree */
@ -135,15 +136,19 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree *volatile fh_tree = NULL;
char direction;
char chain;
char interface_name[10+1];
char *interface_name;
guint32 iface_len = 10;
guint16 etype;
char header[1000] = "FW1 Monitor";
char *header;
char *p_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");
/* Make entries in Protocol column and Info column on summary display */
if (check_col(pinfo->cinfo, COL_PROTOCOL))
col_set_str(pinfo->cinfo, COL_PROTOCOL, "FW1");
@ -163,6 +168,8 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (fw1_with_uuid)
iface_len = 6;
interface_name=ep_alloc(iface_len+1);
tvb_get_nstringz0(tvb, 2, iface_len, interface_name);
/* Known interface name - if not, remember it */
@ -182,7 +189,7 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
for (i=0; i<interface_anzahl; i++) {
p_header = header + strlen(header);
if ( strcmp(p_interfaces[i], interface_name) == 0 ) {
sprintf(p_header, " %c%c %s %c%c",
g_snprintf(p_header, MAX_HEADER_LEN-(p_header-header), " %c%c %s %c%c",
direction == 'i' ? 'i' : (direction == 'O' ? 'O' : ' '),
(direction == 'i' || direction == 'O') ? chain : ' ',
p_interfaces[i],
@ -190,7 +197,7 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
(direction == 'I' || direction == 'o') ? chain : ' '
);
} else {
sprintf(p_header, " %s ", p_interfaces[i]);
g_snprintf(p_header, MAX_HEADER_LEN-(p_header-header), " %s ", p_interfaces[i]);
}
}