From d405e0c1f847ff1ed9df43aa8044c517e5e6c71b Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Thu, 14 Apr 2005 09:54:37 +0000 Subject: use snprintf. okay deraadt@ --- gnu/lib/libiberty/src/cplus-dem.c | 13 +++++++------ gnu/lib/libiberty/src/strsignal.c | 4 ++-- gnu/lib/libiberty/src/xstrerror.c | 13 ++++++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'gnu') diff --git a/gnu/lib/libiberty/src/cplus-dem.c b/gnu/lib/libiberty/src/cplus-dem.c index 59afcd371ba..027f5696d32 100644 --- a/gnu/lib/libiberty/src/cplus-dem.c +++ b/gnu/lib/libiberty/src/cplus-dem.c @@ -1063,9 +1063,9 @@ ada_demangle (mangled, option) sizeof (char)); if (mangled[0] == '<') - strcpy (demangled, mangled); + strlcpy (demangled, mangled, demangled_size); else - sprintf (demangled, "<%s>", mangled); + snprintf (demangled, demangled_size, "<%s>", mangled); return demangled; } @@ -1847,7 +1847,7 @@ demangle_integral_value (work, mangled, s) if (value != -1) { char buf[INTBUF_SIZE]; - sprintf (buf, "%d", value); + snprintf (buf, sizeof buf, "%d", value); string_append (s, buf); /* Numbers not otherwise delimited, might have an underscore @@ -3049,7 +3049,8 @@ gnu_special (work, mangled, declp) if (method) { char buf[50]; - sprintf (buf, "virtual function thunk (delta:%d) for ", -delta); + snprintf (buf, sizeof buf, + "virtual function thunk (delta:%d) for ", -delta); string_append (declp, buf); string_append (declp, method); free (method); @@ -3956,7 +3957,7 @@ demangle_fund_type (work, mangled, result) *mangled += min (strlen (*mangled), 2); } sscanf (buf, "%x", &dec); - sprintf (buf, "int%u_t", dec); + snprintf (buf, sizeof buf, "int%u_t", dec); APPEND_BLANK (result); string_append (result, buf); break; @@ -4886,6 +4887,6 @@ string_append_template_idx (s, idx) int idx; { char buf[INTBUF_SIZE + 1 /* 'T' */]; - sprintf(buf, "T%d", idx); + snprintf(buf, sizeof buf, "T%d", idx); string_append (s, buf); } diff --git a/gnu/lib/libiberty/src/strsignal.c b/gnu/lib/libiberty/src/strsignal.c index a8a7d341fef..fcb20d59aa5 100644 --- a/gnu/lib/libiberty/src/strsignal.c +++ b/gnu/lib/libiberty/src/strsignal.c @@ -433,7 +433,7 @@ strsignal (signo) else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL)) { /* In range, but no sys_siglist or no entry at this index. */ - sprintf (buf, "Signal %d", signo); + snprintf (buf, sizeof buf, "Signal %d", signo); msg = (const char *) buf; } else @@ -489,7 +489,7 @@ strsigno (signo) else if ((signal_names == NULL) || (signal_names[signo] == NULL)) { /* In range, but no signal_names or no entry at this index. */ - sprintf (buf, "Signal %d", signo); + snprintf (buf, sizeof buf, "Signal %d", signo); name = (const char *) buf; } else diff --git a/gnu/lib/libiberty/src/xstrerror.c b/gnu/lib/libiberty/src/xstrerror.c index 770b653ba80..25a83e7ee31 100644 --- a/gnu/lib/libiberty/src/xstrerror.c +++ b/gnu/lib/libiberty/src/xstrerror.c @@ -2,6 +2,17 @@ Fri Jun 16 18:30:00 1995 Pat Rankin This code is in the public domain. */ +/* + +@deftypefn Replacement char* xstrerror (int @var{errnum}) + +Behaves exactly like the standard @code{strerror} function, but +will never return a @code{NULL} pointer. + +@end deftypefn + +*/ + #include #include "libiberty.h" @@ -49,7 +60,7 @@ xstrerror (errnum) /* If `errnum' is out of range, result might be NULL. We'll fix that. */ if (!errstr) { - sprintf (xstrerror_buf, ERRSTR_FMT, errnum); + snprintf (xstrerror_buf, sizeof xstrerror_buf, ERRSTR_FMT, errnum); errstr = xstrerror_buf; } return errstr; -- cgit v1.2.3