* utils.c (safe_strerror): Use xsnprintf instead of sprintf.

(decimal2str, octal2str): Change to return a string allocated by
get_cell.  Use xsnprint instead of snprintf.
(paddr_u, paddr_d): Adjust for changed calling convention of
decimal2str.
(phex, phex_nz, hex_string): Use xsnprintf instead of snprintf.
(int_string): Likewise.  Adjust for changed calling convention of
decimal2str and octal2str.
This commit is contained in:
Mark Kettenis
2005-03-18 20:46:38 +00:00
parent f79d2c3cf8
commit 8cf46f625a
2 changed files with 64 additions and 41 deletions

View File

@ -1,9 +1,20 @@
2005-03-18 Mark Kettenis <kettenis@gnu.org>
* utils.c (safe_strerror): Use xsnprintf instead of sprintf.
(decimal2str, octal2str): Change to return a string allocated by
get_cell. Use xsnprint instead of snprintf.
(paddr_u, paddr_d): Adjust for changed calling convention of
decimal2str.
(phex, phex_nz, hex_string): Use xsnprintf instead of snprintf.
(int_string): Likewise. Adjust for changed calling convention of
decimal2str and octal2str.
2005-03-18 Kevin Buettner <kevinb@redhat.com> 2005-03-18 Kevin Buettner <kevinb@redhat.com>
* frv-linux-tdep.c (frv_linux_sigcontext_reg_addr): Update comments. * frv-linux-tdep.c (frv_linux_sigcontext_reg_addr): Update comments.
Adjust incorrectly computed constant for realtime signal frame. Adjust incorrectly computed constant for realtime signal frame.
2005-03-18 Mark Kettenis <kettenis@elgar.sibelius.xs4all.nl> 2005-03-18 Mark Kettenis <kettenis@gnu.org>
From Ralf Corsepius <ralf.corsepius@rtems.org> From Ralf Corsepius <ralf.corsepius@rtems.org>
* configure.tgt: Add m68*-*-rtems*. * configure.tgt: Add m68*-*-rtems*.

View File

@ -846,12 +846,12 @@ char *
safe_strerror (int errnum) safe_strerror (int errnum)
{ {
char *msg; char *msg;
static char buf[32];
msg = strerror (errnum); msg = strerror (errnum);
if (msg == NULL) if (msg == NULL)
{ {
sprintf (buf, "(undocumented errno %d)", errnum); static char buf[32];
xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
msg = buf; msg = buf;
} }
return (msg); return (msg);
@ -2620,12 +2620,14 @@ paddress (CORE_ADDR addr)
return hex_string (addr); return hex_string (addr);
} }
static void static char *
decimal2str (char *paddr_str, char *sign, ULONGEST addr, int width) decimal2str (char *sign, ULONGEST addr, int width)
{ {
/* steal code from valprint.c:print_decimal(). Should this worry /* Steal code from valprint.c:print_decimal(). Should this worry
about the real size of addr as the above does? */ about the real size of addr as the above does? */
unsigned long temp[3]; unsigned long temp[3];
char *str = get_cell ();
int i = 0; int i = 0;
do do
{ {
@ -2635,31 +2637,38 @@ decimal2str (char *paddr_str, char *sign, ULONGEST addr, int width)
width -= 9; width -= 9;
} }
while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0]))); while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
width += 9; width += 9;
if (width < 0) if (width < 0)
width = 0; width = 0;
switch (i) switch (i)
{ {
case 1: case 1:
sprintf (paddr_str, "%s%0*lu", sign, width, temp[0]); xsnprintf (str, CELLSIZE, "%s%0*lu", sign, width, temp[0]);
break; break;
case 2: case 2:
sprintf (paddr_str, "%s%0*lu%09lu", sign, width, temp[1], temp[0]); xsnprintf (str, CELLSIZE, "%s%0*lu%09lu", sign, width,
temp[1], temp[0]);
break; break;
case 3: case 3:
sprintf (paddr_str, "%s%0*lu%09lu%09lu", sign, width, xsnprintf (str, CELLSIZE, "%s%0*lu%09lu%09lu", sign, width,
temp[2], temp[1], temp[0]); temp[2], temp[1], temp[0]);
break; break;
default: default:
internal_error (__FILE__, __LINE__, internal_error (__FILE__, __LINE__,
_("failed internal consistency check")); _("failed internal consistency check"));
} }
return str;
} }
static void static char *
octal2str (char *paddr_str, ULONGEST addr, int width) octal2str (ULONGEST addr, int width)
{ {
unsigned long temp[3]; unsigned long temp[3];
char *str = get_cell ();
int i = 0; int i = 0;
do do
{ {
@ -2669,76 +2678,78 @@ octal2str (char *paddr_str, ULONGEST addr, int width)
width -= 10; width -= 10;
} }
while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0]))); while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
width += 10; width += 10;
if (width < 0) if (width < 0)
width = 0; width = 0;
switch (i) switch (i)
{ {
case 1: case 1:
if (temp[0] == 0) if (temp[0] == 0)
sprintf (paddr_str, "%*o", width, 0); xsnprintf (str, CELLSIZE, "%*o", width, 0);
else else
sprintf (paddr_str, "0%0*lo", width, temp[0]); xsnprintf (str, CELLSIZE, "0%0*lo", width, temp[0]);
break; break;
case 2: case 2:
sprintf (paddr_str, "0%0*lo%010lo", width, temp[1], temp[0]); xsnprintf (str, CELLSIZE, "0%0*lo%010lo", width, temp[1], temp[0]);
break; break;
case 3: case 3:
sprintf (paddr_str, "0%0*lo%010lo%010lo", width, xsnprintf (str, CELLSIZE, "0%0*lo%010lo%010lo", width,
temp[2], temp[1], temp[0]); temp[2], temp[1], temp[0]);
break; break;
default: default:
internal_error (__FILE__, __LINE__, internal_error (__FILE__, __LINE__,
_("failed internal consistency check")); _("failed internal consistency check"));
} }
return str;
} }
char * char *
paddr_u (CORE_ADDR addr) paddr_u (CORE_ADDR addr)
{ {
char *paddr_str = get_cell (); return decimal2str ("", addr, 0);
decimal2str (paddr_str, "", addr, 0);
return paddr_str;
} }
char * char *
paddr_d (LONGEST addr) paddr_d (LONGEST addr)
{ {
char *paddr_str = get_cell ();
if (addr < 0) if (addr < 0)
decimal2str (paddr_str, "-", -addr, 0); return decimal2str ("-", -addr, 0);
else else
decimal2str (paddr_str, "", addr, 0); return decimal2str ("", addr, 0);
return paddr_str;
} }
/* eliminate warning from compiler on 32-bit systems */ /* Eliminate warning from compiler on 32-bit systems. */
static int thirty_two = 32; static int thirty_two = 32;
char * char *
phex (ULONGEST l, int sizeof_l) phex (ULONGEST l, int sizeof_l)
{ {
char *str; char *str;
switch (sizeof_l) switch (sizeof_l)
{ {
case 8: case 8:
str = get_cell (); str = get_cell ();
sprintf (str, "%08lx%08lx", xsnprintf (str, CELLSIZE, "%08lx%08lx",
(unsigned long) (l >> thirty_two), (unsigned long) (l >> thirty_two),
(unsigned long) (l & 0xffffffff)); (unsigned long) (l & 0xffffffff));
break; break;
case 4: case 4:
str = get_cell (); str = get_cell ();
sprintf (str, "%08lx", (unsigned long) l); xsnprintf (str, CELLSIZE, "%08lx", (unsigned long) l);
break; break;
case 2: case 2:
str = get_cell (); str = get_cell ();
sprintf (str, "%04x", (unsigned short) (l & 0xffff)); xsnprintf (str, CELLSIZE, "%04x", (unsigned short) (l & 0xffff));
break; break;
default: default:
str = phex (l, sizeof (l)); str = phex (l, sizeof (l));
break; break;
} }
return str; return str;
} }
@ -2746,6 +2757,7 @@ char *
phex_nz (ULONGEST l, int sizeof_l) phex_nz (ULONGEST l, int sizeof_l)
{ {
char *str; char *str;
switch (sizeof_l) switch (sizeof_l)
{ {
case 8: case 8:
@ -2753,23 +2765,26 @@ phex_nz (ULONGEST l, int sizeof_l)
unsigned long high = (unsigned long) (l >> thirty_two); unsigned long high = (unsigned long) (l >> thirty_two);
str = get_cell (); str = get_cell ();
if (high == 0) if (high == 0)
sprintf (str, "%lx", (unsigned long) (l & 0xffffffff)); xsnprintf (str, CELLSIZE, "%lx",
(unsigned long) (l & 0xffffffff));
else else
sprintf (str, "%lx%08lx", high, (unsigned long) (l & 0xffffffff)); xsnprintf (str, CELLSIZE, "%lx%08lx", high,
(unsigned long) (l & 0xffffffff));
break; break;
} }
case 4: case 4:
str = get_cell (); str = get_cell ();
sprintf (str, "%lx", (unsigned long) l); xsnprintf (str, CELLSIZE, "%lx", (unsigned long) l);
break; break;
case 2: case 2:
str = get_cell (); str = get_cell ();
sprintf (str, "%x", (unsigned short) (l & 0xffff)); xsnprintf (str, CELLSIZE, "%x", (unsigned short) (l & 0xffff));
break; break;
default: default:
str = phex_nz (l, sizeof (l)); str = phex_nz (l, sizeof (l));
break; break;
} }
return str; return str;
} }
@ -2779,7 +2794,7 @@ char *
hex_string (LONGEST num) hex_string (LONGEST num)
{ {
char *result = get_cell (); char *result = get_cell ();
snprintf (result, CELLSIZE, "0x%s", phex_nz (num, sizeof (num))); xsnprintf (result, CELLSIZE, "0x%s", phex_nz (num, sizeof (num)));
return result; return result;
} }
@ -2833,17 +2848,14 @@ int_string (LONGEST val, int radix, int is_signed, int width,
} }
case 10: case 10:
{ {
char *result = get_cell ();
if (is_signed && val < 0) if (is_signed && val < 0)
decimal2str (result, "-", -val, width); return decimal2str ("-", -val, width);
else else
decimal2str (result, "", val, width); return decimal2str ("", val, width);
return result;
} }
case 8: case 8:
{ {
char *result = get_cell (); char *result = octal2str (val, width);
octal2str (result, val, width);
if (use_c_format || val == 0) if (use_c_format || val == 0)
return result; return result;
else else