aboutsummaryrefslogtreecommitdiff
path: root/ncurses/trace
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2014-03-01 00:40:26 +0000
committerXin LI <delphij@FreeBSD.org>2014-03-01 00:40:26 +0000
commitcea297eb34d2361e79529034397465068ae34ecd (patch)
treefbc3775582ebd1e6f026931751cfab6c588b643c /ncurses/trace
parent6826a395a618014c4541ff6a654be0d3afb392a1 (diff)
downloadsrc-cea297eb34d2361e79529034397465068ae34ecd.tar.gz
src-cea297eb34d2361e79529034397465068ae34ecd.zip
Vendor import of ncurses 5.9 20140222 snapshot.vendor/ncurses/5.9-20140222
Notes
Notes: svn path=/vendor/ncurses/dist/; revision=262639 svn path=/vendor/ncurses/5.9-20140222/; revision=262640; tag=vendor/ncurses/5.9-20140222
Diffstat (limited to 'ncurses/trace')
-rw-r--r--ncurses/trace/lib_trace.c23
-rw-r--r--ncurses/trace/lib_traceatr.c49
-rw-r--r--ncurses/trace/lib_tracebits.c24
-rw-r--r--ncurses/trace/lib_tracechr.c15
-rw-r--r--ncurses/trace/lib_tracedmp.c8
-rw-r--r--ncurses/trace/lib_tracemse.c44
-rw-r--r--ncurses/trace/trace_buf.c11
-rw-r--r--ncurses/trace/trace_tries.c37
-rw-r--r--ncurses/trace/varargs.c23
-rw-r--r--ncurses/trace/visbuf.c50
10 files changed, 171 insertions, 113 deletions
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
index a726901d4a3a..cec01de517f8 100644
--- a/ncurses/trace/lib_trace.c
+++ b/ncurses/trace/lib_trace.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -47,7 +47,7 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_trace.c,v 1.76 2010/12/19 01:21:19 tom Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.82 2013/07/06 19:42:09 tom Exp $")
NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
@@ -103,9 +103,9 @@ trace(const unsigned int tracelevel)
}
TracePath[size] = '\0';
assert(strlen(TracePath) <= size);
- strcat(TracePath, "/trace");
+ _nc_STRCAT(TracePath, "/trace", sizeof(TracePath));
if (_nc_is_dir_path(TracePath)) {
- strcat(TracePath, ".log");
+ _nc_STRCAT(TracePath, ".log", sizeof(TracePath));
}
}
@@ -121,7 +121,7 @@ trace(const unsigned int tracelevel)
* end of each line. This is useful in case the program dies.
*/
#if HAVE_SETVBUF /* ANSI */
- (void) setvbuf(TraceFP, (char *) 0, _IOLBF, 0);
+ (void) setvbuf(TraceFP, (char *) 0, _IOLBF, (size_t) 0);
#elif HAVE_SETBUF /* POSIX */
(void) setbuffer(TraceFP, (char *) 0);
#endif
@@ -185,9 +185,9 @@ _nc_va_tracef(const char *fmt, va_list ap)
if ((pthread_self))
# endif
#ifdef __MINGW32__
- fprintf(TraceFP, "%#lx:", (long) (void *) pthread_self().p);
+ fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self().p);
#else
- fprintf(TraceFP, "%#lx:", (long) (void *) pthread_self());
+ fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self());
#endif
#endif
if (before || after) {
@@ -218,7 +218,7 @@ _tracef(const char *fmt,...)
/* Trace 'bool' return-values */
NCURSES_EXPORT(NCURSES_BOOL)
-_nc_retrace_bool(NCURSES_BOOL code)
+_nc_retrace_bool(int code)
{
T((T_RETURN("%s"), code ? "TRUE" : "FALSE"));
return code;
@@ -226,10 +226,10 @@ _nc_retrace_bool(NCURSES_BOOL code)
/* Trace 'char' return-values */
NCURSES_EXPORT(char)
-_nc_retrace_char(char code)
+_nc_retrace_char(int code)
{
T((T_RETURN("%c"), code));
- return code;
+ return (char) code;
}
/* Trace 'int' return-values */
@@ -339,8 +339,9 @@ _nc_locked_tracef(const char *fmt,...)
_nc_va_tracef(fmt, ap);
va_end(ap);
- if (--(_nc_globals.nested_tracef) == 0)
+ if (--(_nc_globals.nested_tracef) == 0) {
_nc_unlock_global(tracef);
+ }
}
#endif /* USE_REENTRANT */
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
index 35ba0d3e6797..5fb0df95f4fd 100644
--- a/ncurses/trace/lib_traceatr.c
+++ b/ncurses/trace/lib_traceatr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -43,10 +43,13 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_traceatr.c,v 1.74 2011/01/22 19:48:01 tom Exp $")
+MODULE_ID("$Id: lib_traceatr.c,v 1.81 2014/02/01 22:09:27 tom Exp $")
#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
+#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
+#define COLOR_BUF_SIZE(num) (sizeof(my_buffer[num]))
+
#ifdef TRACE
static const char l_brace[] = StringOf(L_BRACE);
@@ -65,9 +68,12 @@ color_of(int c)
my_cached = c;
my_select = !my_select;
if (c == COLOR_DEFAULT)
- strcpy(my_buffer[my_select], "default");
+ _nc_STRCPY(my_buffer[my_select], "default",
+ COLOR_BUF_SIZE(my_select));
else
- sprintf(my_buffer[my_select], "color%d", c);
+ _nc_SPRINTF(my_buffer[my_select],
+ _nc_SLIMIT(COLOR_BUF_SIZE(my_select))
+ "color%d", c);
}
return my_buffer[my_select];
}
@@ -97,6 +103,9 @@ _traceattr2(int bufnum, chtype newmode)
{ A_CHARTEXT, "A_CHARTEXT" },
{ A_NORMAL, "A_NORMAL" },
{ A_COLOR, "A_COLOR" },
+#if USE_ITALIC
+ { A_ITALIC, "A_ITALIC" },
+#endif
/* *INDENT-ON* */
}
@@ -120,14 +129,14 @@ _traceattr2(int bufnum, chtype newmode)
;
size_t n;
char temp[80];
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
if (result != 0) {
unsigned save_nc_tracing = _nc_tracing;
_nc_tracing = 0;
- strcpy(result, l_brace);
+ _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
for (n = 0; n < SIZEOF(names); n++) {
if ((newmode & names[n].val) != 0) {
@@ -139,18 +148,20 @@ _traceattr2(int bufnum, chtype newmode)
short pairnum = (short) PairNumber(newmode);
#ifdef USE_TERMLIB
/* pair_content lives in libncurses */
- (void) sprintf(temp, "{%d}", pairnum);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d}", pairnum);
#else
- short fg, bg;
+ NCURSES_COLOR_T fg, bg;
if (pair_content(pairnum, &fg, &bg) == OK) {
- (void) sprintf(temp,
- "{%d = {%s, %s}}",
- pairnum,
- COLOR_OF(fg),
- COLOR_OF(bg));
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d = {%s, %s}}",
+ pairnum,
+ COLOR_OF(fg),
+ COLOR_OF(bg));
} else {
- (void) sprintf(temp, "{%d}", pairnum);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d}", pairnum);
}
#endif
result = _nc_trace_bufcat(bufnum, temp);
@@ -243,7 +254,7 @@ _nc_altcharset_name(attr_t attr, chtype ch)
#if NCURSES_SP_FUNCS
(void) sp;
#endif
- if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
+ if (SP_PARM != 0 && (attr & A_ALTCHARSET) && (acs_chars != 0)) {
char *cp;
char *found = 0;
const ALT_NAMES *strp;
@@ -271,10 +282,10 @@ NCURSES_EXPORT(char *)
_tracechtype2(int bufnum, chtype ch)
{
const char *found;
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
if (result != 0) {
- strcpy(result, l_brace);
+ _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
(void) _nc_trace_bufcat(bufnum, found);
} else
@@ -311,12 +322,12 @@ _nc_retrace_chtype(chtype code)
NCURSES_EXPORT(char *)
_tracecchar_t2(int bufnum, const cchar_t *ch)
{
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
attr_t attr;
const char *found;
if (result != 0) {
- strcpy(result, l_brace);
+ _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
if (ch != 0) {
attr = AttrOfD(ch);
if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c
index d19d0e420acc..7d8325a828f4 100644
--- a/ncurses/trace/lib_tracebits.c
+++ b/ncurses/trace/lib_tracebits.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2008,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -34,11 +34,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_tracebits.c,v 1.19 2011/01/09 00:23:03 tom Exp $")
-
-#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
-#define _POSIX_SOURCE
-#endif
+MODULE_ID("$Id: lib_tracebits.c,v 1.23 2012/06/09 19:55:46 tom Exp $")
#if HAVE_SYS_TERMIO_H
#include <sys/termio.h> /* needed for ISC */
@@ -80,22 +76,24 @@ typedef struct {
const char *name;
} BITNAMES;
+#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
+
static void
lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
{
const BITNAMES *sp;
- (void) strcat(buf, label);
- (void) strcat(buf, ": {");
+ _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
+ _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
for (sp = table; sp->name; sp++)
if (sp->val != 0
&& (val & sp->val) == sp->val) {
- (void) strcat(buf, sp->name);
- (void) strcat(buf, ", ");
+ _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
+ _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0));
}
if (buf[strlen(buf) - 2] == ',')
buf[strlen(buf) - 2] = '\0';
- (void) strcat(buf, "} ");
+ _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0));
}
NCURSES_EXPORT(char *)
@@ -192,7 +190,7 @@ _nc_trace_ttymode(TTY * tty)
CS_DATA(CS8),
};
const char *result = "CSIZE? ";
- int value = (tty->c_cflag & CSIZE);
+ int value = (int) (tty->c_cflag & CSIZE);
unsigned n;
if (value != 0) {
@@ -203,7 +201,7 @@ _nc_trace_ttymode(TTY * tty)
}
}
}
- strcat(buf, result);
+ _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
}
#endif
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
index a1f9f5aa2706..8977f752b505 100644
--- a/ncurses/trace/lib_tracechr.c
+++ b/ncurses/trace/lib_tracechr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -39,10 +39,12 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_tracechr.c,v 1.20 2009/04/18 22:48:29 tom Exp $")
+MODULE_ID("$Id: lib_tracechr.c,v 1.22 2012/02/22 22:40:24 tom Exp $")
#ifdef TRACE
+#define MyBufSize sizeof(_nc_globals.tracechr_buf)
+
NCURSES_EXPORT(char *)
_nc_tracechar(SCREEN *sp, int ch)
{
@@ -55,19 +57,22 @@ _nc_tracechar(SCREEN *sp, int ch)
name = safe_keyname(SP_PARM, ch);
if (name == 0 || *name == '\0')
name = "NULL";
- (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "'%.30s' = %#03o", name, ch);
} else if (!is8bits(ch) || !isprint(UChar(ch))) {
/*
* workaround for glibc bug:
* sprintf changes the result from unctrl() to an empty string if it
* does not correspond to a valid multibyte sequence.
*/
- (void) sprintf(MyBuffer, "%#03o", ch);
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "%#03o", ch);
} else {
name = safe_unctrl(SP_PARM, (chtype) ch);
if (name == 0 || *name == 0)
name = "null"; /* shouldn't happen */
- (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "'%.30s' = %#03o", name, ch);
}
return (MyBuffer);
}
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
index c7fcbf2e0d56..0fda15b252e6 100644
--- a/ncurses/trace/lib_tracedmp.c
+++ b/ncurses/trace/lib_tracedmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -39,7 +39,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_tracedmp.c,v 1.32 2009/04/18 21:01:38 tom Exp $")
+MODULE_ID("$Id: lib_tracedmp.c,v 1.34 2012/10/27 20:54:42 tom Exp $")
#ifdef TRACE
@@ -70,6 +70,8 @@ _tracedump(const char *name, WINDOW *win)
if (++width + 1 > (int) my_length) {
my_length = (unsigned) (2 * (width + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
+ if (my_buffer == 0)
+ return;
}
for (n = 0; n <= win->_maxy; ++n) {
@@ -111,7 +113,7 @@ _tracedump(const char *name, WINDOW *win)
if (multicolumn) {
ep = my_buffer;
for (j = 0; j < width; ++j) {
- chtype test = WidecExt(win->_line[n].text[j]);
+ int test = WidecExt(win->_line[n].text[j]);
if (test) {
ep[j] = (char) (test + '0');
} else {
diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c
index 1afd15d2e785..51ffa2ef7634 100644
--- a/ncurses/trace/lib_tracemse.c
+++ b/ncurses/trace/lib_tracemse.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -38,7 +38,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_tracemse.c,v 1.18 2011/01/22 19:48:08 tom Exp $")
+MODULE_ID("$Id: lib_tracemse.c,v 1.21 2012/12/15 23:51:19 tom Exp $")
#ifdef TRACE
@@ -47,7 +47,11 @@ MODULE_ID("$Id: lib_tracemse.c,v 1.18 2011/01/22 19:48:08 tom Exp $")
static char *
_trace_mmask_t(SCREEN *sp, mmask_t code)
{
-#define SHOW(m, s) if ((code & m) == m) strcat(strcat(my_buffer, s), ", ")
+#define SHOW(m, s) \
+ if ((code & m) == m) { \
+ _nc_STRCAT(my_buffer, s, sizeof(my_buffer)); \
+ _nc_STRCAT(my_buffer, ", ", sizeof(my_buffer)); \
+ }
SHOW(BUTTON1_RELEASED, "release-1");
SHOW(BUTTON1_PRESSED, "press-1");
@@ -110,23 +114,33 @@ _trace_mmask_t(SCREEN *sp, mmask_t code)
NCURSES_EXPORT(char *)
_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
{
- (void) sprintf(my_buffer, TRACEMSE_FMT,
- ep->id,
- ep->x,
- ep->y,
- ep->z,
- (unsigned long) ep->bstate);
-
- (void) _trace_mmask_t(sp, ep->bstate);
- (void) strcat(my_buffer, "}");
- return (my_buffer);
+ char *result = 0;
+
+ if (sp != 0) {
+ _nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
+ TRACEMSE_FMT,
+ ep->id,
+ ep->x,
+ ep->y,
+ ep->z,
+ (unsigned long) ep->bstate);
+
+ (void) _trace_mmask_t(sp, ep->bstate);
+ _nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
+ result = (my_buffer);
+ }
+ return result;
}
NCURSES_EXPORT(mmask_t)
_nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
{
- *my_buffer = '\0';
- T((T_RETURN("{%s}"), _trace_mmask_t(sp, code)));
+ if (sp != 0) {
+ *my_buffer = '\0';
+ T((T_RETURN("{%s}"), _trace_mmask_t(sp, code)));
+ } else {
+ T((T_RETURN("{?}")));
+ }
return code;
}
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
index 46baba4796b2..84a7a0ce076c 100644
--- a/ncurses/trace/trace_buf.c
+++ b/ncurses/trace/trace_buf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,7 +35,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_buf.c,v 1.17 2011/01/22 19:48:16 tom Exp $")
+MODULE_ID("$Id: trace_buf.c,v 1.20 2012/02/22 22:34:31 tom Exp $")
#ifdef TRACE
@@ -103,13 +103,14 @@ _nc_trace_buf(int bufnum, size_t want)
NCURSES_EXPORT(char *)
_nc_trace_bufcat(int bufnum, const char *value)
{
- char *buffer = _nc_trace_alloc(bufnum, 0);
+ char *buffer = _nc_trace_alloc(bufnum, (size_t) 0);
if (buffer != 0) {
size_t have = strlen(buffer);
+ size_t need = strlen(value) + have;
- buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value));
+ buffer = _nc_trace_alloc(bufnum, 1 + need);
if (buffer != 0)
- (void) strcpy(buffer + have, value);
+ _nc_STRCPY(buffer + have, value, need);
}
return buffer;
diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c
index d3380131ecac..50ba01683e16 100644
--- a/ncurses/trace/trace_tries.c
+++ b/ncurses/trace/trace_tries.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999-2009,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,7 +35,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_tries.c,v 1.16 2011/01/09 00:23:27 tom Exp $")
+MODULE_ID("$Id: trace_tries.c,v 1.17 2012/10/27 20:50:50 tom Exp $")
#ifdef TRACE
#define my_buffer _nc_globals.tracetry_buf
@@ -49,28 +49,31 @@ recur_tries(TRIES * tree, unsigned level)
my_buffer = (unsigned char *) _nc_doalloc(my_buffer, my_length);
}
- while (tree != 0) {
- if ((my_buffer[level] = tree->ch) == 0)
- my_buffer[level] = 128;
- my_buffer[level + 1] = 0;
- if (tree->value != 0) {
- _tracef("%5d: %s (%s)", tree->value,
- _nc_visbuf((char *) my_buffer), keyname(tree->value));
+ if (my_buffer != 0) {
+ while (tree != 0) {
+ if ((my_buffer[level] = tree->ch) == 0)
+ my_buffer[level] = 128;
+ my_buffer[level + 1] = 0;
+ if (tree->value != 0) {
+ _tracef("%5d: %s (%s)", tree->value,
+ _nc_visbuf((char *) my_buffer), keyname(tree->value));
+ }
+ if (tree->child)
+ recur_tries(tree->child, level + 1);
+ tree = tree->sibling;
}
- if (tree->child)
- recur_tries(tree->child, level + 1);
- tree = tree->sibling;
}
}
NCURSES_EXPORT(void)
_nc_trace_tries(TRIES * tree)
{
- my_buffer = typeMalloc(unsigned char, my_length = 80);
- _tracef("BEGIN tries %p", (void *) tree);
- recur_tries(tree, 0);
- _tracef(". . . tries %p", (void *) tree);
- free(my_buffer);
+ if ((my_buffer = typeMalloc(unsigned char, my_length = 80)) != 0) {
+ _tracef("BEGIN tries %p", (void *) tree);
+ recur_tries(tree, 0);
+ _tracef(". . . tries %p", (void *) tree);
+ free(my_buffer);
+ }
}
#else
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
index 541173d27459..66252d88db21 100644
--- a/ncurses/trace/varargs.c
+++ b/ncurses/trace/varargs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-2008,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -34,7 +34,7 @@
#include <ctype.h>
-MODULE_ID("$Id: varargs.c,v 1.8 2008/11/16 00:19:59 juergen Exp $")
+MODULE_ID("$Id: varargs.c,v 1.11 2012/10/27 21:03:28 tom Exp $")
#ifdef TRACE
@@ -149,25 +149,32 @@ _nc_varargs(const char *fmt, va_list ap)
param = buffer;
switch (used) {
case atInteger:
- sprintf(buffer, "%d", ival);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%d", ival);
break;
case atFloat:
- sprintf(buffer, "%f", fval);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%f", fval);
break;
case atPoint:
- sprintf(buffer, "%p", pval);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%p", pval);
break;
case atString:
param = _nc_visbuf2(1, sval);
break;
case atUnknown:
default:
- strcpy(buffer, "?");
+ _nc_STRCPY(buffer, "?", sizeof(buffer));
break;
}
MyLength += strlen(param) + 2;
MyBuffer = typeRealloc(char, MyLength, MyBuffer);
- sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
+ if (MyBuffer != 0) {
+ _nc_SPRINTF(MyBuffer + strlen(MyBuffer),
+ _nc_SLIMIT(MyLength - strlen(MyBuffer))
+ ", %s", param);
+ }
}
}
used = atUnknown;
@@ -177,7 +184,7 @@ _nc_varargs(const char *fmt, va_list ap)
}
}
- return (MyBuffer);
+ return (MyBuffer ? MyBuffer : dummy);
}
#else
EMPTY_MODULE(_nc_varargs)
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
index 66da4f4beca3..effa84352b7d 100644
--- a/ncurses/trace/visbuf.c
+++ b/ncurses/trace/visbuf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2001-2009,2010 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-2012,2014 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -42,7 +42,7 @@
#include <tic.h>
#include <ctype.h>
-MODULE_ID("$Id: visbuf.c,v 1.37 2010/05/29 18:51:41 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.43 2014/02/23 01:21:08 tom Exp $")
#define NUM_VISBUFS 4
@@ -55,13 +55,21 @@ static const char l_brace[] = StringOf(L_BRACE);
static const char r_brace[] = StringOf(R_BRACE);
#endif
+#if USE_STRING_HACKS && HAVE_SNPRINTF
+#define VisChar(tp, chr, limit) _nc_vischar(tp, chr, limit)
+#define LIMIT_ARG ,size_t limit
+#else
+#define VisChar(tp, chr, limit) _nc_vischar(tp, chr)
+#define LIMIT_ARG /* nothing */
+#endif
+
static char *
-_nc_vischar(char *tp, unsigned c)
+_nc_vischar(char *tp, unsigned c LIMIT_ARG)
{
if (c == '"' || c == '\\') {
*tp++ = '\\';
*tp++ = (char) c;
- } else if (is7bits(c) && (isgraph(c) || c == ' ')) {
+ } else if (is7bits((int)c) && (isgraph((int)c) || c == ' ')) {
*tp++ = (char) c;
} else if (c == '\n') {
*tp++ = '\\';
@@ -84,7 +92,8 @@ _nc_vischar(char *tp, unsigned c)
*tp++ = '^';
*tp++ = (char) ('@' + c);
} else {
- sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c));
+ _nc_SPRINTF(tp, _nc_SLIMIT(limit)
+ "\\%03lo", (unsigned long) ChCharOf(c));
tp += strlen(tp);
}
*tp = 0;
@@ -97,6 +106,7 @@ _nc_visbuf2n(int bufnum, const char *buf, int len)
const char *vbuf = 0;
char *tp;
int c;
+ int count;
if (buf == 0)
return ("(null)");
@@ -106,6 +116,7 @@ _nc_visbuf2n(int bufnum, const char *buf, int len)
if (len < 0)
len = (int) strlen(buf);
+ count = len;
#ifdef TRACE
vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len));
#else
@@ -124,8 +135,8 @@ _nc_visbuf2n(int bufnum, const char *buf, int len)
#endif
if (tp != 0) {
*tp++ = D_QUOTE;
- while ((--len >= 0) && (c = *buf++) != '\0') {
- tp = _nc_vischar(tp, UChar(c));
+ while ((--count >= 0) && (c = *buf++) != '\0') {
+ tp = VisChar(tp, UChar(c), NormalLen(len));
}
*tp++ = D_QUOTE;
*tp = '\0';
@@ -175,6 +186,7 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len)
const char *vbuf;
char *tp;
wchar_t c;
+ int count;
if (buf == 0)
return ("(null)");
@@ -182,6 +194,7 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len)
if (len < 0)
len = (int) wcslen(buf);
+ count = len;
#ifdef TRACE
vbuf = tp = _nc_trace_buf(bufnum, WideLen(len));
#else
@@ -193,15 +206,16 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len)
#endif
if (tp != 0) {
*tp++ = D_QUOTE;
- while ((--len >= 0) && (c = *buf++) != '\0') {
+ while ((--count >= 0) && (c = *buf++) != '\0') {
char temp[CCHARW_MAX + 80];
int j = wctomb(temp, c), k;
if (j <= 0) {
- sprintf(temp, "\\u%08X", (unsigned) c);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "\\u%08X", (unsigned) c);
j = (int) strlen(temp);
}
for (k = 0; k < j; ++k) {
- tp = _nc_vischar(tp, UChar(temp[k]));
+ tp = VisChar(tp, UChar(temp[k]), WideLen(len));
}
}
*tp++ = D_QUOTE;
@@ -248,10 +262,12 @@ _nc_viswibuf(const wint_t *buf)
else
mybuf = typeMalloc(wchar_t, mylen);
}
- for (n = 0; buf[n] != 0; ++n) {
- mybuf[n] = (wchar_t) buf[n];
+ if (mybuf != 0) {
+ for (n = 0; buf[n] != 0; ++n) {
+ mybuf[n] = (wchar_t) buf[n];
+ }
+ mybuf[n] = L'\0';
}
- mybuf[n] = L'\0';
return _nc_viswbuf2(0, mybuf);
}
@@ -261,7 +277,7 @@ _nc_viswibuf(const wint_t *buf)
NCURSES_EXPORT(const char *)
_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
{
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
int first;
const char *found;
@@ -315,7 +331,7 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
break;
for (k = 0; k < PUTC_n; k++) {
char temp[80];
- _nc_vischar(temp, UChar(PUTC_buf[k]));
+ VisChar(temp, UChar(PUTC_buf[k]), sizeof(temp));
(void) _nc_trace_bufcat(bufnum, temp);
}
}
@@ -323,8 +339,8 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
#else
{
char temp[80];
- _nc_vischar(temp, UChar(buf[j]));
- result = _nc_trace_bufcat(bufnum, temp);
+ VisChar(temp, UChar(buf[j]), sizeof(temp));
+ (void) _nc_trace_bufcat(bufnum, temp);
}
#endif /* USE_WIDEC_SUPPORT */
}