char labelarr[10];
XmString labelstr;
#if 0
- sprintf(labelarr, "%d", xms->value);
+ int sz = snprintf(labelarr, sizeof(labelarr), "%d", xms->value);
+ assert(sz>=0 && sz<sizeof(labelarr));
labelstr = XmStringCreateLocalized(labelarr);
XtVaSetValues(label, XmNlabelString, labelstr, NULL);
XmStringFree(labelstr);
pushbutton = XmCreatePushButton(paned, "pushbutton", NULL, 0);
text = XmCreateText(paned, "text", NULL, 0);
for (i = 0; i < no_ews; i++) {
- sprintf(buf, "extcli%d", i);
+ int sz = snprintf(buf, sizeof(buf), "extcli%d", i);
+ assert(sz>=0 && sz < sizeof(buf));
emacscli[i] =
XtVaCreateWidget(buf, externalClientWidgetClass, paned,
XmNwidth, 500, XmNheight, 200,
strcpy(labarr, "window:");
for (i = 0; i < no_ews; i++) {
- sprintf(tmpbuf, " %d", XtWindow(emacscli[i]));
+ int sz = snprintf(tmpbuf, sizeof(tmpbuf),
+ " %d", XtWindow(emacscli[i]));
+ assert(sz>=0 && sz<sizeof(tmpbuf));
strcat(labarr, tmpbuf);
}
lab = XmStringCreateLocalized(labarr);
XSetDashes(display, *gc, dash_offset, dash_list, list_length);
}
-load_font(font_info)
-XFontStruct **font_info;
+void
+load_font(XFontStruct **font_info)
{
char *fontname = "9x15";
}
}
-draw_text(win, gc, font_info, win_width, win_height)
-Window win;
-GC gc;
-XFontStruct *font_info;
-unsigned int win_width, win_height;
+void
+draw_text(Window win, GC gc, XFontStruct *font_info, unsigned int win_width, unsigned int win_height)
{
char *string1 = "Hi! I'm a window, who are you?";
char *string2 = "To terminate program; Press any key";
char cd_height[50], cd_width[50], cd_depth[50];
int font_height;
int initial_y_offset, x_offset;
+ int sz;
/* need length for both XTextWidth and XDrawString */
len1 = strlen(string1);
(int)(win_height - font_height), string3, len3);
/* copy numbers into string variables */
- (void)sprintf(cd_height, " Height - %d pixels",
+ sz = snprintf(cd_height, sizeof(cd_height), " Height - %d pixels",
DisplayHeight(display, screen_num));
- (void)sprintf(cd_width, " Width - %d pixels",
+ assert(sz>=0 && sz<sizeof(cd_height));
+
+ sz = snprintf(cd_width, sizeof(cd_width), " Width - %d pixels",
DisplayWidth(display, screen_num));
- (void)sprintf(cd_depth, " Depth - %d plane(s)",
+ assert(sz>=0 && sz<sizeof(cd_width));
+
+ sz = snprintf(cd_depth, sizeof(cd_depth), " Depth - %d plane(s)",
DefaultDepth(display, screen_num));
+ assert(sz>=0 && sz<sizeof(cd_depth));
/* reuse these for same purpose */
len4 = strlen(string4);
#include <stdlib.h>
#include <sys/types.h>
#include <sysfile.h>
+#include <assert.h>
#ifdef HAVE_STRING_H
#include <string.h>
static void tell_emacs_to_resume(int sig)
{
char buffer[GSERV_BUFSZ + 1];
+ int sz;
int s; /* socket / msqid to server */
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
ONN_IPC */
connect_type = make_connection(NULL, 0, &s);
- sprintf(buffer, "(gnuserv-eval '(resume-pid-console %d))",
- (int)getpid());
+ sz = snprintf(buffer, sizeof(buffer), "(gnuserv-eval '(resume-pid-console %d))",
+ (int)getpid());
+ assert(sz>=0 && sz<sizeof(buffer));
send_string(s, buffer);
#ifdef SYSV_IPC
char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
char result[GSERV_BUFSZ + 1];
int i;
+ int sz, msz;
#ifdef INTERNET_DOMAIN_SOCKETS
memset(remotepath, 0, sizeof(remotepath));
#else
connect_type = make_connection(NULL, 0, &s);
#endif
- sprintf(command, "(gnuserv-eval%s '(progn ",
- quick ? "-quickly" : "");
+ sz = snprintf(command, sizeof(command), "(gnuserv-eval%s '(progn ",
+ quick ? "-quickly" : "");
+ assert(sz>=0 && sz<sizeof(command));
send_string(s, command);
if (load_library) {
send_string(s, "(load-library ");
#else
connect_type = make_connection(NULL, 0, &s);
#endif
- sprintf(command, "(gnuserv-eval%s '(progn ",
- quick ? "-quickly" : "");
+ sz = snprintf(command, sizeof(command),
+ "(gnuserv-eval%s '(progn ",
+ quick ? "-quickly" : "");
+ assert(sz>=0 && sz<sizeof(command));
send_string(s, command);
while ((nb = read(fileno(stdin), buffer, GSERV_BUFSZ - 1)) > 0) {
if (suppress_windows_system) {
char *term = getenv("TERM");
+ int sz;
if (!term) {
fprintf(stderr, "%s: unknown terminal type\n",
progname);
exit(1);
}
- sprintf(command,
- "(gnuserv-edit-files '(tty %s %s %d) '(",
- clean_string(tty), clean_string(term),
- (int)getpid());
+ sz = snprintf(command, sizeof(command),
+ "(gnuserv-edit-files '(tty %s %s %d) '(",
+ clean_string(tty), clean_string(term),
+ (int)getpid());
+ assert(sz>=0 && sz<sizeof(command));
} else { /* !suppress_windows_system */
if (0) ;
#ifdef HAVE_X_WINDOWS
- else if (display)
- sprintf(command,
- "(gnuserv-edit-files '(x %s) '(",
- clean_string(display));
+ else if (display) {
+ int sz = snprintf(command, sizeof(command),
+ "(gnuserv-edit-files '(x %s) '(",
+ clean_string(display));
+ assert(sz>=0 && sz<sizeof(command));
+ }
#endif
#ifdef HAVE_GTK
else if (display)
}
filename_expand(fullpath, argv[i], sizeof(fullpath));
#ifdef INTERNET_DOMAIN_SOCKETS
- path =
- (char *)malloc(strlen(remotepath) +
- strlen(fullpath) + 1);
- sprintf(path, "%s%s", remotepath, fullpath);
+ msz = strlen(remotepath) + strlen(fullpath) + 1;
+ path = (char *)malloc(msz);
+ sz = snprintf(path, msz, "%s%s", remotepath, fullpath);
+ assert(sz>=0 && sz<msz);
#else
path = my_strdup(fullpath);
#endif
- sprintf(command, "(%d . %s)", starting_line,
- clean_string(path));
+ sz = snprintf(command, sizeof(command),
+ "(%d . %s)", starting_line,
+ clean_string(path));
+ assert(sz>=0 && sz<sizeof(command));
send_string(s, command);
free(path);
} /* for */
-
- sprintf(command, ")%s%s",
- (quick
- || (nofiles
- && !suppress_windows_system)) ? " 'quick" : "",
- view ? " 'view" : "");
+
+ sz = snprintf(command, sizeof(command),
+ ")%s%s",
+ (quick
+ || (nofiles
+ && !suppress_windows_system)) ? " 'quick" : "",
+ view ? " 'view" : "");
+ assert(sz>=0 && sz<sizeof(command));
send_string(s, command);
send_string(s, ")");
*/
#include "gnuserv.h"
+#include <assert.h>
char gnuserv_version[] = "gnuserv version" GNUSERV_VERSION;
key_t key; /* messge key */
char buf[GSERV_BUFSZ]; /* pathname for key */
- sprintf(buf, "%s/gsrv%d", tmpdir, (int)geteuid());
+ int sz = snprintf(buf, sizeof(buf),"%s/gsrv%d", tmpdir, (int)geteuid());
+ assert(sz>=0 && sz<sizeof(buf));
creat(buf, 0600);
key = ftok(buf, 1);
int ls; /* socket descriptor */
struct sockaddr_un server; /* unix socket address */
socklen_t bindlen;
+ int sz;
if ((ls = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror(progname);
/* if */
/* Set up address structure for the listen socket. */
#ifdef HIDE_UNIX_SOCKET
- sprintf(server.sun_path, "%s/gsrvdir%d", tmpdir, (int)geteuid());
+ sz = snprintf(server.sun_path, sizeof(server.sun_path),
+ "%s/gsrvdir%d", tmpdir, (int)geteuid());
+ assert(sz>=0 && sz<sizeof(server.sun_path));
if (mkdir(server.sun_path, 0700) < 0) {
/* assume it already exists, and try to set perms */
if (chmod(server.sun_path, 0700) < 0) {
strcat(server.sun_path, "/gsrv");
unlink(server.sun_path); /* remove old file if it exists */
#else /* HIDE_UNIX_SOCKET */
- sprintf(server.sun_path, "%s/gsrv%d", tmpdir, (int)geteuid());
+ sz = snprintf(server.sun_path, sizeof(server.sun_path),
+ "%s/gsrv%d", tmpdir, (int)geteuid());
+ assert(sz>=0 && sz<sizeof(server.sun_path));
unlink(server.sun_path); /* remove old file if it exists */
#endif /* HIDE_UNIX_SOCKET */
key_t key; /* message key */
char buf[GSERV_BUFSZ + 1]; /* buffer for filename */
- sprintf(buf, "%s/gsrv%d", tmpdir, (int)geteuid());
+ int sz = snprintf(buf, sizeof(buf),
+ "%s/gsrv%d", tmpdir, (int)geteuid());
+ assert(sz>=0 && sz<sizeof(buf));
creat(buf, 0600);
if ((key = ftok(buf, 1)) == -1) {
perror(progname);
{
int s; /* connected socket descriptor */
struct sockaddr_un server; /* for unix connections */
+ int sz;
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror(progname);
server.sun_family = AF_UNIX;
#ifdef HIDE_UNIX_SOCKET
- sprintf(server.sun_path, "%s/gsrvdir%d/gsrv", tmpdir, (int)geteuid());
+ sz = snprintf(server.sun_path, sizeof(server.sun_path),
+ "%s/gsrvdir%d/gsrv", tmpdir, (int)geteuid());
#else /* HIDE_UNIX_SOCKET */
- sprintf(server.sun_path, "%s/gsrv%d", tmpdir, (int)geteuid());
+ sz = snprintf(server.sun_path, sizeof(server.sun_path),
+ "%s/gsrv%d", tmpdir, (int)geteuid());
#endif /* HIDE_UNIX_SOCKET */
+ assert(sz>=0 && sz<sizeof(server.sun_path));
if (connect(s, (struct sockaddr *)&server, strlen(server.sun_path) + 2)
< 0) {
perror(progname);
*/
int buf_print(buffer_struct * buffer, const char *s)
{
- register int len;
+ register int len, sz, msz = buffer->size - buffer->index;
len = strlen(s);
- if (buffer->index + len >= buffer->size)
+ if ( len >= msz)
return -1;
- sprintf(&(buffer->buf[buffer->index]), s);
+ sz = snprintf(&(buffer->buf[buffer->index]), msz, "%s", s);
+ assert(sz>=0 && sz<msz);
buffer->index += len;
return len;
}
#include "../src/regex.h"
#endif
+#include <assert.h>
+
extern char *optarg;
extern int optind, opterr;
#endif
if (desc < 0) {
- char *message = (char *)xmalloc(strlen(tempname) + 50);
- sprintf(message,
- "%s--see source file lib-src/movemail.c",
- tempname);
+ int msz = strlen(tempname) + 50;
+ char *message = (char *)xmalloc(msz);
+ int sz = snprintf(message, msz,
+ "%s--see source file lib-src/movemail.c",
+ tempname);
+ assert(sz>=0 && sz < msz);
pfatal_with_name(message);
}
close(desc);
int flags;
{
int sock;
+ int sz;
popserver server;
/* Determine the user name */
"recompile pop.c with larger ERROR_MAX");
return (0);
}
- sprintf (pop_error, "USER %s", username);
+ sz = snprintf (pop_error, sizeof(pop_error), "USER %s", username);
+ assert(sz>=0 && sz<sizeof(pop_error));
if (sendline (server, pop_error) || getok (server)) {
return (0);
"recompile pop.c with larger ERROR_MAX");
return (0);
}
- sprintf (pop_error, "PASS %s", password);
+ sz = snprintf (pop_error, sizeof(pop_error),
+ "PASS %s", password);
+ assert(sz>=0 && sz<sizeof(pop_error));
if (sendline (server, pop_error) || getok (server)) {
return (0);
}
if (message) {
- sprintf (pop_error, "LIST %d", message);
+ sz = snprintf (pop_error, sizeof(pop_error), "LIST %d", message);
+ assert(sz>=0 && sz<sizeof(pop_error));
if (sendline (server, pop_error)) {
free ((char *) *IDs);
free ((char *) *sizes);
int message;
char **response;
{
- sprintf (pop_error, "RETR %d", message);
+ int sz = snprintf (pop_error, sizeof(pop_error), "RETR %d", message);
+ assert(sz>=0 && sz<sizeof(pop_error));
return (pop_multi_first (server, pop_error, response));
}
int message, lines;
char **response;
{
- sprintf (pop_error, "TOP %d %d", message, lines);
+ int sz = snprintf (pop_error, sizeof(pop_error),
+ "TOP %d %d", message, lines);
+ assert(sz>=0 && sz<sizeof(pop_error));
return (pop_multi_first (server, pop_error, response));
}
popserver server;
int message;
{
+ int sz;
+
if (server->in_multi) {
strcpy (pop_error, "In multi-line query in pop_delete");
return (-1);
}
- sprintf (pop_error, "DELE %d", message);
+ sz = snprintf (pop_error, sizeof(pop_error),
+ "DELE %d", message);
+ assert(sz>=0 && sz<sizeof(pop_error));
if (sendline (server, pop_error) || getok (server))
return (-1);
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#include "../src/systime.h"
static struct timeval TV1, TV2;
static int watch_not_started = 1; /* flag */
-static char time_string[30];
+static char time_string[64];
/* Reset the stopwatch to zero. */
static char *get_time(void)
{
+ int sz;
if (watch_not_started)
exit(1); /* call reset_watch first ! */
EMACS_GET_TIME(TV2);
TV2.tv_usec += 1000000;
TV2.tv_sec--;
}
- sprintf(time_string, "%lu.%06lu",
- (unsigned long)TV2.tv_sec - TV1.tv_sec,
- (unsigned long)TV2.tv_usec - TV1.tv_usec);
+ sz = snprintf(time_string, sizeof(time_string), "%lu.%06lu",
+ (unsigned long)TV2.tv_sec - TV1.tv_sec,
+ (unsigned long)TV2.tv_usec - TV1.tv_usec);
+ assert(sz>=0 && sz<sizeof(time_string));
return time_string;
}
} else
#ifdef PATH_DATA
#ifdef vms
- sprintf(file, "%s%s", PATH_DATA, YOW_FILE);
+ int sz = snprintf(file, sizeof(file), "%s%s", PATH_DATA, YOW_FILE);
#else
- sprintf(file, "%s/%s", PATH_DATA, YOW_FILE);
+ int sz = snprintf(file, sizeof(file), "%s/%s", PATH_DATA, YOW_FILE);
#endif
+ assert(sz>=0 && sz<sizeof(file));
#else /* !PATH_DATA */
{
fprintf(stderr,
"%s: the location of the \"%s\" file was not supplied at compile-time.\n\
- You must supply it with the -f command-line option.\n",
+You must supply it with the -f command-line option.\n",
argv[0], YOW_FILE);
exit(1);
}
if (!NILP(XASE_CARTESIAN_INTERIOR_TYPE(obj))) {
print_internal(XASE_CARTESIAN_INTERIOR_TYPE(obj), pcf, unused);
}
- {
- char dim[64];
- snprintf(dim, 63, " of dimension %d, ",
- XASE_CARTESIAN_DIMENSION(obj));
- write_c_string(dim, pcf);
- }
+ write_fmt_str(pcf, " of dimension %d, ",
+ XASE_CARTESIAN_DIMENSION(obj));
_ase_cartesian_prnt(XASE_CARTESIAN(obj), pcf);
write_c_string(">", pcf);
static void
ase_yheap_prnt(Lisp_Object obj, Lisp_Object pcf, int SXE_UNUSED(foo))
{
- char siz[128];
ase_yheap_t h = XASE_YHEAP(obj);
EMOD_ASE_DEBUG_HEAP("h:0x%08lx@0x%08lx shall be printed...\n",
write_c_string("#<ase:heap :dynamic", pcf);
write_c_string(" :size ", pcf);
- snprintf(siz, 127, "%u", (unsigned int)ase_yheap_size(h));
- write_c_string(siz, pcf);
+ write_fmt_str(pcf, "%u", (unsigned int)ase_yheap_size(h));
if (ase_yheap_root(h) != NULL &&
ase_yheap_cell_data(ase_yheap_root(h)) != Qnull_pointer) {
static void
ase_dheap_prnt(Lisp_Object obj, Lisp_Object pcf, int SXE_UNUSED(foo))
{
- char siz[128];
ase_dheap_t h = XASE_DHEAP(obj);
EMOD_ASE_DEBUG_HEAP("d:0x%08lx@0x%08lx shall be printed...\n",
(long unsigned int)h, (long unsigned int)obj);
- write_c_string("#<ase:heap :dense", pcf);
- write_c_string(" :size ", pcf);
- snprintf(siz, 127, "%u", (unsigned int)ase_dheap_size(h));
- write_c_string(siz, pcf);
+ write_fmt_str(pcf, "#<ase:heap :dense :size %u",
+ (unsigned int)ase_dheap_size(h));
if (ase_heap_opts_coloured(h)) {
write_c_string(" :coloured", pcf);
static void
ase_wheap_prnt(Lisp_Object obj, Lisp_Object pcf, int SXE_UNUSED(foo))
{
- char siz[128];
ase_wheap_t h = XASE_WHEAP(obj);
EMOD_ASE_DEBUG_HEAP("w:0x%08lx@0x%08lx shall be printed...\n",
(long unsigned int)h, (long unsigned int)obj);
- write_c_string("#<ase:heap :weak", pcf);
-
- write_c_string(" :size ", pcf);
- snprintf(siz, 127, "%u", (unsigned int)ase_wheap_size(h));
- write_c_string(siz, pcf);
+ write_fmt_string(pcf, "#<ase:heap :weak :size %u",
+ (unsigned int)ase_wheap_size(h));
if (ase_heap_opts_coloured(h)) {
write_c_string(" :coloured", pcf);
write_c_string("#<", pcf);
print_internal(XDYNACAT_TYPE(obj), pcf, unused);
{
- char addr[64];
if (NILP(XASE_METRIC_LDIST(obj))) {
- snprintf(addr, 63, " %p", XASE_METRIC_DIST(obj));
+ write_hex_ptr(XASE_METRIC_DIST(obj),pcf);
} else {
Lisp_Object ldist = XASE_METRIC_LDIST(obj);
if (SYMBOLP(ldist)) {
Lisp_String *name =
symbol_name(XSYMBOL(ldist));
- snprintf(addr, 63, " #'%s", string_data(name));
+ write_fmt_string(pcf, " #'%s", string_data(name));
} else if (SUBRP(ldist)) {
const char *name = subr_name(XSUBR(ldist));
- snprintf(addr, 63, " #'%s", name);
+ write_fmt_string(pcf, " #'%s", name);
} else {
- snprintf(addr, 63, " #'(lambda ...)");
+ write_c_string(" #'(lambda ...)", pcf);
}
}
- write_c_string(addr, pcf);
}
write_c_string(">", pcf);
return;
_ase_permutation_prnt_cyc(unsigned long *p, unsigned long idx, Lisp_Object pcf)
{
unsigned long q;
- char *tmp = alloca_array(char, sane_small);
- write_c_string("(", pcf);
- snprintf(tmp, sane_small, "%ld", idx+1);
- write_c_string(tmp, pcf);
-
- for (q = p[idx]; q != idx; q = p[q]) {
- write_c_string(" ", pcf);
- snprintf(tmp, sane_small, "%ld", q+1);
- write_c_string(tmp, pcf);
- }
+ write_fmt_string(pcf, "(%ld", idx+1);
+ for (q = p[idx]; q != idx; q = p[q])
+ write_fmt_str(pcf, " %ld", q+1);
write_c_string(")", pcf);
}
static inline void
_ase_resc_rng_to_string(char *buf, int len, ase_resc_rng_t a)
{
- if (ase_resc_rng_smallp(a))
- snprintf(buf, len, "%ld", a->small_ring);
- else
+ if (ase_resc_rng_smallp(a)) {
+ int sz = snprintf(buf, len, "%ld", a->small_ring);
+ assert(sz >= 0 && sz < len);
+ } else
resc_rng_to_string(buf, len, ase_resc_rng_ring(a));
return;
}
static inline void
_ase_resc_elm_to_string(char *buf, int len, ase_resc_elm_t a)
{
- if (ase_resc_elm_smallp(a))
- snprintf(buf, len, "%ld", a->small_data);
- else
+ if (ase_resc_elm_smallp(a)) {
+ int sz = snprintf(buf, len, "%ld", a->small_data);
+ assert(sz>=0 && sz < len);
+ } else
resc_elm_to_string(buf, len, ase_resc_elm_data(a));
return;
}
#define resc_rng_to_string(_p, _n, _r) mpz_get_str(_p, 10, _r)
#define resc_elm_to_string(_p, _n, _e) mpz_get_str(_p, 10, _e)
#else
-#define resc_rng_to_string(_p, _n, _r) snprintf(_p, _n, "%ld", _r)
-#define resc_elm_to_string(_p, _n, _e) snprintf(_p, _n, "%ld", _e)
+#define resc_rng_to_string(_p, _n, _r) do { int sz = snprintf(_p, _n, "%ld", _r); assert(sz>=0 && sz<_n); } while(0)
+#define resc_elm_to_string(_p, _n, _e) do { int sz = snprintf(_p, _n, "%ld", _e); assert(sz>=0 && sz<_n); } while(0)
#endif
{
Lisp_Object obj;
va_list args;
- char *buf = alloca_array(char, strlen(error_message) + 128);
+ int maxsz = strlen(error_message) + 128;
+ char *buf = alloca_array(char, maxsz);
- sprintf(buf, "%s", error_message);
+ int sz=snprintf(buf, maxsz, "%s", error_message);
+ assert(sz>=0 && sz<maxsz);
va_start(args, error_message);
obj = emacs_doprnt_string_va((const Bufbyte *)GETTEXT(buf), Qnil, -1,
args);
int docp = f->flags.documentationp;
int intp = f->flags.interactivep;
struct gcpro gcpro1, gcpro2;
- char buf[100];
GCPRO2(obj, printcharfun);
write_c_string(print_readably ? "#[" : "#<compiled-function ",
NGCPRO1(instructions);
if (STRINGP(instructions) && !print_readably) {
/* We don't usually want to see that junk in the bytecode. */
- sprintf(buf, "\"...(%ld)\"",
- (long)XSTRING_CHAR_LENGTH(instructions));
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, "\"...(%ld)\"",
+ (long)XSTRING_CHAR_LENGTH(instructions));
} else
print_internal(instructions, printcharfun, escapeflag);
NUNGCPRO;
escapeflag);
/* COMPILED_STACK_DEPTH = 3 */
- sprintf(buf, " %d", compiled_function_stack_depth(f));
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, " %d", compiled_function_stack_depth(f));
/* COMPILED_DOC_STRING = 4 */
if (docp || intp) {
Lisp_Object jen = cte->level2[i - 32];
if (!CHAR_TABLE_ENTRYP(jen)) {
- char buf[100];
-
write_c_string(" [", printcharfun);
print_internal(XCHARSET_NAME(charset), printcharfun, 0);
- sprintf(buf, " %d] ", i);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, " %d] ", i);
print_internal(jen, printcharfun, 0);
} else
print_chartab_charset_row(charset, i,
print_char_table(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
Lisp_Char_Table *ct = XCHAR_TABLE(obj);
- char buf[200];
Lisp_Object tmp_sym = char_table_type_to_symbol(ct->type);
- snprintf(buf, countof(buf)-1, "#s(char-table type %s data (",
- string_data(symbol_name(XSYMBOL(tmp_sym))));
- write_c_string(buf, printcharfun);
+ write_fmt_string(printcharfun, "#s(char-table type %s data (",
+ string_data(symbol_name(XSYMBOL(tmp_sym))));
/* Now write out the ASCII/Control-1 stuff. */
{
static void
print_database(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
- char buf[85];
Lisp_Database *db = XDATABASE(obj);
Lisp_Object tmp1, tmp2;
tmp1 = db->funcs->get_type(db);
tmp2 = db->funcs->get_subtype(db);
- snprintf(buf, sizeof(buf), "\" (%s/%s/%s) 0x%x>",
- (char *)string_data(XSYMBOL(tmp1)->name),
- (char *)string_data(XSYMBOL(tmp2)->name),
- (!DATABASE_LIVE_P(db) ? "closed" :
- (db->access_ & O_WRONLY) ? "writeonly" :
- (db->access_ & O_RDWR) ? "readwrite" : "readonly"),
- db->header.uid);
- write_c_string(buf, printcharfun);
+ write_fmt_string(printcharfun,
+ "\" (%s/%s/%s) 0x%x>",
+ (char *)string_data(XSYMBOL(tmp1)->name),
+ (char *)string_data(XSYMBOL(tmp2)->name),
+ (!DATABASE_LIVE_P(db) ? "closed" :
+ (db->access_ & O_WRONLY) ? "writeonly" :
+ (db->access_ & O_RDWR) ? "readwrite" : "readonly"),
+ db->header.uid);
}
static void finalize_database(void *header, int for_disksave)
print_internal(ldap->host, printcharfun, 1);
if (!ldap->ld)
write_c_string("(dead) ", printcharfun);
- sprintf(buf, " 0x%lx>", (long)ldap);
- write_c_string(buf, printcharfun);
+ write_fmt_string(printcharfun, " 0x%lx>", (long)ldap);
}
static Lisp_LDAP *allocate_ldap(void)
static void
print_pgconn(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
- char buf[256];
PGconn *P;
ConnStatusType cst;
char *host = "", *db = "", *user = "", *port = "";
if (P == NULL) {
/* this may happen since we allow PQfinish() to be called */
- strncpy(buf, "#<PGconn DEAD>", countof(buf));
+ write_c_string("#<PGconn DEAD>", printcharfun);
} else if ((cst = PQstatus(P)) == CONNECTION_OK) {
if (!(host = PQhost(P)))
host = "";
if (!(user = PQuser(P))) {
user = "";
}
- snprintf(buf, sizeof(buf), "#<PGconn %s:%s %s/%s>", /* evil! */
- !strlen(host) ? "localhost" : host, port, user, db);
+ write_fmt_string(printcharfun, "#<PGconn %s:%s %s/%s>",
+ (!strlen(host) ?
+ "localhost" : host) /* evil! */,
+ port, user, db);
} else if (cst == CONNECTION_BAD) {
- strncpy(buf, "#<PGconn BAD>", countof(buf));
+ write_c_string("#<PGconn BAD>", printcharfun);
} else {
- strncpy(buf, "#<PGconn connecting>", countof(buf));
+ write_c_string("#<PGconn connecting>", printcharfun);
}
- write_c_string(buf, printcharfun);
return;
}
static void
print_pgresult(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
- char buf[1024];
PGresult *res;
res = (XPGRESULT(obj))->pgresult;
switch (PQresultStatus(res)) {
case PGRES_TUPLES_OK:
/* Add number of tuples of result to output */
- snprintf(buf, countof(buf), RESULT_TUPLES_FMT,
- PQresStatus(PQresultStatus(res)),
- PQntuples(res), PQcmdStatus(res));
+ write_fmt_string(printcharfun, RESULT_TUPLES_FMT,
+ PQresStatus(PQresultStatus(res)),
+ PQntuples(res), PQcmdStatus(res));
break;
case PGRES_COMMAND_OK:
/* Add number of tuples affected by output-less
command */
if (!strlen(PQcmdTuples(res)))
goto notuples;
- snprintf(buf, countof(buf), RESULT_CMD_TUPLES_FMT,
- PQresStatus(PQresultStatus(res)),
- PQcmdTuples(res), PQcmdStatus(res));
+ write_fmt_string(printcharfun, RESULT_CMD_TUPLES_FMT,
+ PQresStatus(PQresultStatus(res)),
+ PQcmdTuples(res), PQcmdStatus(res));
break;
default:
notuples:
/* No counts to print */
- snprintf(buf, countof(buf), RESULT_DEFAULT_FMT,
- PQresStatus(PQresultStatus(res)),
- PQcmdStatus(res));
+ write_fmt_string(printcharfun, RESULT_DEFAULT_FMT,
+ PQresStatus(PQresultStatus(res)),
+ PQcmdStatus(res));
break;
}
} else {
- strncpy(buf, "#<PGresult DEAD>", countof(buf));
+ write_c_string("#<PGresult DEAD>", printcharfun);
}
-
- write_c_string(buf, printcharfun);
return;
}
# define SIGNAL_ERROR signal_error
# define FFIBYTE Bufbyte
# define WRITE_C_STRING(x,y) write_c_string((x),(y))
+# define WRITE_FMT_STRING(x,y,...) write_fmt_string((x),(y),__VA_ARGS__)
# define LRECORD_DESCRIPTION lrecord_description
#else
# define SIGNAL_ERROR Fsignal
# define FFIBYTE Ibyte
# define WRITE_C_STRING(x,y) write_c_string((y),(x))
+# define WRITE_FMT_STRING(x,y,...) \
+ do { \
+ char wcsb[128]; \
+ int wcss = snprintf(wcsb, sizeof(wcsb), \
+ (y),__VA_ARGS__); \
+ write_c_string((y),wcsb); \
+ } while(0)
# define LRECORD_DESCRIPTION memory_description
#endif /* SXEMACS */
{
/* This function can GC */
Lisp_EffiObject *ffio = XEFFIO(obj);
- char buf[256];
-
escapeflag = escapeflag; /* shutup compiler */
if (print_readably) {
#ifdef SXEMACS
print_internal(ffio->type, printcharfun, 1);
WRITE_C_STRING(" ", printcharfun);
}
- snprintf(buf, 255, "size=%ld fotype=%d foptr=%p>",
- (long)XINT(ffio->size), ffio->fotype, ffio->fop.generic);
- WRITE_C_STRING(buf, printcharfun);
+ WRITE_FMT_STRING(printcharfun,"size=%ld fotype=%d foptr=%p>",
+ (long)XINT(ffio->size), ffio->fotype, ffio->fop.generic);
}
static const struct LRECORD_DESCRIPTION ffiobject_description[] = {
print_ffi_job(worker_job_t job, Lisp_Object pcf)
{
ffi_job_t ffij = ffi_job(job);
- char *str = alloca(64);
SXE_MUTEX_LOCK(&ffij->mtx);
- WRITE_C_STRING(" carrying ", pcf);
- snprintf(str, 63, " #<ffi-job 0x%lx>", (long unsigned int)ffij);
- WRITE_C_STRING(str, pcf);
+ WRITE_FMT_STRING(pcf, " carrying #<ffi-job 0x%lx>",
+ (long unsigned int)ffij);
SXE_MUTEX_UNLOCK(&ffij->mtx);
return;
}
const char *pstack = "/usr/proc/bin/pstack";
if (access(pstack, X_OK) == 0) {
char buf[100];
+ int sz = snprintf(buf, sizeof(buf), "%s %d >&2", pstack,
+ (int)getpid());
stderr_out("\nC backtrace follows:\n"
"(A real debugger may provide better information)\n\n");
- sprintf(buf, "%s %d >&2", pstack,
- (int)getpid());
- system(buf);
+ if ( sz >= 0 && sz < sizeof(buf)) {
+ sz = system(buf);
+ if ( sz != 0 )
+ stderr_out("\nStacktrace utility execution error code: %d\n", sz);
+ } else {
+ stderr_out("\nCould not build command line for stacktrace utility.\n");
+ }
}
}
# endif
print_event_1("#<magic-event ", obj, printcharfun);
break;
case pointer_motion_event: {
- char buf[64];
Lisp_Object Vx, Vy;
Vx = Fevent_x_pixel(obj);
assert(INTP(Vx));
EXTENT anc = extent_ancestor(ext);
Lisp_Object tail;
char buf[100], *bp = buf;
+ int sz;
/* Retrieve the ancestor and use it, for faster retrieval of properties */
*bp++ = '*';
*bp++ = (extent_start_open_p(anc) ? '(' : '[');
if (extent_detached_p(ext))
- strcpy(bp, "detached");
- else
- sprintf(bp, "%ld, %ld",
- XINT(Fextent_start_position(obj)),
- XINT(Fextent_end_position(obj)));
+ strncpy(bp, "detached", sizeof(buf)-1);
+ else {
+ sz=snprintf(bp, sizeof(buf)-2, "%ld, %ld",
+ XINT(Fextent_start_position(obj)),
+ XINT(Fextent_end_position(obj)));
+ assert(sz>=0 && sz<(sizeof(buf)-2));
+ }
bp += strlen(bp);
*bp++ = (extent_end_open_p(anc) ? ')' : ']');
if (!NILP(extent_end_glyph(anc)))
write_c_string(" ", printcharfun);
}
- sprintf(buf, "0x%lx", (long)ext);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, "0x%lx", (long)ext);
}
static void
if (!EXTENT_LIVE_P(XEXTENT(obj))) {
write_c_string("#<destroyed extent", printcharfun);
} else {
- /* C99ified */
- size_t bufsz = strlen(title) + strlen(name) +
- strlen(posttitle) + 1;
- char buf[bufsz];
-
write_c_string("#<extent ", printcharfun);
print_extent_1(obj, printcharfun, escapeflag);
write_c_string(extent_detached_p(XEXTENT(obj))
? " from " : " in ", printcharfun);
- snprintf(buf, bufsz, "%s%s%s", title, name, posttitle);
- write_c_string(buf, printcharfun);
+ write_fmt_string(printcharfun, "%s%s%s", title, name, posttitle);
}
} else {
if (print_readably)
#define PRIVATE_EXTERNAL_LIST_LOOP_6(elt, list, len, hare, \
tortoise, suspicion_length) \
- for (tortoise = hare = list, len = 0; \
- \
- (CONSP (hare) ? ((void)(elt = XCAR (hare)), 1) : \
- (NILP (hare) ? 0 : \
- ((void)signal_malformed_list_error (list), 0))); \
+ for (tortoise = hare = list, len = 0; \
+ \
+ (CONSP (hare) ? ((elt = XCAR (hare)), 1) : \
+ (NILP (hare) ? 0 : \
+ (signal_malformed_list_error (list), 0))); \
\
- hare = XCDR (hare), \
- (void) \
- ((++len > suspicion_length) \
- && \
- ((((len & 1) != 0) && (tortoise = XCDR (tortoise), 0)), \
- (EQ (hare, tortoise) && (signal_circular_list_error (list), 0)))))
+ (hare = XCDR (hare)), \
+ (void)((++len > suspicion_length) && \
+ ((void)(((len & 1) != 0)&& \
+ ((tortoise = XCDR (tortoise)), 0)), \
+ (EQ (hare, tortoise) && \
+ (signal_circular_list_error (list), 0)))))
/* GET_LIST_LENGTH and GET_EXTERNAL_LIST_LENGTH:
/* Explain how pty filenames work. */
#define PTY_ITERATION for (i = 47; i >= 0; i--)
-#define PTY_NAME_SPRINTF sprintf (ptyname, "/dev/pty%03x", i);
-#define PTY_TTY_NAME_SPRINTF sprintf (ptyname, "/dev/ptm%03x", i);
+#define PTY_NAME_SPRINTF snprintf (ptyname, sizeof(ptyname), "/dev/pty%03x", i);
+#define PTY_TTY_NAME_SPRINTF snprintf (ptyname, sizeof(ptyname), "/dev/ptm%03x", i);
/* We can't do interrupt-driven input, so don't let user try. */
}
if (avfc->year) {
char year[12];
+ int sz = snprintf(year, sizeof(year), "%d", avfc->year);
+ assert(sz>=0 && sz<sizeof(year));
strncat(out, " :year ", chars_left);
chars_left -= 7;
- snprintf(year, 12, "%d", avfc->year);
strncat(out, year, chars_left);
}
write_c_string("#<audio ", printcharfun);
if (mtap->name || mtap->codec_name) {
- char *buf = alloca(64);
if (mtap->name && mtap->codec_name)
- snprintf(buf, 63, "%s (%s)",
- mtap->name, mtap->codec_name);
+ write_fmt_str(printcharfun, "%s (%s)",
+ mtap->name, mtap->codec_name);
else if (mtap->name)
- snprintf(buf, 63, "%s [???]", mtap->name);
+ write_fmt_str(printcharfun, "%s [???]", mtap->name);
else if (mtap->codec_name)
- snprintf(buf, 63, "??? (%s)", mtap->codec_name);
-
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, "??? (%s)", mtap->codec_name);
} else
write_c_string("???", printcharfun);
break;
}
- if (mtap->samplerate) {
- char *buf;
- buf = alloca(48);
- snprintf(buf, 47, ", %d Hz, %d Bit",
- mtap->samplerate,
- mtap->samplewidth);
- write_c_string(buf, printcharfun);
- }
+ if (mtap->samplerate)
+ write_fmt_str(printcharfun, ", %d Hz, %d Bit",
+ mtap->samplerate,
+ mtap->samplewidth);
- if (mtap->bitrate) {
- char *buf;
- buf = alloca(24);
- snprintf(buf, 23, ", %d kb/s", mtap->bitrate/1000);
- write_c_string(buf, printcharfun);
- }
+ if (mtap->bitrate)
+ write_fmt_str(printcharfun, ", %d kb/s", mtap->bitrate/1000);
write_c_string(">", printcharfun);
}
write_c_string("#<video ", printcharfun);
if (mtvp->name || mtvp->codec_name) {
- char *buf = alloca(64);
if (mtvp->name && mtvp->codec_name)
- snprintf(buf, 63, "%s (%s)",
- mtvp->name, mtvp->codec_name);
+ write_fmt_str(printcharfun, "%s (%s)",
+ mtvp->name, mtvp->codec_name);
else if (mtvp->name)
- snprintf(buf, 63, "%s [???]", mtvp->name);
+ write_fmt_str(printcharfun, "%s [???]", mtvp->name);
else if (mtvp->codec_name)
- snprintf(buf, 63, "??? (%s)", mtvp->codec_name);
-
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, "??? (%s)", mtvp->codec_name);
} else
write_c_string("???", printcharfun);
- if (mtvp->bitrate) {
- char *buf = alloca(24);
- snprintf(buf, 23, ", %d kb/s", mtvp->bitrate);
- write_c_string(buf, printcharfun);
- }
+ if (mtvp->bitrate)
+ write_fmt_str(printcharfun, ", %d kb/s", mtvp->bitrate);
if (mtvp->width && mtvp->height) {
- char *buf = alloca(48);
if (mtvp->aspect_num > 1 && mtvp->aspect_den >= 1)
- snprintf(buf, 47, ", %dx%d (%d/%d)",
- mtvp->width, mtvp->height,
- mtvp->aspect_num, mtvp->aspect_den);
+ write_fmt_str(printcharfun, ", %dx%d (%d/%d)",
+ mtvp->width, mtvp->height,
+ mtvp->aspect_num, mtvp->aspect_den);
else
- snprintf(buf, 47, ", %dx%d (%.2f/1)",
- mtvp->width, mtvp->height,
- (double)mtvp->width/(double)mtvp->height);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, ", %dx%d (%.2f/1)",
+ mtvp->width, mtvp->height,
+ (double)mtvp->width/(double)mtvp->height);
}
write_c_string(">", printcharfun);
}
sound_alsa_print(Lisp_Object device, Lisp_Object pcfun, int ef)
{
sound_alsa_data_t *sad = NULL;
- char *temp = alloca(48);
-
sad = get_audio_device_data(device);
/* cannot use incomplete or corrupt audio devices */
if (XAUDIO_DEVICE_DRIVER(device) != MYSELF || sad == NULL) {
print_internal(sad->device, pcfun, ef);
if (sad->keep_open) {
- write_c_string(" :keep-open t", pcfun);
- snprintf(temp, 47, " :handle 0x%lx",
- (long unsigned int)sad->handle);
- write_c_string(temp, pcfun);
+ write_fmt_string(pcfun, " :keep-open t :handle 0x%lx",
+ (long unsigned int)sad->handle);
} else
write_c_string(" :keep-open nil", pcfun);
- snprintf(temp, 47, " :params 0x%lx", (long unsigned int)sad->hwparams);
- write_c_string(temp, pcfun);
-
+ write_fmt_str(pcfun, " :params 0x%lx", (long unsigned int)sad->hwparams);
return;
}
void player_error_internal(Audio * audio, char *text, long errorCode)
{
char errorbuff[132], buf[256];
+ int sz;
AGetErrorText(audio, errorCode, errorbuff, 131);
- sprintf(buf, "%s: %s\n", text, errorbuff);
+ sz = sprintf(buf, sizeof(buf), "%s: %s\n", text, errorbuff);
+ assert(sz>=0 && sz<sizeof(buf));
error(buf);
}
/* create out output ports */
for (i = 0; i < sjsd->num_ports; i++) {
char pname[30];
- snprintf(pname, 30, "SXEmacs out_%d", i);
+ int sz = snprintf(pname, sizeof(pname), "SXEmacs out_%d", i);
+ assert(sz>=0 && sz<sizeof(pname));
sjsd->ports[i] = jack_port_register(
client, pname,
JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
sound_pulse_print(Lisp_Object device, Lisp_Object pcfun, int ef)
{
sound_pulse_data_t spd = NULL;
- char *temp = alloca(256);
pa_context_state_t st;
spd = get_audio_device_data(device);
write_c_string(" :api ", pcfun);
if (spd->ml_threaded_p) {
- write_c_string("#threaded", pcfun);
- snprintf(temp, 255, " :mainloop 0x%lx",
- (long unsigned int)spd->tml);
+ write_fmt_str(pcfun, "#threaded :mainloop 0x%lx",
+ (long unsigned int)spd->tml);
} else {
- write_c_string("#non-threaded", pcfun);
- snprintf(temp, 255, " :mainloop 0x%lx",
- (long unsigned int)spd->ml);
+ write_fmt_str(pcfun, "#non-threaded :mainloop 0x%lx",
+ (long unsigned int)spd->ml);
}
-
- write_c_string(temp, pcfun);
-
return;
}
char buf1[100], buf2[100], buf3[250];
audio_enc_to_str(&file_hdr, buf1);
audio_enc_to_str(&new_hdr, buf2);
- sprintf(buf3, "wanted %s, got %s", buf1, buf2);
+ (void)snprintf(buf3, sizeof(buf3), "wanted %s, got %s", buf1, buf2);
warn(buf3);
return 1;
}
if (volume < 0 || volume > 100) {
char buf[255];
- sprintf(buf, "volume must be between 0 and 100 (not %d)",
- volume);
+ int sz = sprintf(buf, sizeof(buf), "volume must be between 0 and 100 (not %d)",
+ volume);
+ assert(sz>=0 && sz<sizeof(buf));
warn(buf);
return 1;
}
}
if (wrtn != rrtn) {
char warn_buf[255];
- sprintf(warn_buf, "play: rrtn = %d, wrtn = %d", rrtn,
- wrtn);
+ int sz = sprintf(warn_buf, sizeof(warn_buf), "play: rrtn = %d, wrtn = %d", rrtn,
+ wrtn);
+ assert(warn_buf>=0 && warn_buf<sizeof(warn_buf));
warn(warn_buf);
goto END_OF_PLAY;
}
}
if (wrtn != length) {
char buf[255];
- sprintf(buf, "play: rrtn = %d, wrtn = %d", length, wrtn);
+ int sz = snprintf(buf, sizeof(buf),
+ "play: rrtn = %d, wrtn = %d", length, wrtn);
+ assert(sz>=0 && sz < sizeof(buf));
warn(buf);
goto END_OF_PLAY;
}
char buf1[100], buf2[100], buf3[250];
audio_enc_to_str(&file_hdr, buf1);
audio_enc_to_str(&new_hdr, buf2);
- sprintf(buf3, "wanted %s, got %s", buf1, buf2);
+ (void)snprintf(buf3, sizeof(buf3), "wanted %s, got %s", buf1, buf2);
warn(buf3);
return 0;
}
#if 0
if (volume < 0 || volume > 100) {
char buf[255];
- sprintf(buf, "volume must be between 0 and 100 (not %d)",
- volume);
+ int sz = snprintf(buf, sizeof(buf),
+ "volume must be between 0 and 100 (not %d)",
+ volume);
+ assert(sz>=0 && sz<sizeof(buf));
warn(buf);
return 0;
}
#endif /* HAVE_FPFLOAT */
/* Print NUMBER to BUFFER.
- This is equivalent to sprintf (buffer, "%ld", number), only much faster.
+ This is equivalent to snprintf (buffer, maxlen, "%ld", number), only much faster.
BUFFER should accept 24 bytes. This should suffice for the longest
numbers on 64-bit machines, including the `-' sign and the trailing
/* If name is already in use, modify it until it is unused. */
name1 = name;
for (i = 1;; i++) {
- char suffix[10];
+ char suffix[24];
+ int sz;
Lisp_Object tem = Fget_process(name1);
if (NILP(tem))
break;
- sprintf(suffix, "<%d>", i);
+ sz = snprintf(suffix, sizeof(suffix), "<%d>", i);
+ assert(sz>=0 && sz<sizeof(suffix));
name1 = concat2(name, build_string(suffix));
}
name = name1;
if (!separator_string_p(XSTRING_DATA(name))) {
char *label_buffer = NULL;
char *temp_label = NULL;
+ int sz, maxsz;
if (STRINGP(suffix) && XSTRING_LENGTH(suffix)) {
- label_buffer =
- alloca(XSTRING_LENGTH(name) + 15 +
- XSTRING_LENGTH(suffix));
- sprintf(label_buffer, "%s %s ",
- XSTRING_DATA(name),
- XSTRING_DATA(suffix));
+ maxsz = XSTRING_LENGTH(name) + 15 +
+ XSTRING_LENGTH(suffix);
+ label_buffer = alloca(maxsz);
+ sz = snprintf(label_buffer, maxsz, "%s %s ",
+ XSTRING_DATA(name),
+ XSTRING_DATA(suffix));
+ assert(sz>=0 && sz<maxsz);
} else {
- label_buffer =
- alloca(XSTRING_LENGTH(name) + 15);
- sprintf(label_buffer, "%s ",
- XSTRING_DATA(name));
+ maxsz = XSTRING_LENGTH(name) + 15;
+ label_buffer = alloca(maxsz);
+ sz = sprintf(label_buffer, maxsz, "%s ",
+ XSTRING_DATA(name));
+ assert(sz>=0 && sz<maxsz);
}
temp_label = convert_underscores(label_buffer);