forked from osmocom/wireshark
Remove and replace obsolete ws_snprintf() definition
Since fe94133f0d
ws_snprintf()
and ws_vsnprintf() don't actually do anything anymore.
The return value of ws_[v]snprintf was discarded before,
now it too conforms to C99.
pespin/rlcmac
parent
670fab2ce5
commit
73d793788c
|
@ -381,15 +381,15 @@ as to avoid collisions with other names - this might be more of an issue
|
|||
on Windows, as it appears to #define names such as DELETE and
|
||||
OPTIONAL.
|
||||
|
||||
Don't use the "numbered argument" feature that many UNIX printf's
|
||||
Don't use the "positional parameters" extension that many UNIX printf's
|
||||
implement, e.g.:
|
||||
|
||||
g_snprintf(add_string, 30, " - (%1$d) (0x%1$04x)", value);
|
||||
snprintf(add_string, 30, " - (%1$d) (0x%1$04x)", value);
|
||||
|
||||
as not all UNIX printf's implement it, and Windows printf doesn't appear
|
||||
to implement it. Use something like
|
||||
|
||||
g_snprintf(add_string, 30, " - (%d) (0x%04x)", value, value);
|
||||
snprintf(add_string, 30, " - (%d) (0x%04x)", value, value);
|
||||
|
||||
instead.
|
||||
|
||||
|
@ -399,9 +399,13 @@ Don't use
|
|||
|
||||
as that's not supported by all compilers.
|
||||
|
||||
snprintf() -> g_snprintf()
|
||||
snprintf() is not available on all platforms, so it's a good idea to use the
|
||||
g_snprintf() function declared by <glib.h> instead.
|
||||
Prefer the C99 output functions from <stdio.h> instead of their GLib
|
||||
replacements (note that positional format parameters are not part of C99).
|
||||
In the past we used to recommend using g_snprintf() and g_vsnprintf()
|
||||
instead but since Visual Studio 2015 native C99 implementations are
|
||||
available on all platforms we support. These are optimized better than
|
||||
the gnulib (GLib) implementation and on hot codepaths that can be a
|
||||
noticeable difference in execution speed.
|
||||
|
||||
tmpnam() -> mkstemp()
|
||||
tmpnam is insecure and should not be used any more. Wireshark brings its
|
||||
|
@ -432,7 +436,7 @@ Do not use functions such as strcat() or strcpy().
|
|||
A lot of work has been done to remove the existing calls to these functions and
|
||||
we do not want any new callers of these functions.
|
||||
|
||||
Instead use g_snprintf() since that function will if used correctly prevent
|
||||
Instead use snprintf() since that function will if used correctly prevent
|
||||
buffer overflows for large strings.
|
||||
|
||||
Be sure that all pointers passed to %s specifiers in format strings are non-
|
||||
|
@ -459,7 +463,7 @@ or
|
|||
buffer=wmem_alloc(wmem_packet_scope(), MAX_BUFFER);
|
||||
buffer[0]='\0';
|
||||
...
|
||||
g_snprintf(buffer, MAX_BUFFER, ...
|
||||
snprintf(buffer, MAX_BUFFER, ...
|
||||
|
||||
This avoids the stack from being corrupted in case there is a bug in your code
|
||||
that accidentally writes beyond the end of the buffer.
|
||||
|
@ -643,12 +647,12 @@ should be stored in a 32-bit variable, such as an "int"; if you store it
|
|||
in an 8-bit or 16-bit variable, you run the risk of the variable
|
||||
overflowing.
|
||||
|
||||
sprintf() -> g_snprintf()
|
||||
sprintf() -> snprintf()
|
||||
Prevent yourself from using the sprintf() function, as it does not test the
|
||||
length of the given output buffer and might be writing into unintended memory
|
||||
areas. This function is one of the main causes of security problems like buffer
|
||||
exploits and many other bugs that are very hard to find. It's much better to
|
||||
use the g_snprintf() function declared by <glib.h> instead.
|
||||
use the snprintf() function declared by <stdio.h> instead.
|
||||
|
||||
You should test your dissector against incorrectly-formed packets. This
|
||||
can be done using the randpkt and editcap utilities that come with the
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <epan/dfilter/dfilter.h>
|
||||
|
||||
#include <wsutil/utf8_entities.h>
|
||||
#include <wsutil/ws_printf.h>
|
||||
|
||||
#ifdef HAVE_LUA
|
||||
#include <epan/wslua/wslua.h>
|
||||
|
@ -431,15 +430,15 @@ col_append_str_uint(column_info *cinfo, const gint col, const gchar *abbrev, gui
|
|||
}
|
||||
|
||||
static inline void
|
||||
col_snprint_port(gchar *buf, gulong buf_siz, port_type typ, guint16 val)
|
||||
col_snprint_port(gchar *buf, size_t buf_siz, port_type typ, guint16 val)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if (gbl_resolv_flags.transport_name &&
|
||||
(str = try_serv_name_lookup(typ, val)) != NULL) {
|
||||
ws_snprintf(buf, buf_siz, "%s(%"G_GUINT16_FORMAT")", str, val);
|
||||
snprintf(buf, buf_siz, "%s(%"G_GUINT16_FORMAT")", str, val);
|
||||
} else {
|
||||
ws_snprintf(buf, buf_siz, "%"G_GUINT16_FORMAT, val);
|
||||
snprintf(buf, buf_siz, "%"G_GUINT16_FORMAT, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,7 +497,7 @@ col_do_append_fstr(column_info *cinfo, const int el, const char *separator, cons
|
|||
va_list ap2;
|
||||
|
||||
G_VA_COPY(ap2, ap);
|
||||
ws_vsnprintf(&col_item->col_buf[len], (guint32)(max_len - len), format, ap2);
|
||||
vsnprintf(&col_item->col_buf[len], max_len - len, format, ap2);
|
||||
va_end(ap2);
|
||||
}
|
||||
}
|
||||
|
@ -571,7 +570,7 @@ col_prepend_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
|
|||
orig = orig_buf;
|
||||
}
|
||||
va_start(ap, format);
|
||||
ws_vsnprintf(col_item->col_buf, max_len, format, ap);
|
||||
vsnprintf(col_item->col_buf, max_len, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
/*
|
||||
|
@ -614,7 +613,7 @@ col_prepend_fence_fstr(column_info *cinfo, const gint el, const gchar *format, .
|
|||
orig = orig_buf;
|
||||
}
|
||||
va_start(ap, format);
|
||||
ws_vsnprintf(col_item->col_buf, max_len, format, ap);
|
||||
vsnprintf(col_item->col_buf, max_len, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
/*
|
||||
|
@ -792,7 +791,7 @@ col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
|
|||
col_item->col_data = col_item->col_buf;
|
||||
}
|
||||
va_start(ap, format);
|
||||
ws_vsnprintf(&col_item->col_buf[col_item->col_fence], max_len - col_item->col_fence, format, ap);
|
||||
vsnprintf(&col_item->col_buf[col_item->col_fence], max_len - col_item->col_fence, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
@ -916,7 +915,7 @@ set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean
|
|||
}
|
||||
switch (tsprecision) {
|
||||
case WTAP_TSPREC_SEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
|
||||
snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
|
@ -925,7 +924,7 @@ set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean
|
|||
tmp->tm_sec);
|
||||
break;
|
||||
case WTAP_TSPREC_DSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d%s%01d",
|
||||
snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d%s%01d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
|
@ -936,7 +935,7 @@ set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean
|
|||
fd->abs_ts.nsecs / 100000000);
|
||||
break;
|
||||
case WTAP_TSPREC_CSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d%s%02d",
|
||||
snprintf(buf, COL_MAX_LEN,"%04d-%02d-%02d %02d:%02d:%02d%s%02d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
|
@ -947,7 +946,7 @@ set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean
|
|||
fd->abs_ts.nsecs / 10000000);
|
||||
break;
|
||||
case WTAP_TSPREC_MSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%03d",
|
||||
snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%03d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
|
@ -958,7 +957,7 @@ set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean
|
|||
fd->abs_ts.nsecs / 1000000);
|
||||
break;
|
||||
case WTAP_TSPREC_USEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%06d",
|
||||
snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%06d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
|
@ -969,7 +968,7 @@ set_abs_ymd_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean
|
|||
fd->abs_ts.nsecs / 1000);
|
||||
break;
|
||||
case WTAP_TSPREC_NSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%09d",
|
||||
snprintf(buf, COL_MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d%s%09d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
|
@ -1050,7 +1049,7 @@ set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolea
|
|||
}
|
||||
switch (tsprecision) {
|
||||
case WTAP_TSPREC_SEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d",
|
||||
snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_yday + 1,
|
||||
tmp->tm_hour,
|
||||
|
@ -1058,7 +1057,7 @@ set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolea
|
|||
tmp->tm_sec);
|
||||
break;
|
||||
case WTAP_TSPREC_DSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d%s%01d",
|
||||
snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d%s%01d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_yday + 1,
|
||||
tmp->tm_hour,
|
||||
|
@ -1068,7 +1067,7 @@ set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolea
|
|||
fd->abs_ts.nsecs / 100000000);
|
||||
break;
|
||||
case WTAP_TSPREC_CSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d%s%02d",
|
||||
snprintf(buf, COL_MAX_LEN,"%04d/%03d %02d:%02d:%02d%s%02d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_yday + 1,
|
||||
tmp->tm_hour,
|
||||
|
@ -1078,7 +1077,7 @@ set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolea
|
|||
fd->abs_ts.nsecs / 10000000);
|
||||
break;
|
||||
case WTAP_TSPREC_MSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%03d",
|
||||
snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%03d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_yday + 1,
|
||||
tmp->tm_hour,
|
||||
|
@ -1088,7 +1087,7 @@ set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolea
|
|||
fd->abs_ts.nsecs / 1000000);
|
||||
break;
|
||||
case WTAP_TSPREC_USEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%06d",
|
||||
snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%06d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_yday + 1,
|
||||
tmp->tm_hour,
|
||||
|
@ -1098,7 +1097,7 @@ set_abs_ydoy_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolea
|
|||
fd->abs_ts.nsecs / 1000);
|
||||
break;
|
||||
case WTAP_TSPREC_NSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%09d",
|
||||
snprintf(buf, COL_MAX_LEN, "%04d/%03d %02d:%02d:%02d%s%09d",
|
||||
tmp->tm_year + 1900,
|
||||
tmp->tm_yday + 1,
|
||||
tmp->tm_hour,
|
||||
|
@ -1240,25 +1239,25 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
switch (tsprecision) {
|
||||
case WTAP_TSPREC_SEC:
|
||||
if (secs >= (60*60)) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2ds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / (60 * 60),
|
||||
(gint32) (secs / 60) % 60,
|
||||
(gint32) secs % 60);
|
||||
} else if (secs >= 60) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dm %2ds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / 60,
|
||||
(gint32) secs % 60);
|
||||
} else {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%ds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%ds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs);
|
||||
}
|
||||
break;
|
||||
case WTAP_TSPREC_DSEC:
|
||||
if (secs >= (60*60)) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%01lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%01lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / (60 * 60),
|
||||
(gint32) (secs / 60) % 60,
|
||||
|
@ -1266,14 +1265,14 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
decimal_point,
|
||||
nsecs / 100000000);
|
||||
} else if (secs >= 60) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%01lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%01lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / 60,
|
||||
(gint32) secs % 60,
|
||||
decimal_point,
|
||||
nsecs / 100000000);
|
||||
} else {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%01lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%d%s%01lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs,
|
||||
decimal_point,
|
||||
|
@ -1282,7 +1281,7 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
break;
|
||||
case WTAP_TSPREC_CSEC:
|
||||
if (secs >= (60*60)) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%02lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%02lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / (60 * 60),
|
||||
(gint32) (secs / 60) % 60,
|
||||
|
@ -1290,14 +1289,14 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
decimal_point,
|
||||
nsecs / 10000000);
|
||||
} else if (secs >= 60) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%02lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%02lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / 60,
|
||||
(gint32) secs % 60,
|
||||
decimal_point,
|
||||
nsecs / 10000000);
|
||||
} else {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%02lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%d%s%02lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs,
|
||||
decimal_point,
|
||||
|
@ -1306,7 +1305,7 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
break;
|
||||
case WTAP_TSPREC_MSEC:
|
||||
if (secs >= (60*60)) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%03lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%03lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / (60 * 60),
|
||||
(gint32) (secs / 60) % 60,
|
||||
|
@ -1314,14 +1313,14 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
decimal_point,
|
||||
nsecs / 1000000);
|
||||
} else if (secs >= 60) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%03lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%03lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / 60,
|
||||
(gint32) secs % 60,
|
||||
decimal_point,
|
||||
nsecs / 1000000);
|
||||
} else {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%03lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%d%s%03lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs,
|
||||
decimal_point,
|
||||
|
@ -1330,7 +1329,7 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
break;
|
||||
case WTAP_TSPREC_USEC:
|
||||
if (secs >= (60*60)) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%06lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%06lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / (60 * 60),
|
||||
(gint32) (secs / 60) % 60,
|
||||
|
@ -1338,14 +1337,14 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
decimal_point,
|
||||
nsecs / 1000);
|
||||
} else if (secs >= 60) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%06lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%06lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / 60,
|
||||
(gint32) secs % 60,
|
||||
decimal_point,
|
||||
nsecs / 1000);
|
||||
} else {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%06lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%d%s%06lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs,
|
||||
decimal_point,
|
||||
|
@ -1354,7 +1353,7 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
break;
|
||||
case WTAP_TSPREC_NSEC:
|
||||
if (secs >= (60*60)) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%09lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dh %2dm %2d%s%09lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / (60 * 60),
|
||||
(gint32) (secs / 60) % 60,
|
||||
|
@ -1362,14 +1361,14 @@ set_time_hour_min_sec(const frame_data *fd, const nstime_t *ts, gchar *buf, char
|
|||
decimal_point,
|
||||
nsecs);
|
||||
} else if (secs >= 60) {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%09lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%dm %2d%s%09lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs / 60,
|
||||
(gint32) secs % 60,
|
||||
decimal_point,
|
||||
nsecs);
|
||||
} else {
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%s%d%s%09lds",
|
||||
snprintf(buf, COL_MAX_LEN, "%s%d%s%09lds",
|
||||
negative ? "- " : "",
|
||||
(gint32) secs,
|
||||
decimal_point,
|
||||
|
@ -1508,13 +1507,13 @@ set_abs_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean loc
|
|||
}
|
||||
switch (tsprecision) {
|
||||
case WTAP_TSPREC_SEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
|
||||
snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d",
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec);
|
||||
break;
|
||||
case WTAP_TSPREC_DSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%01d",
|
||||
snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%01d",
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec,
|
||||
|
@ -1522,7 +1521,7 @@ set_abs_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean loc
|
|||
fd->abs_ts.nsecs / 100000000);
|
||||
break;
|
||||
case WTAP_TSPREC_CSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%02d",
|
||||
snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%02d",
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec,
|
||||
|
@ -1530,7 +1529,7 @@ set_abs_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean loc
|
|||
fd->abs_ts.nsecs / 10000000);
|
||||
break;
|
||||
case WTAP_TSPREC_MSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%03d",
|
||||
snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%03d",
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec,
|
||||
|
@ -1538,7 +1537,7 @@ set_abs_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean loc
|
|||
fd->abs_ts.nsecs / 1000000);
|
||||
break;
|
||||
case WTAP_TSPREC_USEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%06d",
|
||||
snprintf(buf, COL_MAX_LEN,"%02d:%02d:%02d%s%06d",
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec,
|
||||
|
@ -1546,7 +1545,7 @@ set_abs_time(const frame_data *fd, gchar *buf, char *decimal_point, gboolean loc
|
|||
fd->abs_ts.nsecs / 1000);
|
||||
break;
|
||||
case WTAP_TSPREC_NSEC:
|
||||
ws_snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d%s%09d",
|
||||
snprintf(buf, COL_MAX_LEN, "%02d:%02d:%02d%s%09d",
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec,
|
||||
|
@ -2012,7 +2011,7 @@ col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gbo
|
|||
|
||||
case PT_IPX:
|
||||
/* XXX - resolve IPX socket numbers */
|
||||
ws_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
|
||||
snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
|
||||
g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
|
||||
if (is_src)
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "ipx.src.socket";
|
||||
|
@ -2022,7 +2021,7 @@ col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gbo
|
|||
|
||||
case PT_IDP:
|
||||
/* XXX - resolve IDP socket numbers */
|
||||
ws_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
|
||||
snprintf(col_item->col_buf, COL_MAX_LEN, "0x%04x", port);
|
||||
g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
|
||||
if (is_src)
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "idp.src.socket";
|
||||
|
@ -2032,7 +2031,7 @@ col_set_port(packet_info *pinfo, const int col, const gboolean is_res, const gbo
|
|||
|
||||
case PT_USB:
|
||||
/* XXX - resolve USB endpoint numbers */
|
||||
ws_snprintf(col_item->col_buf, COL_MAX_LEN, "0x%08x", port);
|
||||
snprintf(col_item->col_buf, COL_MAX_LEN, "0x%08x", port);
|
||||
g_strlcpy(pinfo->cinfo->col_expr.col_expr_val[col], col_item->col_buf,COL_MAX_LEN);
|
||||
if (is_src)
|
||||
pinfo->cinfo->col_expr.col_expr[col] = "usb.src.endpoint";
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <epan/packet.h>
|
||||
#include <epan/expert.h>
|
||||
|
@ -68,7 +69,6 @@
|
|||
#include <epan/etypes.h>
|
||||
|
||||
#include <wsutil/utf8_entities.h>
|
||||
#include <wsutil/ws_printf.h>
|
||||
|
||||
#include "packet-e164.h"
|
||||
#include "packet-ieee1609dot2.h"
|
||||
|
@ -405,7 +405,7 @@ dissect_btpb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
|
|||
pinfo->destport = dst_port;
|
||||
|
||||
char buf_dst[32];
|
||||
ws_snprintf(buf_dst, 32, "%"G_GUINT16_FORMAT, dst_port);
|
||||
snprintf(buf_dst, 32, "%"G_GUINT16_FORMAT, dst_port);
|
||||
col_append_lstr(pinfo->cinfo, COL_INFO, " " UTF8_RIGHTWARDS_ARROW " ", buf_dst, COL_ADD_LSTR_TERMINATOR);
|
||||
|
||||
btpbh->btp_pdst = dst_port;
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wsutil/ws_printf.h>
|
||||
|
||||
#include "packet.h"
|
||||
#include "expert.h"
|
||||
#include "uat.h"
|
||||
|
@ -526,7 +524,7 @@ expert_set_info_vformat(packet_info *pinfo, proto_item *pi, int group, int sever
|
|||
}
|
||||
|
||||
if (use_vaformat) {
|
||||
ws_vsnprintf(formatted, ITEM_LABEL_LENGTH, format, ap);
|
||||
vsnprintf(formatted, ITEM_LABEL_LENGTH, format, ap);
|
||||
} else {
|
||||
g_strlcpy(formatted, format, ITEM_LABEL_LENGTH);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <glib.h>
|
||||
|
||||
#include <wsutil/wsjson.h>
|
||||
#include <wsutil/ws_printf.h>
|
||||
#include <wsutil/json_dumper.h>
|
||||
|
||||
#include <file.h>
|
||||
|
@ -707,7 +706,7 @@ sharkd_session_create_columns(column_info *cinfo, const char *buf, const jsmntok
|
|||
char tok_column_name[64];
|
||||
char *custom_sepa;
|
||||
|
||||
ws_snprintf(tok_column_name, sizeof(tok_column_name), "column%d", i);
|
||||
snprintf(tok_column_name, sizeof(tok_column_name), "column%d", i);
|
||||
tok_column = json_find_attr(buf, tokens, count, tok_column_name);
|
||||
if (tok_column == NULL)
|
||||
break;
|
||||
|
@ -2197,7 +2196,7 @@ sharkd_session_process_tap(char *buf, const jsmntok_t *tokens, int count)
|
|||
const char *tap_filter = "";
|
||||
GString *tap_error = NULL;
|
||||
|
||||
ws_snprintf(tapbuf, sizeof(tapbuf), "tap%d", i);
|
||||
snprintf(tapbuf, sizeof(tapbuf), "tap%d", i);
|
||||
tok_tap = json_find_attr(buf, tokens, count, tapbuf);
|
||||
if (!tok_tap)
|
||||
break;
|
||||
|
@ -3618,7 +3617,7 @@ sharkd_session_process_setconf(char *buf, const jsmntok_t *tokens, int count)
|
|||
if (!tok_name || tok_name[0] == '\0' || !tok_value)
|
||||
return;
|
||||
|
||||
ws_snprintf(pref, sizeof(pref), "%s:%s", tok_name, tok_value);
|
||||
snprintf(pref, sizeof(pref), "%s:%s", tok_name, tok_value);
|
||||
|
||||
ret = prefs_set_pref(pref, &errmsg);
|
||||
|
||||
|
|
|
@ -11,58 +11,6 @@
|
|||
#ifndef __WS_PRINTF_H__
|
||||
#define __WS_PRINTF_H__
|
||||
|
||||
/*
|
||||
* GLib's string utility routines are slow on windows, likely due to calling
|
||||
* g_printf_string_upper_bound. Using ws_snprintf and ws_vsnprintf in hot
|
||||
* code paths can speed up program execution. Otherwise you're probably safe
|
||||
* sticking with g_snprintf and g_vsnprintf.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <strsafe.h>
|
||||
|
||||
/* The UCRT versions of snprintf and vsnprintf conform to C99 */
|
||||
|
||||
static __inline void
|
||||
ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr)
|
||||
{
|
||||
vsnprintf(buffer, size_of_buffer, format, argptr);
|
||||
}
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/*
|
||||
* Use g_vsnprintf. On Linux and macOS these should be a thin wrapper around
|
||||
* vsprintf.
|
||||
*/
|
||||
|
||||
static inline void
|
||||
ws_vsnprintf(char *buffer, size_t size_of_buffer, const char *format, va_list argptr)
|
||||
{
|
||||
g_vsnprintf(buffer, (gulong) size_of_buffer, format, argptr);
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef _WIN32
|
||||
static __inline void
|
||||
#else
|
||||
static inline void
|
||||
#endif
|
||||
ws_snprintf(char *buffer, size_t size_of_buffer, const char * format, ...) {
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, format);
|
||||
ws_vsnprintf(buffer, size_of_buffer, format, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
/* This is intended to fool checkAPIs.pl for places that have "debugging"
|
||||
(using printf) usually wrapped in an #ifdef, but checkAPIs.pl isn't smart
|
||||
enough to figure that out.
|
||||
|
@ -71,8 +19,4 @@ debugging context has a protocol tree.
|
|||
*/
|
||||
#define ws_debug_printf printf
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __WS_PRINTF_H__ */
|
||||
|
|
Loading…
Reference in New Issue