Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

used snprintf function instead of sprintf #808

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions sys/dev/netmap/netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,30 +709,42 @@ nm_bound_var(u_int *v, u_int dflt, u_int lo, u_int hi, const char *msg)

/*
* packet-dump function, user-supplied or static buffer.
* The destination buffer must be at least 30+4*len
* The destination buffer must be at least (((len-1)/16+1) * (12 + 64 + 1) + 51 + 1) bytes size.
*/
const char *
nm_dump_buf(char *p, int len, int lim, char *dst)
{
static char _dst[8192];
int i, j, i0;
int i, j, i0, print_size;
static char hex[] ="0123456789abcdef";
char *o; /* output position */
char *dst_end;

#define P_HI(x) hex[((x) & 0xf0)>>4]
#define P_LO(x) hex[((x) & 0xf)]
#define P_C(x) ((x) >= 0x20 && (x) <= 0x7e ? (x) : '.')
if (!dst)
if (!dst) {
dst = _dst;
dst_end = dst + sizeof(_dst);
} else {
/*
* 51 == strlen("buf 0x0xffffffffffff len 2147483647 lim 2147483647\n")
* 12 == strlen("2147483647: ")
*/
dst_end = dst + ((len-1)/16+1) * (12 + 64 + 1) + 51 + 1;
}
if (lim <= 0 || lim > len)
lim = len;
o = dst;
sprintf(o, "buf 0x%p len %d lim %d\n", p, len, lim);
o += strlen(o);
print_size = snprintf(o, dst_end-o, "buf 0x%p len %d lim %d\n", p, len, lim);
if (print_size >= dst_end-o) return dst;
o += print_size;
/* hexdump routine */
for (i = 0; i < lim; ) {
sprintf(o, "%5d: ", i);
o += strlen(o);
print_size = snprintf(o, dst_end-o, "%5d: ", i);
if (print_size >= dst_end-o) return dst;
o += print_size;
if (dst_end-o < 48+16+1+1) return dst;
memset(o, ' ', 48);
i0 = i;
for (j=0; j < 16 && i < lim; i++, j++) {
Expand Down