aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-03-07 10:02:08 -0500
committerMichael Mann <mmann78@netscape.net>2015-03-11 22:50:55 +0000
commit0bec88518f22aca076e69654d029c96fa050f003 (patch)
treedcb2a50a29f790b8b84f00570d006581d841b077 /epan/ftypes
parentb5d062ba57efd4b78f83518ac868fcb25d9bc243 (diff)
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>
Diffstat (limited to 'epan/ftypes')
-rw-r--r--epan/ftypes/ftype-bytes.c49
-rw-r--r--epan/ftypes/ftype-integer.c21
-rw-r--r--epan/ftypes/ftype-time.c12
-rw-r--r--epan/ftypes/ftype-tvbuff.c19
4 files changed, 40 insertions, 61 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c
index e63276c336..5f54a44f5c 100644
--- a/epan/ftypes/ftype-bytes.c
+++ b/epan/ftypes/ftype-bytes.c
@@ -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
diff --git a/epan/ftypes/ftype-integer.c b/epan/ftypes/ftype-integer.c
index f12a004ea2..e412a1e8f4 100644
--- a/epan/ftypes/ftype-integer.c
+++ b/epan/ftypes/ftype-integer.c
@@ -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
diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c
index 8aaac3aebd..34e3826246 100644
--- a/epan/ftypes/ftype-time.c
+++ b/epan/ftypes/ftype-time.c
@@ -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);
}
diff --git a/epan/ftypes/ftype-tvbuff.c b/epan/ftypes/ftype-tvbuff.c
index a1376475bd..38cbe15b61 100644
--- a/epan/ftypes/ftype-tvbuff.c
+++ b/epan/ftypes/ftype-tvbuff.c
@@ -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 */