Remove use of sprintf for ftype string formatting

Change-Id: I656d6193aad740ab88bf16fb25c202e766e3092a
Reviewed-on: https://code.wireshark.org/review/7616
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2015-03-07 10:02:08 -05:00
parent b5d062ba57
commit 0bec88518f
4 changed files with 39 additions and 60 deletions

View File

@ -20,13 +20,13 @@
#include "config.h"
#include <stdio.h>
#include <ftypes-int.h>
#include <string.h>
#include <epan/addr_resolv.h>
#include <epan/strutil.h>
#include <epan/oids.h>
#include <epan/osi-utils.h>
#include <epan/to_str-int.h>
#define CMP_MATCHES cmp_matches
@ -140,39 +140,26 @@ system_id_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf)
static void
bytes_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf)
{
guint8 *c;
char *write_cursor;
unsigned int i;
char separator;
c = fv->value.bytes->data;
write_cursor = buf;
for (i = 0; i < fv->value.bytes->len; i++) {
if (i == 0) {
sprintf(write_cursor, "%02x", *c++);
write_cursor += 2;
}
else {
switch(field_display)
{
case SEP_DOT:
separator = '.';
break;
case SEP_DASH:
separator = '-';
break;
case SEP_SPACE:
case SEP_COLON:
case BASE_NONE:
default:
separator = ':';
break;
}
sprintf(write_cursor, "%c%02x", separator, *c++);
write_cursor += 3;
}
switch(field_display)
{
case SEP_DOT:
separator = '.';
break;
case SEP_DASH:
separator = '-';
break;
case SEP_SPACE:
case SEP_COLON:
case BASE_NONE:
default:
separator = ':';
break;
}
buf = bytes_to_hexstr_punct(buf, fv->value.bytes->data, fv->value.bytes->len, separator);
*buf = '\0';
}
static void

View File

@ -20,11 +20,11 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "ftypes-int.h"
#include <epan/addr_resolv.h>
#include <epan/to_str-int.h>
#include <wsutil/pint.h>
@ -243,16 +243,9 @@ integer_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *b
}
static int
uinteger_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display)
uinteger_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_)
{
if (field_display == BASE_HEX)
{
return 11; /* fits 0x%08x */
}
else
{
return 10; /* enough for 2^32-1, in decimal */
}
return 10; /* enough for 2^32-1, in decimal or 0xXXXXXXXX */
}
static void
@ -261,7 +254,11 @@ uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *buf)
if (field_display == BASE_HEX)
{
/* This format perfectly fits into 11 bytes. */
sprintf(buf, "0x%08x", fv->value.uinteger);
*buf++ = '0';
*buf++ = 'x';
buf = dword_to_hex(buf, fv->value.uinteger);
*buf++ = '\0';
}
else
{
@ -304,7 +301,7 @@ ipxnet_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_)
static void
ipxnet_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf)
{
sprintf(buf, "0x%08x", fv->value.uinteger);
uinteger_to_repr(fv, rtype, BASE_HEX, buf);
}
static gboolean

View File

@ -344,9 +344,15 @@ absolute_val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *
gchar *rep = abs_time_to_str(NULL, &fv->value.time, ABSOLUTE_TIME_LOCAL,
rtype == FTREPR_DISPLAY);
if (rtype == FTREPR_DFILTER) {
sprintf(buf, "\"%s\"", rep);
} else {
strcpy(buf, rep);
*buf++ = '\"';
}
strcpy(buf, rep);
if (rtype == FTREPR_DFILTER) {
buf += strlen(rep);
*buf++ = '\"';
*buf++ = '\0';
}
wmem_free(NULL, rep);
}

View File

@ -20,8 +20,8 @@
#include "config.h"
#include <stdio.h>
#include <ftypes-int.h>
#include <epan/to_str-int.h>
#include <string.h>
#include <epan/exceptions.h>
@ -141,25 +141,14 @@ static void
val_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char * volatile buf)
{
guint length;
const guint8 *c;
unsigned int i;
g_assert(rtype == FTREPR_DFILTER);
TRY {
length = tvb_length(fv->value.tvb);
c = tvb_get_ptr(fv->value.tvb, 0, length);
for (i = 0; i < length; i++) {
if (i == 0) {
sprintf((char *)buf, "%02x", *c++);
buf += 2;
}
else {
sprintf((char *)buf, ":%02x", *c++);
buf += 3;
}
}
buf = bytes_to_hexstr_punct(buf, tvb_get_ptr(fv->value.tvb, 0, length), length, ':');
*buf = '\0';
}
CATCH_ALL {
/* nothing */