const char *name =
lrecord_implementations_table[i]->name;
int len = strlen(name);
+ int sz;
+
/* save this for the FSFmacs-compatible part of the
summary */
if (i == lrecord_type_vector)
lcrecord_stats[i].bytes_in_use +
lcrecord_stats[i].bytes_freed;
- snprintf(buf, sizeof(buf), "%s-storage", name);
+ sz = snprintf(buf, sizeof(buf), "%s-storage", name);
+ assert(sz >=0 && sz < sizeof(buf));
pl = gc_plist_hack(buf, lcrecord_stats[i].bytes_in_use,
pl);
/* Okay, simple pluralization check for
`symbol-value-varalias' */
if (name[len - 1] == 's')
- snprintf(buf, sizeof(buf), "%ses-freed", name);
+ sz = snprintf(buf, sizeof(buf), "%ses-freed", name);
else
- snprintf(buf, sizeof(buf), "%ss-freed", name);
+ sz = snprintf(buf, sizeof(buf), "%ss-freed", name);
+ assert(sz >=0 && sz < sizeof(buf));
if (lcrecord_stats[i].instances_freed != 0)
pl = gc_plist_hack(buf,
lcrecord_stats[i].
instances_freed, pl);
if (name[len - 1] == 's')
- snprintf(buf, sizeof(buf), "%ses-on-free-list", name);
+ sz = snprintf(buf, sizeof(buf), "%ses-on-free-list", name);
else
- snprintf(buf, sizeof(buf), "%ss-on-free-list", name);
+ sz = snprintf(buf, sizeof(buf), "%ss-on-free-list", name);
+ assert(sz >=0 && sz < sizeof(buf));
if (lcrecord_stats[i].instances_on_free_list != 0)
pl = gc_plist_hack(buf,
lcrecord_stats[i].
instances_on_free_list, pl);
if (name[len - 1] == 's')
- snprintf(buf, sizeof(buf), "%ses-used", name);
+ sz = snprintf(buf, sizeof(buf), "%ses-used", name);
else
- snprintf(buf, sizeof(buf), "%ss-used", name);
+ sz = snprintf(buf, sizeof(buf), "%ss-used", name);
+ assert(sz >=0 && sz < sizeof(buf));
pl = gc_plist_hack(buf,
lcrecord_stats[i].instances_in_use,
pl);
print_case_table(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
Lisp_Case_Table *ct = XCASE_TABLE(obj);
- char buf[200];
if (print_readably)
error("printing unreadable object #<case-table 0x%x",
ct->header.uid);
- write_c_string("#<case-table ", printcharfun);
- sprintf(buf, "0x%x>", ct->header.uid);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, "#<case-table 0x%x>", ct->header.uid);
}
static const struct lrecord_description case_table_description[] = {
if (FLOATP(number)) {
char pigbuf[350]; /* see comments in float_to_string */
- float_to_string(pigbuf, XFLOAT_DATA(number));
+ float_to_string(pigbuf, XFLOAT_DATA(number), sizeof(pigbuf));
return build_string(pigbuf);
}
#endif /* HAVE_FPFLOAT */
return retval;
}
- long_to_string(buffer, XINT(number));
+ long_to_string(buffer, XINT(number), sizeof(buffer));
return build_string(buffer);
}
} else /* ch == 'b' */ {
text_len = __ulong_to_bit_string(text, Z);
}
-
+ assert(text_len >= 0 && text_len < alloc_sz);
/* postprocess, move stuff around, insert naughts, etc. */
text_len = __postproc2(s, text, text_len, alloc_sz);
char *p = constructed_spec;
int length, alloca_sz = max_float_print_size;
int min = spec->minwidth, prec = spec->precision;
+ int max_spec = sizeof(constructed_spec);
#if 0
/* absolute non-sense :O ...
*p++ = '0';
if (spec->minwidth >= 0) {
- long_to_string(p, spec->minwidth);
+ long_to_string(p, spec->minwidth, max_spec);
+ max_spec -= strlen(p);
p += strlen (p);
}
if (spec->precision >= 0) {
*p++ = '.';
- long_to_string(p, spec->precision);
+ --max_spec;
+ long_to_string(p, spec->precision, max_spec);
+ max_spec -= strlen(p);
p += strlen (p);
}
#if fpfloat_long_double_p
*p++ = 'L';
+ --max_spec;
#endif
*p++ = ch;
+ --max_spec;
*p++ = '\0';
+ --max_spec;
+ assert(max_spec >= 0);
if (NILP(obj))
length = snprintf(text_to_print, alloca_sz,
constructed_spec, arg.d);
length = snprintf(text_to_print, alloca_sz,
constructed_spec, XFLOAT_DATA(obj));
- if (length > alloca_sz)
+ if (length > alloca_sz) {
+ /* should we really silently truncate?! */
length = alloca_sz;
-
+ }
doprnt_1(stream, (Bufbyte *)text_to_print, length, 0, -1, 0, 0);
return;
static int pdump_file_try(char *exe_path, size_t size)
{
char *w = exe_path + strlen(exe_path);
+ int sz;
size -= strlen(exe_path);
do {
#ifdef EMACS_PATCH_LEVEL
- snprintf(w, size, "-%d.%d.%d-%08x.dmp",
+ sz = snprintf(w, size, "-%d.%d.%d-%08x.dmp",
EMACS_MAJOR_VERSION, EMACS_MINOR_VERSION,
EMACS_PATCH_LEVEL, dump_id);
- if (pdump_file_get(exe_path)) {
+ if (sz >=0 && sz < size && pdump_file_get(exe_path)) {
if (pdump_load_check()) {
return 1;
}
}
#endif /* EMACS_PATCH_LEVEL */
#ifdef EMACS_BETA_VERSION
- snprintf(w, size, "-%d.%d.%d-%08x.dmp",
+ sz = snprintf(w, size, "-%d.%d.%d-%08x.dmp",
EMACS_MAJOR_VERSION, EMACS_MINOR_VERSION,
EMACS_BETA_VERSION, dump_id);
- if (pdump_file_get(exe_path)) {
+ if (sz >=0 && sz < size && pdump_file_get(exe_path)) {
if (pdump_load_check()) {
return 1;
}
}
#endif /* EMACS_BETA_VERSION */
- snprintf(w, size, "-%08x.dmp", dump_id);
- if (pdump_file_get(exe_path)) {
+ sz = snprintf(w, size, "-%08x.dmp", dump_id);
+ if (sz >=0 && sz < size && pdump_file_get(exe_path)) {
if (pdump_load_check()) {
return 1;
}
pdump_free();
}
- snprintf(w, size, ".dmp");
- if (pdump_file_get(exe_path)) {
+ sz = snprintf(w, size, ".dmp");
+ if (sz >=0 && sz < size && pdump_file_get(exe_path)) {
if (pdump_load_check()) {
return 1;
}
if (!*p) {
/* Oh well, let's have some kind of default */
- snprintf(exe_path, sizeof(exe_path),
- "./%s", name);
+ int sz = snprintf(exe_path, sizeof(exe_path),
+ "./%s", name);
+ assert(sz >= 0 && sz < sizeof(exe_path));
break;
}
path = p + 1;
tzstring = (char *)XSTRING_DATA(zone);
} else if (INTP(zone)) {
int abszone = abs(XINT(zone));
- snprintf(tzbuf, countof(tzbuf) - 1, "XXX%s%d:%02d:%02d",
- "-" + (XINT(zone) < 0), abszone / (60 * 60),
- (abszone / 60) % 60, abszone % 60);
+ int sz = snprintf(tzbuf, sizeof(tzbuf), "XXX%s%d:%02d:%02d",
+ "-" + (XINT(zone) < 0), abszone / (60 * 60),
+ (abszone / 60) % 60, abszone % 60);
+ assert(sz >= 0 && sz < sizeof(tzbuf));
tzstring = tzbuf;
} else {
error("Invalid time zone specification");
tzstring = (char *)XSTRING_DATA(zone);
else if (INTP(zone)) {
int abszone = abs(XINT(zone));
- sprintf(tzbuf, "XXX%s%d:%02d:%02d",
- "-" + (XINT(zone) < 0), abszone / (60 * 60),
- (abszone / 60) % 60, abszone % 60);
+ int sz = snprintf(tzbuf, sizeof(tzbuf), "XXX%s%d:%02d:%02d",
+ "-" + (XINT(zone) < 0), abszone / (60 * 60),
+ (abszone / 60) % 60, abszone % 60);
+ assert(sz>=0 && sz < sizeof(tzbuf));
tzstring = tzbuf;
} else
error("Invalid time zone specification");
/* No local time zone name is available; use "+-NNNN"
instead. */
int am = (offset < 0 ? -offset : offset) / 60;
- sprintf(buf, "%c%02d%02d", (offset < 0 ? '-' : '+'),
- am / 60, am % 60);
+ int sz = snprintf(buf, sizeof(buf), "%c%02d%02d",
+ (offset < 0 ? '-' : '+'),
+ am / 60, am % 60);
+ assert(sz>=0 && sz < sizeof(buf));
s = buf;
}
return list2(make_int(offset), build_string(s));
print_hash_table(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
hash_table_t ht = XHASH_TABLE(obj);
- char buf[128];
write_c_string(print_readably ? "#s(hash-table" : "#<hash-table",
printcharfun);
if (ht->count || !print_readably) {
if (print_readably)
- sprintf(buf, " size %lu", (unsigned long)ht->count);
+ write_fmt_str(printcharfun, " size %lu", (unsigned long)ht->count);
else
- sprintf(buf, " size %lu/%lu",
- (unsigned long)ht->count,
- (unsigned long)ht->size);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, " size %lu/%lu",
+ (unsigned long)ht->count,
+ (unsigned long)ht->size);
}
if (ht->weakness != HASH_TABLE_NON_WEAK) {
- sprintf(buf, " weakness %s",
- (ht->weakness == HASH_TABLE_WEAK ? "key-and-value" :
- ht->weakness == HASH_TABLE_KEY_WEAK ? "key" :
- ht->weakness == HASH_TABLE_VALUE_WEAK ? "value" :
- ht->weakness ==
- HASH_TABLE_KEY_VALUE_WEAK ? "key-or-value" :
- "you-d-better-not-see-this"));
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, " weakness %s",
+ (ht->weakness == HASH_TABLE_WEAK ? "key-and-value" :
+ ht->weakness == HASH_TABLE_KEY_WEAK ? "key" :
+ ht->weakness == HASH_TABLE_VALUE_WEAK ? "value" :
+ ht->weakness ==
+ HASH_TABLE_KEY_VALUE_WEAK ? "key-or-value" :
+ "you-d-better-not-see-this"));
}
if (ht->count)
if (print_readably)
write_c_string(")", printcharfun);
- else {
- sprintf(buf, " 0x%x>", ht->header.uid);
- write_c_string(buf, printcharfun);
- }
+ else
+ write_fmt_str(printcharfun, " 0x%x>", ht->header.uid);
}
static void finalize_hash_table(void *header, int for_disksave)
("\nFatal error: assertion failed, file %s, line %d, %s\n",
file, line, expr);
}
+ fflush(stderr);
enter_debugger();
#if !defined (ASSERTIONS_DONT_ABORT)
{
char pigbuf[350]; /* see comments in float_to_string */
- float_to_string(pigbuf, XFLOAT_DATA(obj));
+ float_to_string(pigbuf, XFLOAT_DATA(obj), sizeof(pigbuf));
write_c_string(pigbuf, printcharfun);
}
/* let's compute the array we need to print such a float */
#if fpfloat_double_p
- max_float_print_size = snprintf(NULL, 0, "%f", fp) + 10;
+ max_float_print_size = snprintf(NULL, 0, "%f", fp);
#elif fpfloat_long_double_p
- max_float_print_size = snprintf(NULL, 0, "%Lf", fp) + 10;
+ max_float_print_size = snprintf(NULL, 0, "%Lf", fp);
#endif
+ assert(max_float_print_size>0);
+ max_float_print_size += 10;
DEFVAR_CONST_INT("max-float-print-size", &max_float_print_size /*
The maximal string length of a printed float.
extern Lisp_Object Qfloat;
extern void print_float(Lisp_Object, Lisp_Object, int);
-extern void float_to_string(char*, fpfloat);
+extern void float_to_string(char*, fpfloat, int);
/* Note: the 'unused_next_' field exists only to ensure that the
`next' pointer fits within the structure, for the purposes of the
str[expt] = '\0';
len = expt + 1;
}
-#if 0
- /* never want this here */
- /* Computerized scientific notation */
- /* We need room for a radix point, format identifier, and exponent */
- const int space = (expt < 0)
- ? (int)(log(-expt) / log(base)) + 3
- : (int)(log(expt) / log(base)) + 2;
- xrealloc_array(str, Bufbyte, len + space);
- memmove(&str[neg + 2], &str[neg + 1], len - neg);
- str[len + 1] = 'l';
- sprintf ((char *)&str[len + 2], "%ld", expt);
-}
-#endif
return str;
}
print_timeout(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
const Lisp_Timeout *t = XTIMEOUT(obj);
- char buf[64];
-
- sprintf(buf, "#<INTERNAL OBJECT (SXEmacs bug?) (timeout) 0x%lx>",
- (unsigned long)t);
- write_c_string(buf, printcharfun);
+ write_fmt_string(printcharfun, "#<INTERNAL OBJECT (SXEmacs bug?) (timeout) 0x%lx>",
+ (unsigned long)t);
}
static const struct lrecord_description timeout_description[] = {
assert(INTP(Vx));
Vy = Fevent_y_pixel(obj);
assert(INTP(Vy));
- sprintf(buf, "#<motion-event %ld, %ld", (long)XINT(Vx),
- (long)XINT(Vy));
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, "#<motion-event %ld, %ld", (long)XINT(Vx),
+ (long)XINT(Vy));
break;
}
case process_event:
char *lock_info_str;
char *host_name;
char *user_name = user_login_name(NULL);
+ int sz, maxlen;
if (user_name == NULL)
user_name = "";
else
host_name = "";
- lock_info_str = (char *)alloca(strlen(user_name) + strlen(host_name)
- + LOCK_PID_MAX + 5);
+ maxlen = strlen(user_name) + strlen(host_name)
+ + LOCK_PID_MAX + 5
+ lock_info_str = (char *)alloca(maxlen);
- sprintf(lock_info_str, "%s@%s.%lu", user_name, host_name,
- (unsigned long)getpid());
+ sz = snprintf(lock_info_str, maxlen, "%s@%s.%lu", user_name, host_name,
+ (unsigned long)getpid());
+ assert(sz>=0 && sz < maxlen);
err = symlink(lock_info_str, lfname);
if (err != 0 && errno == EEXIST && force) {
struct gcpro gcpro1, gcpro2, gcpro3;
Lisp_Object old_current_buffer;
Lisp_Object subject_buf;
+ int sz;
if (inhibit_clash_detection)
return;
/* Else consider breaking the lock */
locker = (char *)alloca(strlen(lock_info.user) + strlen(lock_info.host)
+ LOCK_PID_MAX + 9);
- sprintf(locker, "%s@%s (pid %lu)", lock_info.user, lock_info.host,
- lock_info.pid);
+ sz = snprintf(locker, sizeof(locker), "%s@%s (pid %lu)",
+ lock_info.user, lock_info.host,
+ lock_info.pid);
+ assert(sz>=0 && sz < sizeof(locker));
FREE_LOCK_INFO(lock_info);
attack = call2_in_buffer(BUFFERP(subject_buf) ? XBUFFER(subject_buf) :
if ((value < -10) || (value > 18)) {
char buf[255];
- sprintf(buf, "sst_set_ger: GER %d out of range", value);
+ int sz = snprintf(buf, sizeof(buf), "sst_set_ger: GER %d out of range", value);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
if ((value < -18) || (value > 12)) {
char buf[255];
- sprintf(buf, "sst_set_gr: GR %d out of range", value);
+ int sz = sprintf(buf, sizeof(buf), "sst_set_gr: GR %d out of range", value);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
char buf[255];
if ((value < -18) || (value > 12)) {
- sprintf(buf, "sst_set_gx: GX %d out of range", value);
+ int sz = snprintf(buf, sizeof(buf), "sst_set_gx: GX %d out of range", value);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
else {
dval1 = (dhz1 * 128 + 63) / 1000;
if ((dval1 < 1) || (dval1 > 255)) {
- sprintf(buf, "sst_tones: dhz1 %d out of range", dhz1);
+ int sz = snprintf(buf, sizeof(buf),
+ "sst_tones: dhz1 %d out of range", dhz1);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
else {
dval2 = (dhz2 * 128 + 63) / 1000;
if ((dval2 < 1) || (dval2 > 255)) {
- sprintf(buf, "sst_tones: dhz2 %d out of range", dhz2);
+ int sz = snprintf(buf, sizeof(buf),
+ "sst_tones: dhz2 %d out of range", dhz2);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
else {
tval = (thz * 128 + 63) / 2000;
if ((tval < 1) || (tval > 255)) {
- sprintf(buf, "sst_tones: thz %d out of range", thz);
+ int sz = snprintf(buf, sizeof(buf),
+ "sst_tones: thz %d out of range", thz);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
else {
rval = (rhz * 128 + 63) / 2000;
if ((rval < 1) || (rval > 255)) {
- sprintf(buf, "sst_tones: rhz %d out of range", dhz2);
+ int sz = snprintf(buf, sizeof(buf),
+ "sst_tones: rhz %d out of range", dhz2);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
}
if ((dval1 != 0 || dval2 != 0) && (tval != 0 || rval != 0)) {
- sprintf(buf,
- "sst_tones: cannot use DTMF and TONE or RINGER at the same time",
- dhz2);
+ int sz = snprintf(buf, sizeof(buf),
+ "sst_tones: cannot use DTMF and TONE or RINGER "
+ "at the same time", dhz2);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
if (tval != 0 && rval != 0) {
- sprintf(buf,
- "sst_tones: cannot use TONE and RINGER at the same time",
- dhz2);
+ int sz = sprintf(buf, sizeof(buf),
+ "sst_tones: cannot use TONE and RINGER at the same time",
+ dhz2);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
return;
}
default:
{
char buf[255];
- sprintf(buf,
- "sst_dtmf: unknown dialing code '%c'",
- *cp);
+ int sz = snprintf(buf, sizeof(buf),
+ "sst_dtmf: unknown dialing code '%c'",
+ *cp);
+ assert(sz >= 0 && sz < sizeof(buf));
warn(buf);
}
}
void print_cons(Lisp_Object, Lisp_Object, int);
void print_vector(Lisp_Object, Lisp_Object, int);
void print_string(Lisp_Object, Lisp_Object, int);
-char *long_to_string(char *, long);
+char *long_to_string(char *, long, int);
void print_internal(Lisp_Object, Lisp_Object, int);
void print_symbol(Lisp_Object, Lisp_Object, int);
/* The number of bytes required to store the decimal printed
/* trigger arts */
if (arts_init() == 0) {
- char tmp[16];
- snprintf(tmp, 15, "SXEmacs%lx", pthread_self());
+ char tmp[48];
+ int sz = snprintf(tmp, sizeof(tmp), "SXEmacs%lx", pthread_self());
+ assert(sz>=0 && sz<sizeof(tmp));
sasd->as = arts_play_stream(sasd->mtap->samplerate,
16 /* HARDCODED */,
sasd->mtap->channels, tmp);
write_c_string(" :server-handle ", pcfun);
if (snd->aud == NULL)
write_c_string("#b0rked", pcfun);
- else {
- char *tmp = alloca(32);
- snprintf(tmp, 31, "0x%x", (unsigned int)snd->aud);
- write_c_string(tmp, pcfun);
- }
+ else
+ write_fmt_str(pcfun, "0x%x", (unsigned int)snd->aud);
return;
}
print_audio_job(worker_job_t job, Lisp_Object pcf)
{
audio_job_t aj = audio_job(job);
- char *str = alloca(64);
-
SXE_MUTEX_LOCK(&aj->mtx);
- write_c_string(" carrying ", pcf);
- snprintf(str, 63, " #<audio-job 0x%lx>", (long unsigned int)aj);
- write_c_string(str, pcf);
+ write_fmt_string(pcf, " carrying #<audio-job 0x%lx>", (long unsigned int)aj);
SXE_MUTEX_UNLOCK(&aj->mtx);
return;
}
specified and we still have a room to store the message
there. */
char msg[256];
-
+ int sz;
switch (ccl->status) {
case CCL_STAT_INVALID_CMD:
- sprintf(msg,
- "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
- code & 0x1F, code, this_ic);
+ sz = snprintf(msg, sizeof(msg),
+ "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
+ code & 0x1F, code, this_ic);
+ assert(sz >= 0 && sz < sizeof(msg));
#ifdef CCL_DEBUG
{
int i = ccl_backtrace_idx - 1;
i = CCL_DEBUG_BACKTRACE_LEN - 1;
if (ccl_backtrace_table[i] == 0)
break;
- sprintf(msg, " %d",
- ccl_backtrace_table[i]);
+ sz = snprintf(msg, sizeof(msg), " %d",
+ ccl_backtrace_table[i]);
+ assert(sz >= 0 && sz < sizeof(msg));
Dynarr_add_many(destination,
(unsigned char *)msg,
strlen(msg));
break;
case CCL_STAT_QUIT:
- sprintf(msg, "\nCCL: Exited.");
+ sz = snprintf(msg, sizeof(msg), "\nCCL: Exited.");
+ assert(sz >= 0 && sz < sizeof(msg));
break;
default:
- sprintf(msg, "\nCCL: Unknown error type (%d).",
- ccl->status);
+ sz = snprintf(msg, sizeof(msg), "\nCCL: Unknown error type (%d).",
+ ccl->status);
+ assert(sz >= 0 && sz < sizeof(msg));
}
Dynarr_add_many(destination, (unsigned char *)msg, strlen(msg));
print_opaque(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
const Lisp_Opaque *p = XOPAQUE(obj);
- char buf[200];
- sprintf(buf,
- "#<INTERNAL OBJECT (SXEmacs bug?) (opaque, size=%lu) 0x%lx>",
- (long)(p->size), (unsigned long)p);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun,
+ "#<INTERNAL OBJECT (SXEmacs bug?) (opaque, size=%lu) 0x%lx>",
+ (long)(p->size), (unsigned long)p);
}
static inline size_t
print_opaque_ptr(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
const Lisp_Opaque_Ptr *p = XOPAQUE_PTR(obj);
- char buf[200];
-
- sprintf(buf,
- "#<INTERNAL OBJECT (SXEmacs bug?) "
- "(opaque-ptr, adr=%p) %p>", p->ptr, p);
- write_c_string(buf, printcharfun);
+
+ write_fmt_string(printcharfun,
+ "#<INTERNAL OBJECT (SXEmacs bug?) "
+ "(opaque-ptr, adr=%p) %p>", p->ptr, p);
}
static int equal_opaque_ptr(Lisp_Object obj1, Lisp_Object obj2, int depth)
static void
print_evp_pkey(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
- char buf[256];
EVP_PKEY *pkey;
X509 *x509;
write_c_string(" empty key", printcharfun);
if (EVP_PKEY_size(pkey) > 0) {
- snprintf(buf, 256, ", size %d", EVP_PKEY_size(pkey)*8);
- write_c_string(buf, printcharfun);
+ write_fmt_str(printcharfun, ", size %d", EVP_PKEY_size(pkey)*8);
}
}
* re-writing _doprnt to be more sane)?
* -wsr
*/
-void float_to_string(char *buf, fpfloat data)
+void float_to_string(char *buf, fpfloat data, int maxlen)
{
Bufbyte *cp, c;
- int width;
+ int width, sz;
if (NILP(Vfloat_output_format) || !STRINGP(Vfloat_output_format)) {
lose:
#if fpfloat_double_p
- sprintf(buf, "%.16g", data);
+ sz = snprintf(buf, maxlen, "%.16g", data);
#elif fpfloat_long_double_p
- sprintf(buf, "%.16Lg", data);
+ sz = snprintf(buf, maxlen, "%.16Lg", data);
#endif
+ assert(sz>=0 && sz<maxlen);
} else { /* oink oink */
/* Check that the spec we have is fully valid.
if (cp[1] != 0)
goto lose;
- sprintf(buf, (char *)XSTRING_DATA(Vfloat_output_format), data);
+ sz = snprintf(buf, maxlen,
+ (char *)XSTRING_DATA(Vfloat_output_format), data);
+ assert(sz>=0 && sz < maxlen);
}
/* added by jwz: don't allow "1.0" to print as "1"; that destroys
{
Bufbyte *s = (Bufbyte *) buf; /* don't use signed chars here!
isdigit() can't hack them! */
- if (*s == '-')
+ if (*s == '-') {
s++;
+ maxlen--;
+ assert(maxlen>0);
+ }
for (; *s; s++)
/* if there's a non-digit, then there is a decimal point, or
it's in exponential notation, both of which are ok. */
if (!isdigit(*s))
goto DONE_LABEL;
/* otherwise, we need to hack it. */
+ maxlen-=2;
+ assert(maxlen>0);
*s++ = '.';
*s++ = '0';
*s = 0;
/* Some machines print "0.4" as ".4". I don't like that. */
if (buf[0] == '.' || (buf[0] == '-' && buf[1] == '.')) {
+ assert(maxlen>0);
int i;
for (i = strlen(buf) + 1; i >= 0; i--)
buf[i + 1] = buf[i];
BUFFER should accept 24 bytes. This should suffice for the longest
numbers on 64-bit machines, including the `-' sign and the trailing
'\0'. Returns a pointer to the trailing '\0'. */
-char *long_to_string(char *buffer, long number)
+char *long_to_string(char *buffer, long number, int maxlen)
{
#if (SIZEOF_LONG != 4) && (SIZEOF_LONG != 8)
/* Huh? */
- sprintf(buffer, "%ld", number);
+ int sz = snprintf(buffer, maxlen, "%ld", number);
+ assert(sz>=0 && sz < maxlen);
return buffer + strlen(buffer);
#else /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
char *p = buffer;
*p++ = '-';
number = -number;
}
-#define FROB(figure) do { \
- if (force || number >= figure) \
- *p++ = number / figure + '0', number %= figure, force = 1; \
- } while (0)
+#define FROB(figure) \
+ do { \
+ if (force || number >= figure) { \
+ *p++ = number / figure + '0'; \
+ number %= figure; \
+ force = 1; \
+ --maxlen; \
+ assert(maxlen>0); \
+ } \
+ } while (0)
#if SIZEOF_LONG == 8
FROB(1000000000000000000L);
FROB(100000000000000000L);
if (EQ(obj, being_printed[i])) {
char buf[32];
*buf = '#';
- long_to_string(buf + 1, i);
+ long_to_string(buf + 1, i, sizeof(buf)-1);
write_c_string(buf, printcharfun);
return;
}
/* ASCII Decimal representation uses 2.4 times as many bits as
machine binary. */
char buf[3 * sizeof(EMACS_INT) + 5];
- long_to_string(buf, XINT(obj));
+ long_to_string(buf, XINT(obj),sizeof(buf));
write_c_string(buf, printcharfun);
break;
}
#endif /* PTY_ITERATION */
{
+ int sz;
+
#ifdef PTY_NAME_SPRINTF
- PTY_NAME_SPRINTF
+ PTY_NAME_SPRINTF;
#else
- sprintf(pty_name, "/dev/pty%c%x", c, i);
+ sz = snprintf(pty_name, sizeof(pty_name), "/dev/pty%c%x", c, i);
+ assert(sz >= 0 && sz < sizeof(pty_name));
#endif /* no PTY_NAME_SPRINTF */
if (sxemacs_stat(pty_name, &stb) < 0) {
if (fd >= 0) {
#ifdef PTY_TTY_NAME_SPRINTF
- PTY_TTY_NAME_SPRINTF
+ PTY_TTY_NAME_SPRINTF;
#else
- sprintf(pty_name, "/dev/tty%c%x", c, i);
+ int sz = snprintf(pty_name, sizeof(pty_name),
+ "/dev/tty%c%x", c, i);
+ assert(sz >= 0 && sz < sizeof(pty_name));
#endif /* no PTY_TTY_NAME_SPRINTF */
if (access(pty_name, R_OK | W_OK) == 0) {
setup_pty(fd);
* Convert to a C string for later use by getaddrinfo.
*/
if (INTP(service)) {
- snprintf(portbuf, sizeof(portbuf), "%ld",
- (long)XINT(service));
+ int sz= snprintf(portbuf, sizeof(portbuf), "%ld",
+ (long)XINT(service));
+ assert(sz >= 0 && sz < sizeof(portbuf));
portstring = portbuf;
port = htons((unsigned short)XINT(service));
} else {
* Convert to a C string for later use by getaddrinfo.
*/
if (INTP(service)) {
- snprintf(portbuf, sizeof(portbuf), "%ld",
- (long)XINT(service));
+ int sz = snprintf(portbuf, sizeof(portbuf), "%ld",
+ (long)XINT(service));
+ assert(sz >= 0 && sz < sizeof(portbuf));
portstring = portbuf;
port = htons((unsigned short)XINT(service));
} else {
#define SHORT_CAST_BUG
/* This is how to get the device name of the tty end of a pty. */
-#define PTY_TTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/pty/tty%c%x", c, i);
+#define PTY_TTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/pty/tty%c%x", c, i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
+
+
/* This is how to get the device name of the control end of a pty. */
-#define PTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/ptym/pty%c%x", c, i);
+#define PTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/ptym/pty%c%x", c, i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
/* This triggers a conditional in xfaces.c. */
#define XOS_NEEDS_TIME_H
#define fsync(x) 0 /* "Comment out" fsync calls */
/* This is how to get the device name of the tty end of a pty. */
-#define PTY_TTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/ttyp%x", i);
+#define PTY_TTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/ttyp%x", i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
/* This is how to get the device name of the control end of a pty. */
-#define PTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/pty%x", i);
+#define PTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/pty%x", i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
/* Formerly "BSD_PGRPS" */
#define PTY_ITERATION \
for (i = 0; ; i++)
-#define PTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/ptyp%d", i);
-#define PTY_TTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/ttyp%d", i);
+#define PTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/ptyp%d", i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
+
+#define PTY_TTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/ttyp%d", i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
/* Must use 'cc' to link when build with motif toolkit. */
#ifndef __GNUC__
/* SCO has ptys, but with weird names */
#define HAVE_PTYS
#define PTY_ITERATION \
- for (i = 0; ; i++)
-#define PTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/ptyp%d", i);
-#define PTY_TTY_NAME_SPRINTF \
- sprintf (pty_name, "/dev/ttyp%d", i);
+ for (i = 0; ; i++)
+#define PTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/ptyp%d", i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
+
+#define PTY_TTY_NAME_SPRINTF \
+ do { \
+ int sz = snprintf (pty_name, sizeof(pty_name), \
+ "/dev/ttyp%d", i); \
+ assert(sz>=0 && sz<sizeof(pty_name)); \
+ } while(0)
+
#define FORCE_ALLOCATE_PTY_THE_OLD_FASHIONED_WAY
/* We have sockets. Always. */
if (sizeof(num) > 16)
abort();
- sprintf(buf, "%lu", (unsigned long)num);
+ length = snprintf(buf, sizeof(buf), "%lu", (unsigned long)num);
+ assert(length >= 0 && length<sizeof(buf));
length = add_str(string, buf, max);
return length;
}
print_symbol_value_magic(Lisp_Object obj,
Lisp_Object printcharfun, int escapeflag)
{
- char buf[200];
- sprintf(buf, "#<INTERNAL OBJECT (SXEmacs bug?) (%s type %d) 0x%lx>",
- XRECORD_LHEADER_IMPLEMENTATION(obj)->name,
- XSYMBOL_VALUE_MAGIC_TYPE(obj), (long)XPNTR(obj));
- write_c_string(buf, printcharfun);
+ write_fmt_str( printcharfun, "#<INTERNAL OBJECT (SXEmacs bug?) (%s type %d) 0x%lx>",
+ XRECORD_LHEADER_IMPLEMENTATION(obj)->name,
+ XSYMBOL_VALUE_MAGIC_TYPE(obj), (long)XPNTR(obj));
}
static const struct lrecord_description symbol_value_forward_description[] = {
line = buffer_line_number(b, pos, 1);
- long_to_string(window_line_number_buf, line + 1);
+ long_to_string(window_line_number_buf, line + 1, sizeof(window_line_number_buf));
return window_line_number_buf;
}
1) + !!column_number_start_at_one;
char buf[sizeof(long)*3+1];
- long_to_string(buf, col);
+ long_to_string(buf, col, sizeof(buf));
Dynarr_add_many(mode_spec_bufbyte_string,
(const Bufbyte *)buf, strlen(buf));