From 79c49ad25398ba5ef48148758fea6c582147e20e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 15:17:53 -0700 Subject: * xdisp.c, lisp.h (message_nolog): Remove; unused. --- src/ChangeLog | 4 ++++ src/lisp.h | 1 - src/xdisp.c | 16 ---------------- 3 files changed, 4 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 1dff4e4a61b..69ab6d0ef3a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-04-06 Paul Eggert + + * xdisp.c, lisp.h (message_nolog): Remove; unused. + 2011-04-06 Eli Zaretskii * msdos.c (careadlinkat, careadlinkatcwd): MS-DOS replacements. diff --git a/src/lisp.h b/src/lisp.h index f3016d521d1..41a64d2f47d 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2628,7 +2628,6 @@ extern Lisp_Object current_message (void); extern void set_message (const char *s, Lisp_Object, EMACS_INT, int); extern void clear_message (int, int); extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); -extern void message_nolog (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); extern void message1 (const char *); extern void message1_nolog (const char *); extern void message2 (const char *, EMACS_INT, int); diff --git a/src/xdisp.c b/src/xdisp.c index fbdd553aa51..16954d0f809 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -8434,22 +8434,6 @@ message (const char *m, ...) } -/* The non-logging version of message. */ - -void -message_nolog (const char *m, ...) -{ - Lisp_Object old_log_max; - va_list ap; - va_start (ap, m); - old_log_max = Vmessage_log_max; - Vmessage_log_max = Qnil; - vmessage (m, ap); - Vmessage_log_max = old_log_max; - va_end (ap); -} - - /* Display the current message in the current mini-buffer. This is only called from error handlers in process.c, and is not time critical. */ -- cgit v1.2.1 From 266c95470005fc0fdb22b984de4bb8ec73aec727 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 15:27:58 -0700 Subject: * term.c (maybe_fatal): Mark its 3rd arg as a printf format, too. --- src/ChangeLog | 2 ++ src/term.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 69ab6d0ef3a..8c92869db1f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-06 Paul Eggert + * term.c (maybe_fatal): Mark its 3rd arg as a printf format, too. + * xdisp.c, lisp.h (message_nolog): Remove; unused. 2011-04-06 Eli Zaretskii diff --git a/src/term.c b/src/term.c index 39c9592e28f..d4e5faf01c8 100644 --- a/src/term.c +++ b/src/term.c @@ -86,7 +86,7 @@ static void dissociate_if_controlling_tty (int fd); static void delete_tty (struct terminal *); static void maybe_fatal (int must_succeed, struct terminal *terminal, const char *str1, const char *str2, ...) - NO_RETURN ATTRIBUTE_FORMAT_PRINTF (4, 5); + NO_RETURN ATTRIBUTE_FORMAT_PRINTF (3, 5) ATTRIBUTE_FORMAT_PRINTF (4, 5); static void vfatal (const char *str, va_list ap) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0); -- cgit v1.2.1 From ce4d90b550a2bfb66099784386910a81b31421ed Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 15:46:00 -0700 Subject: * xterm.c (x_catch_errors): Remove duplicate declaration. --- src/ChangeLog | 2 ++ src/xterm.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 8c92869db1f..ce97ca8204b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-06 Paul Eggert + * xterm.c (x_catch_errors): Remove duplicate declaration. + * term.c (maybe_fatal): Mark its 3rd arg as a printf format, too. * xdisp.c, lisp.h (message_nolog): Remove; unused. diff --git a/src/xterm.c b/src/xterm.c index 92df7ae8746..3fc431c1350 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -7540,8 +7540,6 @@ x_error_catcher (Display *display, XErrorEvent *event) Calling x_uncatch_errors resumes the normal error handling. */ -void x_check_errors (Display *dpy, const char *format); - void x_catch_errors (Display *dpy) { -- cgit v1.2.1 From 7e2cac200108a4626573c4a8de851560c1fee456 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 16:02:23 -0700 Subject: * coding.c (Fdecode_sjis_char): Don't assume CODE fits in int. --- src/ChangeLog | 2 ++ src/coding.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index ce97ca8204b..34e0e1b4cad 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-06 Paul Eggert + * coding.c (Fdecode_sjis_char): Don't assume CODE fits in int. + * xterm.c (x_catch_errors): Remove duplicate declaration. * term.c (maybe_fatal): Mark its 3rd arg as a printf format, too. diff --git a/src/coding.c b/src/coding.c index 555c29cbdf3..798e5c533f6 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9023,7 +9023,7 @@ Return the corresponding character. */) { Lisp_Object spec, attrs, val; struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; - int c; + EMACS_INT c; CHECK_NATNUM (code); c = XFASTINT (code); @@ -9048,7 +9048,8 @@ Return the corresponding character. */) } else { - int c1 = c >> 8, c2 = c & 0xFF; + EMACS_INT c1 = c >> 8; + int c2 = c & 0xFF; if (c1 < 0x81 || (c1 > 0x9F && c1 < 0xE0) || c1 > 0xEF || c2 < 0x40 || c2 == 0x7F || c2 > 0xFC) -- cgit v1.2.1 From bff87ef0301f6039ffcf1f2eb5503fa262a32285 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 19:51:18 -0700 Subject: * keyboard.c (access_keymap_keyremap): Print func name, not garbage. --- src/ChangeLog | 4 ++++ src/keyboard.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 34e0e1b4cad..d31710bcbca 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-04-07 Paul Eggert + + * keyboard.c (access_keymap_keyremap): Print func name, not garbage. + 2011-04-06 Paul Eggert * coding.c (Fdecode_sjis_char): Don't assume CODE fits in int. diff --git a/src/keyboard.c b/src/keyboard.c index ae4fddb2c89..7a8451d8375 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -8778,7 +8778,8 @@ access_keymap_keyremap (Lisp_Object map, Lisp_Object key, Lisp_Object prompt, (To ignore it safely, we would need to gcpro a bunch of other variables.) */ if (! (VECTORP (next) || STRINGP (next))) - error ("Function %s returns invalid key sequence", tem); + error ("Function %s returns invalid key sequence", + SSDATA (SYMBOL_NAME (tem))); } return next; } -- cgit v1.2.1 From b189fa667ed7ac7b17f9665cd8a0c26316b3c521 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 19:53:19 -0700 Subject: * eval.c (internal_lisp_condition_case): Don't pass spurious arg. --- src/ChangeLog | 2 ++ src/eval.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index d31710bcbca..6f2509429d2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-07 Paul Eggert + * eval.c (internal_lisp_condition_case): Don't pass spurious arg. + * keyboard.c (access_keymap_keyremap): Print func name, not garbage. 2011-04-06 Paul Eggert diff --git a/src/eval.c b/src/eval.c index 93da7799bec..8b029967e7a 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1401,7 +1401,7 @@ internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform, || (CONSP (tem) && (SYMBOLP (XCAR (tem)) || CONSP (XCAR (tem)))))) - error ("Invalid condition handler", tem); + error ("Invalid condition handler"); } c.tag = Qnil; -- cgit v1.2.1 From 5fdb398c4b75b0c834aff7132f90b0ce5317a25a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 20:34:05 -0700 Subject: error: Print 32- and 64-bit integers portably (Bug#8435). Without this change, on typical 64-bit hosts error ("...%d...", N) was used to print both 32- and 64-bit integers N, which relied on undefined behavior. * lisp.h, src/m/amdx86-64.h, src/m/ia64.h, src/m/ibms390x.h (pEd): New macro. * lisp.h (error, verror): Mark as printf-like functions. * eval.c (verror): Use vsnprintf, not doprnt, to do the real work. Report overflow in size calculations when allocating printf buffer. Do not truncate output string at its first null byte. * xdisp.c (vmessage): Use vsnprintf, not doprnt, to do the real work. Truncate the output at a character boundary, since vsnprintf does not do that. * charset.c (check_iso_charset_parameter): Convert internal character to string before calling 'error', since %c now has the printf meaning. * coding.c (Fdecode_sjis_char, Fdecode_big5_char): Avoid int overflow when computing char to be passed to 'error'. Do not pass Lisp_Object to 'error'; pass the integer instead. * nsfns.m (Fns_do_applescript): Use int, not long, since it's formatted with plain %d. --- src/ChangeLog | 22 ++++++++++++++++++++++ src/category.c | 4 ++-- src/charset.c | 18 ++++++++++++------ src/coding.c | 53 ++++++++++++++++++++++++++++++++--------------------- src/doc.c | 4 ++-- src/eval.c | 21 +++++++++++++-------- src/fns.c | 2 +- src/intervals.c | 2 +- src/lisp.h | 7 +++++-- src/m/amdx86-64.h | 1 + src/m/ia64.h | 1 + src/m/ibms390x.h | 2 +- src/nsfns.m | 15 +++++++-------- src/sysdep.c | 3 ++- src/window.c | 4 ++-- src/xdisp.c | 16 ++++++++++++---- src/xfns.c | 2 +- 17 files changed, 117 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 6f2509429d2..c1bea6b4cc7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,27 @@ 2011-04-07 Paul Eggert + error: Print 32- and 64-bit integers portably (Bug#8435). + Without this change, on typical 64-bit hosts error ("...%d...", N) + was used to print both 32- and 64-bit integers N, which relied on + undefined behavior. + * lisp.h, src/m/amdx86-64.h, src/m/ia64.h, src/m/ibms390x.h (pEd): + New macro. + * lisp.h (error, verror): Mark as printf-like functions. + * eval.c (verror): Use vsnprintf, not doprnt, to do the real work. + Report overflow in size calculations when allocating printf buffer. + Do not truncate output string at its first null byte. + * xdisp.c (vmessage): Use vsnprintf, not doprnt, to do the real work. + Truncate the output at a character boundary, since vsnprintf does not + do that. + * charset.c (check_iso_charset_parameter): Convert internal + character to string before calling 'error', since %c now has the + printf meaning. + * coding.c (Fdecode_sjis_char, Fdecode_big5_char): Avoid int + overflow when computing char to be passed to 'error'. Do not + pass Lisp_Object to 'error'; pass the integer instead. + * nsfns.m (Fns_do_applescript): Use int, not long, since it's + formatted with plain %d. + * eval.c (internal_lisp_condition_case): Don't pass spurious arg. * keyboard.c (access_keymap_keyremap): Print func name, not garbage. diff --git a/src/category.c b/src/category.c index cc7ff88474f..bba030360c4 100644 --- a/src/category.c +++ b/src/category.c @@ -128,7 +128,7 @@ the current buffer's category table. */) table = check_category_table (table); if (!NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) - error ("Category `%c' is already defined", XFASTINT (category)); + error ("Category `%c' is already defined", (int) XFASTINT (category)); if (!NILP (Vpurify_flag)) docstring = Fpurecopy (docstring); CATEGORY_DOCSTRING (table, XFASTINT (category)) = docstring; @@ -373,7 +373,7 @@ then delete CATEGORY from the category set instead of adding it. */) table = check_category_table (table); if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) - error ("Undefined category: %c", XFASTINT (category)); + error ("Undefined category: %c", (int) XFASTINT (category)); set_value = NILP (reset) ? Qt : Qnil; diff --git a/src/charset.c b/src/charset.c index 32836d459f3..55cbfc4a399 100644 --- a/src/charset.c +++ b/src/charset.c @@ -493,7 +493,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, int co unbind_to (count, Qnil); if (fd < 0 || ! (fp = fdopen (fd, "r"))) - error ("Failure in loading charset map: %S", SDATA (mapfile)); + error ("Failure in loading charset map: %s", SDATA (mapfile)); /* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is large (larger than MAX_ALLOCA). */ @@ -1000,7 +1000,7 @@ usage: (define-charset-internal ...) */) { CHECK_NUMBER (val); if (XINT (val) < '0' || XINT (val) > 127) - error ("Invalid iso-final-char: %d", XINT (val)); + error ("Invalid iso-final-char: %"pEd, XINT (val)); charset.iso_final = XINT (val); } @@ -1022,7 +1022,7 @@ usage: (define-charset-internal ...) */) { CHECK_NATNUM (val); if ((XINT (val) > 0 && XINT (val) <= 128) || XINT (val) >= 256) - error ("Invalid emacs-mule-id: %d", XINT (val)); + error ("Invalid emacs-mule-id: %"pEd, XINT (val)); charset.emacs_mule_id = XINT (val); } @@ -1440,11 +1440,17 @@ check_iso_charset_parameter (Lisp_Object dimension, Lisp_Object chars, Lisp_Obje CHECK_NATNUM (final_char); if (XINT (dimension) > 3) - error ("Invalid DIMENSION %d, it should be 1, 2, or 3", XINT (dimension)); + error ("Invalid DIMENSION %"pEd", it should be 1, 2, or 3", + XINT (dimension)); if (XINT (chars) != 94 && XINT (chars) != 96) - error ("Invalid CHARS %d, it should be 94 or 96", XINT (chars)); + error ("Invalid CHARS %"pEd", it should be 94 or 96", XINT (chars)); if (XINT (final_char) < '0' || XINT (final_char) > '~') - error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", XINT (chars)); + { + unsigned char str[MAX_MULTIBYTE_LENGTH + 1]; + int len = CHAR_STRING (XINT (chars), str); + str[len] = '\0'; + error ("Invalid FINAL-CHAR %s, it should be `0'..`~'", str); + } } diff --git a/src/coding.c b/src/coding.c index 798e5c533f6..f099605c774 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9023,14 +9023,15 @@ Return the corresponding character. */) { Lisp_Object spec, attrs, val; struct charset *charset_roman, *charset_kanji, *charset_kana, *charset; - EMACS_INT c; + EMACS_INT ch; + int c; CHECK_NATNUM (code); - c = XFASTINT (code); + ch = XFASTINT (code); CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec); attrs = AREF (spec, 0); - if (ASCII_BYTE_P (c) + if (ASCII_BYTE_P (ch) && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) return code; @@ -9039,27 +9040,31 @@ Return the corresponding character. */) charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val))); - if (c <= 0x7F) - charset = charset_roman; - else if (c >= 0xA0 && c < 0xDF) + if (ch <= 0x7F) + { + c = ch; + charset = charset_roman; + } + else if (ch >= 0xA0 && ch < 0xDF) { + c = ch - 0x80; charset = charset_kana; - c -= 0x80; } else { - EMACS_INT c1 = c >> 8; - int c2 = c & 0xFF; + EMACS_INT c1 = ch >> 8; + int c2 = ch & 0xFF; if (c1 < 0x81 || (c1 > 0x9F && c1 < 0xE0) || c1 > 0xEF || c2 < 0x40 || c2 == 0x7F || c2 > 0xFC) - error ("Invalid code: %d", code); + error ("Invalid code: %"pEd, ch); + c = ch; SJIS_TO_JIS (c); charset = charset_kanji; } c = DECODE_CHAR (charset, c); if (c < 0) - error ("Invalid code: %d", code); + error ("Invalid code: %"pEd, ch); return make_number (c); } @@ -9099,14 +9104,15 @@ Return the corresponding character. */) { Lisp_Object spec, attrs, val; struct charset *charset_roman, *charset_big5, *charset; + EMACS_INT ch; int c; CHECK_NATNUM (code); - c = XFASTINT (code); + ch = XFASTINT (code); CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec); attrs = AREF (spec, 0); - if (ASCII_BYTE_P (c) + if (ASCII_BYTE_P (ch) && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))) return code; @@ -9114,19 +9120,24 @@ Return the corresponding character. */) charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val); charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val))); - if (c <= 0x7F) - charset = charset_roman; + if (ch <= 0x7F) + { + c = ch; + charset = charset_roman; + } else { - int b1 = c >> 8, b2 = c & 0x7F; + EMACS_INT b1 = ch >> 8; + int b2 = ch & 0x7F; if (b1 < 0xA1 || b1 > 0xFE || b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE) - error ("Invalid code: %d", code); + error ("Invalid code: %"pEd, ch); + c = ch; charset = charset_big5; } - c = DECODE_CHAR (charset, (unsigned )c); + c = DECODE_CHAR (charset, c); if (c < 0) - error ("Invalid code: %d", code); + error ("Invalid code: %"pEd, ch); return make_number (c); } @@ -9298,7 +9309,7 @@ usage: (find-operation-coding-system OPERATION ARGUMENTS...) */) || (EQ (operation, Qinsert_file_contents) && CONSP (target) && STRINGP (XCAR (target)) && BUFFERP (XCDR (target))) || (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) - error ("Invalid %dth argument", XFASTINT (target_idx) + 1); + error ("Invalid %"pEd"th argument", XFASTINT (target_idx) + 1); if (CONSP (target)) target = XCAR (target); @@ -9774,7 +9785,7 @@ usage: (define-coding-system-internal ...) */) CHECK_CHARSET_GET_ID (tmp1, id); CHECK_NATNUM_CDR (val); if (XINT (XCDR (val)) >= 4) - error ("Invalid graphic register number: %d", XINT (XCDR (val))); + error ("Invalid graphic register number: %"pEd, XINT (XCDR (val))); XSETCAR (val, make_number (id)); } diff --git a/src/doc.c b/src/doc.c index 158b09790f7..ed0d2323ed5 100644 --- a/src/doc.c +++ b/src/doc.c @@ -154,7 +154,7 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition) if (0 > lseek (fd, position - offset, 0)) { emacs_close (fd); - error ("Position %ld out of range in doc string file \"%s\"", + error ("Position %"pEd" out of range in doc string file \"%s\"", position, name); } @@ -669,7 +669,7 @@ the same file name is found in the `doc-directory'. */) ; /* Just a source file name boundary marker. Ignore it. */ else - error ("DOC file invalid at position %d", pos); + error ("DOC file invalid at position %"pEd, pos); } } pos += end - buf; diff --git a/src/eval.c b/src/eval.c index 8b029967e7a..77411a911ee 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1977,21 +1977,26 @@ void verror (const char *m, va_list ap) { char buf[200]; - EMACS_INT size = 200; - int mlen; + size_t size = sizeof buf; + size_t size_max = (size_t) -1; char *buffer = buf; int allocated = 0; + int used; Lisp_Object string; - mlen = strlen (m); - while (1) { - EMACS_INT used; - used = doprnt (buffer, size, m, m + mlen, ap); + used = vsnprintf (buffer, size, m, ap); + if (used < 0) + used = 0; if (used < size) break; - size *= 2; + if (size <= size_max / 2) + size *= 2; + else if (size < size_max) + size = size_max; + else + memory_full (); if (allocated) buffer = (char *) xrealloc (buffer, size); else @@ -2001,7 +2006,7 @@ verror (const char *m, va_list ap) } } - string = build_string (buffer); + string = make_string (buffer, used); if (allocated) xfree (buffer); diff --git a/src/fns.c b/src/fns.c index c45d9e31ef2..09ce8c1b597 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1076,7 +1076,7 @@ an error is signaled. */) EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0); if (converted < chars) - error ("Can't convert the %dth character to unibyte", converted); + error ("Can't convert the %"pEd"th character to unibyte", converted); string = make_unibyte_string ((char *) str, chars); xfree (str); } diff --git a/src/intervals.c b/src/intervals.c index 729e6810f74..952f826778c 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -777,7 +777,7 @@ update_interval (register INTERVAL i, EMACS_INT pos) i = i->right; /* Move to the right child */ } else if (NULL_PARENT (i)) - error ("Point %d after end of properties", pos); + error ("Point %"pEd" after end of properties", pos); else i = INTERVAL_PARENT (i); continue; diff --git a/src/lisp.h b/src/lisp.h index 41a64d2f47d..7999fb42d5f 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -38,6 +38,7 @@ extern void check_cons_list (void); #ifndef EMACS_INT #define EMACS_INT long #define BITS_PER_EMACS_INT BITS_PER_LONG +#define pEd "ld" #endif #ifndef EMACS_UINT #define EMACS_UINT unsigned long @@ -46,6 +47,7 @@ extern void check_cons_list (void); #ifndef EMACS_INT #define EMACS_INT int #define BITS_PER_EMACS_INT BITS_PER_INT +#define pEd "d" #endif #ifndef EMACS_UINT #define EMACS_UINT unsigned int @@ -2872,8 +2874,9 @@ extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (size_t, Lisp_Obje extern void specbind (Lisp_Object, Lisp_Object); extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object); extern Lisp_Object unbind_to (int, Lisp_Object); -extern void error (const char *, ...) NO_RETURN; -extern void verror (const char *, va_list) NO_RETURN; +extern void error (const char *, ...) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 2); +extern void verror (const char *, va_list) + NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0); extern void do_autoload (Lisp_Object, Lisp_Object); extern Lisp_Object un_autoload (Lisp_Object); EXFUN (Ffetch_bytecode, 1); diff --git a/src/m/amdx86-64.h b/src/m/amdx86-64.h index 441f41b4444..dbca9b5b838 100644 --- a/src/m/amdx86-64.h +++ b/src/m/amdx86-64.h @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */ /* Define the type to use. */ #define EMACS_INT long +#define pEd "ld" #define EMACS_UINT unsigned long /* Define XPNTR to avoid or'ing with DATA_SEG_BITS */ diff --git a/src/m/ia64.h b/src/m/ia64.h index 101d56e648b..a1374d7c224 100644 --- a/src/m/ia64.h +++ b/src/m/ia64.h @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */ /* Define the type to use. */ #define EMACS_INT long +#define pEd "ld" #define EMACS_UINT unsigned long #ifdef REL_ALLOC diff --git a/src/m/ibms390x.h b/src/m/ibms390x.h index d4ef5c291ef..14228b61e56 100644 --- a/src/m/ibms390x.h +++ b/src/m/ibms390x.h @@ -24,6 +24,7 @@ along with GNU Emacs. If not, see . */ /* Define the type to use. */ #define EMACS_INT long +#define pEd "ld" #define EMACS_UINT unsigned long /* On the 64 bit architecture, we can use 60 bits for addresses */ @@ -31,4 +32,3 @@ along with GNU Emacs. If not, see . */ /* Define XPNTR to avoid or'ing with DATA_SEG_BITS */ #define XPNTR(a) XUINT (a) - diff --git a/src/nsfns.m b/src/nsfns.m index 6a5adbd7bf3..d4445d1d627 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -483,7 +483,7 @@ ns_set_name_internal (FRAME_PTR f, Lisp_Object name) if (!STRINGP (f->icon_name)) encoded_icon_name = encoded_name; else - encoded_icon_name = ENCODE_UTF_8 (f->icon_name); + encoded_icon_name = ENCODE_UTF_8 (f->icon_name); str = [NSString stringWithUTF8String: SDATA (encoded_icon_name)]; @@ -637,7 +637,7 @@ ns_set_name_as_filename (struct frame *f) if (FRAME_ICONIFIED_P (f)) [[view window] setMiniwindowTitle: str]; - else + else { NSString *fstr; @@ -1021,8 +1021,8 @@ frame_parm_handler ns_frame_parm_handlers[] = 0, /* x_set_fullscreen will ignore */ x_set_font_backend, /* generic OK */ x_set_alpha, - 0, /* x_set_sticky */ - 0, /* x_set_tool_bar_position */ + 0, /* x_set_sticky */ + 0, /* x_set_tool_bar_position */ }; @@ -2044,7 +2044,7 @@ In case the execution fails, an error is signaled. */) (Lisp_Object script) { Lisp_Object result; - long status; + int status; CHECK_STRING (script); check_ns (); @@ -2330,7 +2330,7 @@ If omitted or nil, that stands for the selected frame's display. */) { struct ns_display_info *dpyinfo; check_ns (); - + dpyinfo = check_ns_display_info (display); /* We force 24+ bit depths to 24-bit to prevent an overflow. */ return make_number (1 << min (dpyinfo->n_planes, 24)); @@ -2373,7 +2373,7 @@ compute_tip_xy (struct frame *f, pt.y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - XINT (top) - height; } - + /* Ensure in bounds. (Note, screen origin = lower left.) */ if (INTEGERP (left)) *root_x = pt.x; @@ -2655,4 +2655,3 @@ be used as the image of the icon representing the frame. */); check_window_system_func = check_ns; } - diff --git a/src/sysdep.c b/src/sysdep.c index a165a9ca52f..f4f767dac3f 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2361,7 +2361,8 @@ serial_configure (struct Lisp_Process *p, CHECK_NUMBER (tem); err = cfsetspeed (&attr, XINT (tem)); if (err != 0) - error ("cfsetspeed(%d) failed: %s", XINT (tem), emacs_strerror (errno)); + error ("cfsetspeed(%"pEd") failed: %s", XINT (tem), + emacs_strerror (errno)); childp2 = Fplist_put (childp2, QCspeed, tem); /* Configure bytesize. */ diff --git a/src/window.c b/src/window.c index 5ca46dd3316..ebfd1b0f778 100644 --- a/src/window.c +++ b/src/window.c @@ -3804,7 +3804,7 @@ See Info node `(elisp)Splitting Windows' for more details and examples. */) error ("Window height %d too small (after splitting)", size_int); if (size_int + window_safe_height > XFASTINT (o->total_lines)) error ("Window height %d too small (after splitting)", - XFASTINT (o->total_lines) - size_int); + (int) (XFASTINT (o->total_lines) - size_int)); if (NILP (o->parent) || NILP (XWINDOW (o->parent)->vchild)) { @@ -3821,7 +3821,7 @@ See Info node `(elisp)Splitting Windows' for more details and examples. */) error ("Window width %d too small (after splitting)", size_int); if (size_int + window_safe_width > XFASTINT (o->total_cols)) error ("Window width %d too small (after splitting)", - XFASTINT (o->total_cols) - size_int); + (int) (XFASTINT (o->total_cols) - size_int)); if (NILP (o->parent) || NILP (XWINDOW (o->parent)->hchild)) { diff --git a/src/xdisp.c b/src/xdisp.c index 16954d0f809..a296fb33a9f 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -8407,10 +8407,18 @@ vmessage (const char *m, va_list ap) { if (m) { - EMACS_INT len; - - len = doprnt (FRAME_MESSAGE_BUF (f), - FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap); + char *buf = FRAME_MESSAGE_BUF (f); + size_t bufsize = FRAME_MESSAGE_BUF_SIZE (f); + int len = vsnprintf (buf, bufsize, m, ap); + if (len < 0) + len = 0; + + /* Do any truncation at a character boundary. */ + if (0 < bufsize && bufsize <= len) + for (len = bufsize - 1; + len && ! CHAR_HEAD_P (buf[len - 1]); + len--) + continue; message2 (FRAME_MESSAGE_BUF (f), len, 0); } diff --git a/src/xfns.c b/src/xfns.c index 8e5639681df..04b8e44b561 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -215,7 +215,7 @@ check_x_display_info (Lisp_Object object) struct terminal *t = get_terminal (object, 1); if (t->type != output_x_window) - error ("Terminal %d is not an X display", XINT (object)); + error ("Terminal %"pEd" is not an X display", XINT (object)); dpyinfo = t->display_info.x; } -- cgit v1.2.1 From ea6c7ae6bf4e43c7c31babf76600d2ee008f4e19 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 20:49:25 -0700 Subject: Remove the doprnt implementation, as Emacs now uses vsnprintf. --- src/ChangeLog | 6 ++ src/Makefile.in | 2 +- src/deps.mk | 1 - src/doprnt.c | 279 -------------------------------------------------------- src/lisp.h | 4 +- 5 files changed, 8 insertions(+), 284 deletions(-) delete mode 100644 src/doprnt.c (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index c1bea6b4cc7..a98c4e72ba1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2011-04-07 Paul Eggert + Remove the doprnt implementation, as Emacs now uses vsnprintf. + * doprnt.c: Remove. + * lisp.h (doprnt): Remove. + * Makefile.in (base_obj): Remove doprnt.o. + * deps.mk (doprnt.o): Remove. + error: Print 32- and 64-bit integers portably (Bug#8435). Without this change, on typical 64-bit hosts error ("...%d...", N) was used to print both 32- and 64-bit integers N, which relied on diff --git a/src/Makefile.in b/src/Makefile.in index e1195968f7f..154d6abba4e 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -354,7 +354,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \ syntax.o $(UNEXEC_OBJ) bytecode.o \ process.o gnutls.o callproc.o \ region-cache.o sound.o atimer.o \ - doprnt.o intervals.o textprop.o composite.o xml.o \ + intervals.o textprop.o composite.o xml.o \ $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) obj = $(base_obj) $(NS_OBJC_OBJ) diff --git a/src/deps.mk b/src/deps.mk index be5d3694fca..2df1577ef78 100644 --- a/src/deps.mk +++ b/src/deps.mk @@ -82,7 +82,6 @@ dispnew.o: dispnew.c systime.h commands.h process.h frame.h coding.h \ # doc.o's dependency on buildobj.h is in src/Makefile.in. doc.o: doc.c lisp.h $(config_h) buffer.h keyboard.h keymap.h \ character.h systime.h coding.h composite.h ../lib/unistd.h globals.h -doprnt.o: doprnt.c character.h lisp.h globals.h ../lib/unistd.h $(config_h) dosfns.o: buffer.h termchar.h termhooks.h frame.h blockinput.h window.h \ msdos.h dosfns.h dispextern.h charset.h coding.h atimer.h systime.h \ lisp.h $(config_h) diff --git a/src/doprnt.c b/src/doprnt.c deleted file mode 100644 index 36eb272caae..00000000000 --- a/src/doprnt.c +++ /dev/null @@ -1,279 +0,0 @@ -/* Output like sprintf to a buffer of specified size. - Also takes args differently: pass one pointer to an array of strings - in addition to the format string which is separate. - Copyright (C) 1985, 2001-2011 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs. If not, see . */ - - -#include -#include -#include -#include - -#ifdef STDC_HEADERS -#include -#endif - -#include - -#include "lisp.h" - -/* Since we use the macro CHAR_HEAD_P, we have to include this, but - don't have to include others because CHAR_HEAD_P does not contains - another macro. */ -#include "character.h" - -#ifndef DBL_MAX_10_EXP -#define DBL_MAX_10_EXP 308 /* IEEE double */ -#endif - -/* Generate output from a format-spec FORMAT, - terminated at position FORMAT_END. - Output goes in BUFFER, which has room for BUFSIZE chars. - If the output does not fit, truncate it to fit. - Returns the number of bytes stored into BUFFER. - ARGS points to the vector of arguments, and NARGS says how many. - A double counts as two arguments. - String arguments are passed as C strings. - Integers are passed as C integers. */ - -EMACS_INT -doprnt (char *buffer, register int bufsize, const char *format, - const char *format_end, va_list ap) -{ - const char *fmt = format; /* Pointer into format string */ - register char *bufptr = buffer; /* Pointer into output buffer.. */ - - /* Use this for sprintf unless we need something really big. */ - char tembuf[DBL_MAX_10_EXP + 100]; - - /* Size of sprintf_buffer. */ - unsigned size_allocated = sizeof (tembuf); - - /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */ - char *sprintf_buffer = tembuf; - - /* Buffer we have got with malloc. */ - char *big_buffer = 0; - - register int tem; - char *string; - char fixed_buffer[20]; /* Default buffer for small formatting. */ - char *fmtcpy; - int minlen; - char charbuf[MAX_MULTIBYTE_LENGTH + 1]; /* Used for %c. */ - - if (format_end == 0) - format_end = format + strlen (format); - - if ((format_end - format + 1) < sizeof (fixed_buffer)) - fmtcpy = fixed_buffer; - else - fmtcpy = (char *) alloca (format_end - format + 1); - - bufsize--; - - /* Loop until end of format string or buffer full. */ - while (fmt != format_end && bufsize > 0) - { - if (*fmt == '%') /* Check for a '%' character */ - { - unsigned size_bound = 0; - EMACS_INT width; /* Columns occupied by STRING. */ - - fmt++; - /* Copy this one %-spec into fmtcpy. */ - string = fmtcpy; - *string++ = '%'; - while (1) - { - *string++ = *fmt; - if ('0' <= *fmt && *fmt <= '9') - { - /* Get an idea of how much space we might need. - This might be a field width or a precision; e.g. - %1.1000f and %1000.1f both might need 1000+ bytes. - Parse the width or precision, checking for overflow. */ - unsigned n = *fmt - '0'; - while ('0' <= fmt[1] && fmt[1] <= '9') - { - if (n * 10 + fmt[1] - '0' < n) - error ("Format width or precision too large"); - n = n * 10 + fmt[1] - '0'; - *string++ = *++fmt; - } - - if (size_bound < n) - size_bound = n; - } - else if (*fmt == '-' || *fmt == ' ' || *fmt == '.' || *fmt == '+') - ; - else - break; - fmt++; - } - *string = 0; - - /* Make the size bound large enough to handle floating point formats - with large numbers. */ - if (size_bound + DBL_MAX_10_EXP + 50 < size_bound) - error ("Format width or precision too large"); - size_bound += DBL_MAX_10_EXP + 50; - - /* Make sure we have that much. */ - if (size_bound > size_allocated) - { - if (big_buffer) - big_buffer = (char *) xrealloc (big_buffer, size_bound); - else - big_buffer = (char *) xmalloc (size_bound); - sprintf_buffer = big_buffer; - size_allocated = size_bound; - } - minlen = 0; - switch (*fmt++) - { - default: - error ("Invalid format operation %%%c", fmt[-1]); - -/* case 'b': */ - case 'd': - case 'o': - case 'x': - if (sizeof (int) == sizeof (EMACS_INT)) - ; - else if (sizeof (long) == sizeof (EMACS_INT)) - /* Insert an `l' the right place. */ - string[1] = string[0], - string[0] = string[-1], - string[-1] = 'l', - string++; - else - abort (); - sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *)); - /* Now copy into final output, truncating as nec. */ - string = sprintf_buffer; - goto doit; - - case 'f': - case 'e': - case 'g': - { - double d = va_arg(ap, double); - sprintf (sprintf_buffer, fmtcpy, d); - /* Now copy into final output, truncating as nec. */ - string = sprintf_buffer; - goto doit; - } - - case 'S': - string[-1] = 's'; - case 's': - if (fmtcpy[1] != 's') - minlen = atoi (&fmtcpy[1]); - string = va_arg (ap, char *); - tem = strlen (string); - width = strwidth (string, tem); - goto doit1; - - /* Copy string into final output, truncating if no room. */ - doit: - /* Coming here means STRING contains ASCII only. */ - width = tem = strlen (string); - doit1: - /* We have already calculated: - TEM -- length of STRING, - WIDTH -- columns occupied by STRING when displayed, and - MINLEN -- minimum columns of the output. */ - if (minlen > 0) - { - while (minlen > width && bufsize > 0) - { - *bufptr++ = ' '; - bufsize--; - minlen--; - } - minlen = 0; - } - if (tem > bufsize) - { - /* Truncate the string at character boundary. */ - tem = bufsize; - while (!CHAR_HEAD_P (string[tem - 1])) tem--; - memcpy (bufptr, string, tem); - /* We must calculate WIDTH again. */ - width = strwidth (bufptr, tem); - } - else - memcpy (bufptr, string, tem); - bufptr += tem; - bufsize -= tem; - if (minlen < 0) - { - while (minlen < - width && bufsize > 0) - { - *bufptr++ = ' '; - bufsize--; - minlen++; - } - minlen = 0; - } - continue; - - case 'c': - { - /* Sometimes for %c we pass a char, which would widen - to int. Sometimes we pass XFASTINT() or XINT() - values, which would be EMACS_INT. Let's hope that - both are passed the same way, otherwise we'll need - to rewrite callers. */ - EMACS_INT chr = va_arg(ap, EMACS_INT); - tem = CHAR_STRING ((int) chr, (unsigned char *) charbuf); - string = charbuf; - string[tem] = 0; - width = strwidth (string, tem); - if (fmtcpy[1] != 'c') - minlen = atoi (&fmtcpy[1]); - goto doit1; - } - - case '%': - fmt--; /* Drop thru and this % will be treated as normal */ - } - } - - { - /* Just some character; Copy it if the whole multi-byte form - fit in the buffer. */ - char *save_bufptr = bufptr; - - do { *bufptr++ = *fmt++; } - while (--bufsize > 0 && !CHAR_HEAD_P (*fmt)); - if (!CHAR_HEAD_P (*fmt)) - { - bufptr = save_bufptr; - break; - } - } - }; - - /* If we had to malloc something, free it. */ - xfree (big_buffer); - - *bufptr = 0; /* Make sure our string end with a '\0' */ - return bufptr - buffer; -} diff --git a/src/lisp.h b/src/lisp.h index 7999fb42d5f..a6933e70288 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2782,9 +2782,7 @@ extern Lisp_Object internal_with_output_to_temp_buffer extern void float_to_string (char *, double); extern void syms_of_print (void); -/* Defined in doprnt.c */ -extern EMACS_INT doprnt (char *, int, const char *, const char *, va_list); - +/* Defined in lread.c. */ extern Lisp_Object Qvariable_documentation, Qstandard_input; extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; extern Lisp_Object initial_obarray; -- cgit v1.2.1 From 70476b54414db1be5261c71073fc991eab5cd34a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Apr 2011 22:19:50 -0700 Subject: * eval.c (verror): Initial buffer size is 4000 (not 200) bytes. --- src/ChangeLog | 2 ++ src/eval.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index a98c4e72ba1..0993b67cbca 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-07 Paul Eggert + * eval.c (verror): Initial buffer size is 4000 (not 200) bytes. + Remove the doprnt implementation, as Emacs now uses vsnprintf. * doprnt.c: Remove. * lisp.h (doprnt): Remove. diff --git a/src/eval.c b/src/eval.c index 77411a911ee..f794a18da7d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1976,7 +1976,7 @@ find_handler_clause (Lisp_Object handlers, Lisp_Object conditions, void verror (const char *m, va_list ap) { - char buf[200]; + char buf[4000]; size_t size = sizeof buf; size_t size_max = (size_t) -1; char *buffer = buf; -- cgit v1.2.1 From eb3f1cc8dfe6a96505f1c5f9174b2712998cb52f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 8 Apr 2011 16:28:52 -0700 Subject: * eval.c: Port to Windows vsnprintf (Bug#8435). Include . (SIZE_MAX): Define if the headers do not. (verror): Do not give up if vsnprintf returns a negative count. Instead, grow the buffer. This ports to Windows vsnprintf, which does not conform to C99. Problem reported by Eli Zaretskii. Also, simplify the allocation scheme, by avoiding the need for calling realloc, and removing the ALLOCATED variable. --- src/ChangeLog | 11 +++++++++++ src/eval.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 0993b67cbca..68f3dbdedcb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2011-04-08 Paul Eggert + + * eval.c: Port to Windows vsnprintf (Bug#8435). + Include . + (SIZE_MAX): Define if the headers do not. + (verror): Do not give up if vsnprintf returns a negative count. + Instead, grow the buffer. This ports to Windows vsnprintf, which + does not conform to C99. Problem reported by Eli Zaretskii. + Also, simplify the allocation scheme, by avoiding the need for + calling realloc, and removing the ALLOCATED variable. + 2011-04-07 Paul Eggert * eval.c (verror): Initial buffer size is 4000 (not 200) bytes. diff --git a/src/eval.c b/src/eval.c index f794a18da7d..0f9e012b823 100644 --- a/src/eval.c +++ b/src/eval.c @@ -18,6 +18,7 @@ along with GNU Emacs. If not, see . */ #include +#include #include #include "lisp.h" #include "blockinput.h" @@ -30,6 +31,10 @@ along with GNU Emacs. If not, see . */ #include "xterm.h" #endif +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + /* This definition is duplicated in alloc.c and keyboard.c. */ /* Putting it in lisp.h makes cc bomb out! */ @@ -1978,36 +1983,37 @@ verror (const char *m, va_list ap) { char buf[4000]; size_t size = sizeof buf; - size_t size_max = (size_t) -1; + size_t size_max = + min (MOST_POSITIVE_FIXNUM, min (INT_MAX, SIZE_MAX - 1)) + 1; char *buffer = buf; - int allocated = 0; int used; Lisp_Object string; while (1) { used = vsnprintf (buffer, size, m, ap); + if (used < 0) - used = 0; - if (used < size) - break; - if (size <= size_max / 2) - size *= 2; - else if (size < size_max) - size = size_max; - else - memory_full (); - if (allocated) - buffer = (char *) xrealloc (buffer, size); - else { - buffer = (char *) xmalloc (size); - allocated = 1; + /* Non-C99 vsnprintf, such as w32, returns -1 when SIZE is too small. + Guess a larger USED to work around the incompatibility. */ + used = (size <= size_max / 2 ? 2 * size + : size < size_max ? size_max - 1 + : size_max); } + else if (used < size) + break; + if (size_max <= used) + memory_full (); + size = used + 1; + + if (buffer != buf) + xfree (buffer); + buffer = (char *) xmalloc (size); } string = make_string (buffer, used); - if (allocated) + if (buffer != buf) xfree (buffer); xsignal1 (Qerror, string); -- cgit v1.2.1 From 76032d70ca341d94996b968a3e1b522b3070196c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 12:12:39 -0700 Subject: * keyboard.c (read_char): Remove unused var. --- src/ChangeLog | 2 ++ src/keyboard.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index cd1b74b75f1..27dbdd7cb11 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-09 Paul Eggert + * keyboard.c (read_char): Remove unused var. + * eval.c: Port to Windows vsnprintf (Bug#8435). Include . (SIZE_MAX): Define if the headers do not. diff --git a/src/keyboard.c b/src/keyboard.c index e9992ceb365..5df4f1b1ff4 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3090,7 +3090,6 @@ read_char (int commandflag, int nmaps, Lisp_Object *maps, Lisp_Object prev_event /* Process the help character specially if enabled */ if (!NILP (Vhelp_form) && help_char_p (c)) { - Lisp_Object tem0; int count = SPECPDL_INDEX (); help_form_saved_window_configs -- cgit v1.2.1 From dae0cd48d84709e8f3662b7bbf14d22cc46038de Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 12:14:12 -0700 Subject: * ftfont.c: Distingish more carefully between FcChar8 and char. The previous code passed unsigned char * to a functions like strlen and xstrcasecmp that expect char *, which does not conform to the C standard. (get_adstyle_property, ftfont_pattern_entity): Use FcChar8 for arguments to FcPatternGetString, and explicitly cast FcChar8 * to char * when the C standard requires it. --- src/ChangeLog | 8 ++++++++ src/ftfont.c | 29 +++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 27dbdd7cb11..c8811f7708b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2011-04-09 Paul Eggert + * ftfont.c: Distingish more carefully between FcChar8 and char. + The previous code passed unsigned char * to a functions like + strlen and xstrcasecmp that expect char *, which does not + conform to the C standard. + (get_adstyle_property, ftfont_pattern_entity): Use FcChar8 for + arguments to FcPatternGetString, and explicitly cast FcChar8 * to + char * when the C standard requires it. + * keyboard.c (read_char): Remove unused var. * eval.c: Port to Windows vsnprintf (Bug#8435). diff --git a/src/ftfont.c b/src/ftfont.c index 06ba6d7fe25..2e66222d268 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -160,11 +160,13 @@ static struct static Lisp_Object get_adstyle_property (FcPattern *p) { - unsigned char *str, *end; + FcChar8 *fcstr; + char *str, *end; Lisp_Object adstyle; - if (FcPatternGetString (p, FC_STYLE, 0, (FcChar8 **) &str) != FcResultMatch) + if (FcPatternGetString (p, FC_STYLE, 0, &fcstr) != FcResultMatch) return Qnil; + str = (char *) fcstr; for (end = str; *end && *end != ' '; end++); if (*end) { @@ -189,19 +191,20 @@ static Lisp_Object ftfont_pattern_entity (FcPattern *p, Lisp_Object extra) { Lisp_Object key, cache, entity; - unsigned char *file, *str; + FcChar8 *str; + char *file; int idx; int numeric; double dbl; FcBool b; - if (FcPatternGetString (p, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch) + if (FcPatternGetString (p, FC_FILE, 0, &str) != FcResultMatch) return Qnil; if (FcPatternGetInteger (p, FC_INDEX, 0, &idx) != FcResultMatch) return Qnil; - key = Fcons (make_unibyte_string ((char *) file, strlen ((char *) file)), - make_number (idx)); + file = (char *) str; + key = Fcons (make_unibyte_string (file, strlen (file)), make_number (idx)); cache = ftfont_lookup_cache (key, FTFONT_CACHE_FOR_ENTITY); entity = XCAR (cache); if (! NILP (entity)) @@ -219,10 +222,16 @@ ftfont_pattern_entity (FcPattern *p, Lisp_Object extra) ASET (entity, FONT_TYPE_INDEX, Qfreetype); ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1); - if (FcPatternGetString (p, FC_FOUNDRY, 0, (FcChar8 **) &str) == FcResultMatch) - ASET (entity, FONT_FOUNDRY_INDEX, font_intern_prop (str, strlen (str), 1)); - if (FcPatternGetString (p, FC_FAMILY, 0, (FcChar8 **) &str) == FcResultMatch) - ASET (entity, FONT_FAMILY_INDEX, font_intern_prop (str, strlen (str), 1)); + if (FcPatternGetString (p, FC_FOUNDRY, 0, &str) == FcResultMatch) + { + char *s = (char *) str; + ASET (entity, FONT_FOUNDRY_INDEX, font_intern_prop (s, strlen (s), 1)); + } + if (FcPatternGetString (p, FC_FAMILY, 0, &str) == FcResultMatch) + { + char *s = (char *) str; + ASET (entity, FONT_FAMILY_INDEX, font_intern_prop (s, strlen (s), 1)); + } if (FcPatternGetInteger (p, FC_WEIGHT, 0, &numeric) == FcResultMatch) { if (numeric >= FC_WEIGHT_REGULAR && numeric < FC_WEIGHT_MEDIUM) -- cgit v1.2.1 From becfa255fb1fb207fa0b5d850e8df3eb53ba0bea Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 13:19:05 -0700 Subject: * callint.c (Fcall_interactively): <, not <=, for optimization. (Fcall_interactively): Count the number of arguments produced, not the number of arguments given. This is simpler and lets GCC 4.6.0 generate slightly better code. --- src/ChangeLog | 5 +++++ src/callint.c | 35 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index c8811f7708b..86dec69e094 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2011-04-09 Paul Eggert + * callint.c (Fcall_interactively): <, not <=, for optimization. + (Fcall_interactively): Count the number of arguments produced, + not the number of arguments given. This is simpler and lets GCC + 4.6.0 generate slightly better code. + * ftfont.c: Distingish more carefully between FcChar8 and char. The previous code passed unsigned char * to a functions like strlen and xstrcasecmp that expect char *, which does not diff --git a/src/callint.c b/src/callint.c index 60570369d9e..047fbcdb467 100644 --- a/src/callint.c +++ b/src/callint.c @@ -269,8 +269,8 @@ invoke it. If KEYS is omitted or nil, the return value of recorded as a call to the function named callint_argfuns[varies[i]]. */ int *varies; - register size_t i, j; - size_t count; + register size_t i; + size_t nargs; int foo; char prompt1[100]; char *tem1; @@ -445,30 +445,29 @@ invoke it. If KEYS is omitted or nil, the return value of else break; } - /* Count the number of arguments the interactive spec would have - us give to the function. */ + /* Count the number of arguments, which is one plus the number of arguments + the interactive spec would have us give to the function. */ tem = string; - for (j = 0; *tem;) + for (nargs = 1; *tem; ) { /* 'r' specifications ("point and mark as 2 numeric args") produce *two* arguments. */ if (*tem == 'r') - j += 2; + nargs += 2; else - j++; + nargs++; tem = strchr (tem, '\n'); if (tem) ++tem; else break; } - count = j; - args = (Lisp_Object *) alloca ((count + 1) * sizeof (Lisp_Object)); - visargs = (Lisp_Object *) alloca ((count + 1) * sizeof (Lisp_Object)); - varies = (int *) alloca ((count + 1) * sizeof (int)); + args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); + visargs = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); + varies = (int *) alloca (nargs * sizeof (int)); - for (i = 0; i < (count + 1); i++) + for (i = 0; i < nargs; i++) { args[i] = Qnil; visargs[i] = Qnil; @@ -476,8 +475,8 @@ invoke it. If KEYS is omitted or nil, the return value of } GCPRO5 (prefix_arg, function, *args, *visargs, up_event); - gcpro3.nvars = (count + 1); - gcpro4.nvars = (count + 1); + gcpro3.nvars = nargs; + gcpro4.nvars = nargs; if (!NILP (enable)) specbind (Qenable_recursive_minibuffers, Qt); @@ -809,14 +808,14 @@ invoke it. If KEYS is omitted or nil, the return value of if (arg_from_tty || !NILP (record_flag)) { visargs[0] = function; - for (i = 1; i < count + 1; i++) + for (i = 1; i < nargs; i++) { if (varies[i] > 0) visargs[i] = Fcons (intern (callint_argfuns[varies[i]]), Qnil); else visargs[i] = quotify_arg (args[i]); } - Vcommand_history = Fcons (Flist (count + 1, visargs), + Vcommand_history = Fcons (Flist (nargs, visargs), Vcommand_history); /* Don't keep command history around forever. */ if (INTEGERP (Vhistory_length) && XINT (Vhistory_length) > 0) @@ -829,7 +828,7 @@ invoke it. If KEYS is omitted or nil, the return value of /* If we used a marker to hold point, mark, or an end of the region, temporarily, convert it to an integer now. */ - for (i = 1; i <= count; i++) + for (i = 1; i < nargs; i++) if (varies[i] >= 1 && varies[i] <= 4) XSETINT (args[i], marker_position (args[i])); @@ -846,7 +845,7 @@ invoke it. If KEYS is omitted or nil, the return value of specbind (Qcommand_debug_status, Qnil); temporarily_switch_to_single_kboard (NULL); - val = Ffuncall (count + 1, args); + val = Ffuncall (nargs, args); UNGCPRO; return unbind_to (speccount, val); } -- cgit v1.2.1 From e30196164233d058f66efb342eee223f014bf69b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 13:39:49 -0700 Subject: * xmenu.c (set_frame_menubar): Allocate smaller local vectors. This also lets GCC 4.6.0 generate slightly better loop code. --- src/ChangeLog | 3 +++ src/xmenu.c | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 86dec69e094..084f41fc974 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2011-04-09 Paul Eggert + * xmenu.c (set_frame_menubar): Allocate smaller local vectors. + This also lets GCC 4.6.0 generate slightly better loop code. + * callint.c (Fcall_interactively): <, not <=, for optimization. (Fcall_interactively): Count the number of arguments produced, not the number of arguments given. This is simpler and lets GCC diff --git a/src/xmenu.c b/src/xmenu.c index dbf8145f737..b1f7dfb26bc 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -966,6 +966,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) Lisp_Object *previous_items = (Lisp_Object *) alloca (previous_menu_items_used * sizeof (Lisp_Object)); + EMACS_UINT subitems; /* If we are making a new widget, its contents are empty, do always reinitialize them. */ @@ -1010,21 +1011,21 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) menu_items = f->menu_bar_vector; menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0; - submenu_start = (int *) alloca (XVECTOR (items)->size * sizeof (int *)); - submenu_end = (int *) alloca (XVECTOR (items)->size * sizeof (int *)); - submenu_n_panes = (int *) alloca (XVECTOR (items)->size * sizeof (int)); - submenu_top_level_items - = (int *) alloca (XVECTOR (items)->size * sizeof (int *)); + subitems = XVECTOR (items)->size / 4; + submenu_start = (int *) alloca (subitems * sizeof (int *)); + submenu_end = (int *) alloca (subitems * sizeof (int *)); + submenu_n_panes = (int *) alloca (subitems * sizeof (int)); + submenu_top_level_items = (int *) alloca (subitems * sizeof (int *)); init_menu_items (); - for (i = 0; i < XVECTOR (items)->size; i += 4) + for (i = 0; i < subitems; i++) { Lisp_Object key, string, maps; last_i = i; - key = XVECTOR (items)->contents[i]; - string = XVECTOR (items)->contents[i + 1]; - maps = XVECTOR (items)->contents[i + 2]; + key = XVECTOR (items)->contents[4 * i]; + string = XVECTOR (items)->contents[4 * i + 1]; + maps = XVECTOR (items)->contents[4 * i + 2]; if (NILP (string)) break; @@ -1051,7 +1052,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) wv->help = Qnil; first_wv = wv; - for (i = 0; i < last_i; i += 4) + for (i = 0; i < last_i; i++) { menu_items_n_panes = submenu_n_panes[i]; wv = digest_single_submenu (submenu_start[i], submenu_end[i], -- cgit v1.2.1 From 3befa583862681a0df1f75274287d1d32f95f7e4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 13:46:34 -0700 Subject: * charset.c (load_charset_map): <, not <=, for optimization. --- src/ChangeLog | 2 ++ src/charset.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 084f41fc974..1e2d4fd00af 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-09 Paul Eggert + * charset.c (load_charset_map): <, not <=, for optimization. + * xmenu.c (set_frame_menubar): Allocate smaller local vectors. This also lets GCC 4.6.0 generate slightly better loop code. diff --git a/src/charset.c b/src/charset.c index 55cbfc4a399..00206cccf0b 100644 --- a/src/charset.c +++ b/src/charset.c @@ -317,7 +317,7 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, for (i = 0; i < n_entries; i++) { unsigned from, to; - int from_index, to_index; + int from_index, to_index, lim_index; int from_c, to_c; int idx = i % 0x10000; @@ -339,6 +339,7 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, } if (from_index < 0 || to_index < 0) continue; + lim_index = to_index + 1; if (to_c > max_char) max_char = to_c; @@ -348,10 +349,10 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, if (control_flag == 1) { if (charset->method == CHARSET_METHOD_MAP) - for (; from_index <= to_index; from_index++, from_c++) + for (; from_index < lim_index; from_index++, from_c++) ASET (vec, from_index, make_number (from_c)); else - for (; from_index <= to_index; from_index++, from_c++) + for (; from_index < lim_index; from_index++, from_c++) CHAR_TABLE_SET (Vchar_unify_table, CHARSET_CODE_OFFSET (charset) + from_index, make_number (from_c)); @@ -360,7 +361,7 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, { if (charset->method == CHARSET_METHOD_MAP && CHARSET_COMPACT_CODES_P (charset)) - for (; from_index <= to_index; from_index++, from_c++) + for (; from_index < lim_index; from_index++, from_c++) { unsigned code = INDEX_TO_CODE_POINT (charset, from_index); @@ -368,17 +369,17 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, CHAR_TABLE_SET (table, from_c, make_number (code)); } else - for (; from_index <= to_index; from_index++, from_c++) + for (; from_index < lim_index; from_index++, from_c++) { if (NILP (CHAR_TABLE_REF (table, from_c))) CHAR_TABLE_SET (table, from_c, make_number (from_index)); } } else if (control_flag == 3) - for (; from_index <= to_index; from_index++, from_c++) + for (; from_index < lim_index; from_index++, from_c++) SET_TEMP_CHARSET_WORK_DECODER (from_c, from_index); else if (control_flag == 4) - for (; from_index <= to_index; from_index++, from_c++) + for (; from_index < lim_index; from_index++, from_c++) SET_TEMP_CHARSET_WORK_ENCODER (from_c, from_index); else /* control_flag == 0 */ { -- cgit v1.2.1 From 9248994de4e597941230d9cb07a50df994c7825b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 15:21:42 -0700 Subject: * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. --- src/ChangeLog | 1 + src/chartab.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 1e2d4fd00af..9029fff9820 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,7 @@ 2011-04-09 Paul Eggert * charset.c (load_charset_map): <, not <=, for optimization. + * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. * xmenu.c (set_frame_menubar): Allocate smaller local vectors. This also lets GCC 4.6.0 generate slightly better loop code. diff --git a/src/chartab.c b/src/chartab.c index 9ad182131e9..450948a9b37 100644 --- a/src/chartab.c +++ b/src/chartab.c @@ -392,7 +392,8 @@ sub_char_table_set_range (Lisp_Object *table, int depth, int min_char, int from, *table = val; else { - int i, j; + int i; + unsigned j; depth++; if (! SUB_CHAR_TABLE_P (*table)) @@ -403,8 +404,9 @@ sub_char_table_set_range (Lisp_Object *table, int depth, int min_char, int from, to = max_char; i = CHARTAB_IDX (from, depth, min_char); j = CHARTAB_IDX (to, depth, min_char); + j++; min_char += chartab_chars[depth] * i; - for (; i <= j; i++, min_char += chartab_chars[depth]) + for (; i < j; i++, min_char += chartab_chars[depth]) sub_char_table_set_range (XSUB_CHAR_TABLE (*table)->contents + i, depth, min_char, from, to, val); } @@ -416,16 +418,16 @@ char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val) { struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); Lisp_Object *contents = tbl->contents; - int i, min_char; + int i; if (from == to) char_table_set (table, from, val); else { - for (i = CHARTAB_IDX (from, 0, 0), min_char = i * chartab_chars[0]; - min_char <= to; - i++, min_char += chartab_chars[0]) - sub_char_table_set_range (contents + i, 0, min_char, from, to, val); + unsigned lim = to / chartab_chars[0] + 1; + for (i = CHARTAB_IDX (from, 0, 0); i < lim; i++) + sub_char_table_set_range (contents + i, 0, i * chartab_chars[0], + from, to, val); if (ASCII_CHAR_P (from)) tbl->ascii = char_table_ascii (table); } -- cgit v1.2.1 From f9a68bc5fccc6e3b48d59199addaeeaf2a92a8b0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 15:31:34 -0700 Subject: * casetab.c (set_identity, shuffle): Likewise. --- src/ChangeLog | 1 + src/casetab.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 9029fff9820..a979af1050d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -2,6 +2,7 @@ * charset.c (load_charset_map): <, not <=, for optimization. * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. + * casetab.c (set_identity, shuffle): Likewise. * xmenu.c (set_frame_menubar): Allocate smaller local vectors. This also lets GCC 4.6.0 generate slightly better loop code. diff --git a/src/casetab.c b/src/casetab.c index 56f6b065358..9a1accf6940 100644 --- a/src/casetab.c +++ b/src/casetab.c @@ -191,7 +191,8 @@ set_identity (Lisp_Object table, Lisp_Object c, Lisp_Object elt) { if (NATNUMP (elt)) { - int from, to; + int from; + unsigned to; if (CONSP (c)) { @@ -200,7 +201,7 @@ set_identity (Lisp_Object table, Lisp_Object c, Lisp_Object elt) } else from = to = XINT (c); - for (; from <= to; from++) + for (to++; from < to; from++) CHAR_TABLE_SET (table, from, make_number (from)); } } @@ -215,7 +216,8 @@ shuffle (Lisp_Object table, Lisp_Object c, Lisp_Object elt) { if (NATNUMP (elt)) { - int from, to; + int from; + unsigned to; if (CONSP (c)) { @@ -225,7 +227,7 @@ shuffle (Lisp_Object table, Lisp_Object c, Lisp_Object elt) else from = to = XINT (c); - for (; from <= to; from++) + for (to++; from < to; from++) { Lisp_Object tem = Faref (table, elt); Faset (table, elt, make_number (from)); -- cgit v1.2.1 From 14f04e6b49166bbcb05a08fa9f4a4cc0c93597ed Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 15:34:16 -0700 Subject: * chartab.c: Use similar style as for other recent patches. --- src/chartab.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/chartab.c b/src/chartab.c index 450948a9b37..7a0a3aabbb6 100644 --- a/src/chartab.c +++ b/src/chartab.c @@ -404,9 +404,8 @@ sub_char_table_set_range (Lisp_Object *table, int depth, int min_char, int from, to = max_char; i = CHARTAB_IDX (from, depth, min_char); j = CHARTAB_IDX (to, depth, min_char); - j++; min_char += chartab_chars[depth] * i; - for (; i < j; i++, min_char += chartab_chars[depth]) + for (j++; i < j; i++, min_char += chartab_chars[depth]) sub_char_table_set_range (XSUB_CHAR_TABLE (*table)->contents + i, depth, min_char, from, to, val); } -- cgit v1.2.1 From bbf47d44bf46c0cd216119a4bf3fefabd3e53e20 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 15:34:58 -0700 Subject: Mention potential integer overflow problems. --- src/ChangeLog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index a979af1050d..be3925c088e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,7 @@ 2011-04-09 Paul Eggert - * charset.c (load_charset_map): <, not <=, for optimization. + * charset.c (load_charset_map): <, not <=, for optimization, + and to avoid potential problems with integer overflow. * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. * casetab.c (set_identity, shuffle): Likewise. -- cgit v1.2.1 From 3ab1c7ce324bc733e0f45d3f7301eb833736b956 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 15:39:14 -0700 Subject: * editfns.c (Fformat): Likewise. --- src/ChangeLog | 1 + src/editfns.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index be3925c088e..9e2538c5851 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -4,6 +4,7 @@ and to avoid potential problems with integer overflow. * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. * casetab.c (set_identity, shuffle): Likewise. + * editfns.c (Fformat): Likewise. * xmenu.c (set_frame_menubar): Allocate smaller local vectors. This also lets GCC 4.6.0 generate slightly better loop code. diff --git a/src/editfns.c b/src/editfns.c index cd424f277bf..e754a074ba8 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3674,7 +3674,7 @@ usage: (format STRING &rest OBJECTS) */) if (!info) info = (struct info *) alloca (nbytes); memset (info, 0, nbytes); - for (i = 0; i <= nargs; i++) + for (i = 0; i < nargs + 1; i++) info[i].start = -1; if (!discarded) SAFE_ALLOCA (discarded, char *, SBYTES (args[0])); -- cgit v1.2.1 From 1e69125eae782c27b700990bc83a982646ca8ba2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 15:51:22 -0700 Subject: * syntax.c (skip_chars): Likewise. --- src/ChangeLog | 1 + src/syntax.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 9e2538c5851..b5e617b1f20 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -5,6 +5,7 @@ * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. * casetab.c (set_identity, shuffle): Likewise. * editfns.c (Fformat): Likewise. + * syntax.c (skip_chars): Likewise. * xmenu.c (set_frame_menubar): Allocate smaller local vectors. This also lets GCC 4.6.0 generate slightly better loop code. diff --git a/src/syntax.c b/src/syntax.c index 56176f32418..1301c0689ad 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1541,7 +1541,8 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl if (c <= c2) { - while (c <= c2) + unsigned lim2 = c2 + 1; + while (c < lim2) fastmap[c++] = 1; if (! ASCII_CHAR_P (c2)) string_has_eight_bit = 1; @@ -1681,7 +1682,8 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl } if (! ASCII_CHAR_P (c)) { - while (leading_code <= leading_code2) + unsigned lim2 = leading_code2 + 1; + while (leading_code < lim2) fastmap[leading_code++] = 1; if (c <= c2) { @@ -1713,9 +1715,9 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl for (i = 0; i < n_char_ranges; i += 2) { int c1 = char_ranges[i]; - int c2 = char_ranges[i + 1]; + unsigned lim2 = char_ranges[i + 1] + 1; - for (; c1 <= c2; c1++) + for (; c1 < lim2; c1++) { int b = CHAR_TO_BYTE_SAFE (c1); if (b >= 0) -- cgit v1.2.1 From 7d66342ce292392fea0d53e343ec07119ee2d1b8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 16:11:48 -0700 Subject: * xdisp.c (vmessage): Use a better test for character truncation. --- src/ChangeLog | 2 ++ src/xdisp.c | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index b5e617b1f20..3bd4fc1f4c0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-04-09 Paul Eggert + * xdisp.c (vmessage): Use a better test for character truncation. + * charset.c (load_charset_map): <, not <=, for optimization, and to avoid potential problems with integer overflow. * chartab.c (sub_char_table_set_range, char_table_set_range): Likewise. diff --git a/src/xdisp.c b/src/xdisp.c index b1209b998e2..f37254419eb 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -8410,13 +8410,14 @@ vmessage (const char *m, va_list ap) { char *buf = FRAME_MESSAGE_BUF (f); size_t bufsize = FRAME_MESSAGE_BUF_SIZE (f); - int len = vsnprintf (buf, bufsize, m, ap); - if (len < 0) - len = 0; + int len; + + memset (buf, 0, bufsize); + len = vsnprintf (buf, bufsize, m, ap); /* Do any truncation at a character boundary. */ - if (0 < bufsize && bufsize <= len) - for (len = bufsize - 1; + if (! (0 <= len && len < bufsize)) + for (len = strnlen (buf, bufsize); len && ! CHAR_HEAD_P (buf[len - 1]); len--) continue; @@ -19495,7 +19496,7 @@ decode_mode_spec (struct window *w, register int c, int field_width, EMACS_INT limit = BUF_BEGV (b); EMACS_INT limit_byte = BUF_BEGV_BYTE (b); EMACS_INT position; - EMACS_INT distance = + EMACS_INT distance = (height * 2 + 30) * line_number_display_limit_width; if (startpos - distance > limit) -- cgit v1.2.1 From 3fc4037235381288defecf6166450a99d65cd69a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2011 19:27:15 -0700 Subject: * xdisp.c (message_nolog): Bring this back, inside "#if 0". See . --- src/xdisp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/xdisp.c b/src/xdisp.c index f37254419eb..6fd3945511b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -8444,6 +8444,24 @@ message (const char *m, ...) } +#if 0 +/* The non-logging version of message. */ + +void +message_nolog (const char *m, ...) +{ + Lisp_Object old_log_max; + va_list ap; + va_start (ap, m); + old_log_max = Vmessage_log_max; + Vmessage_log_max = Qnil; + vmessage (m, ap); + Vmessage_log_max = old_log_max; + va_end (ap); +} +#endif + + /* Display the current message in the current mini-buffer. This is only called from error handlers in process.c, and is not time critical. */ -- cgit v1.2.1 From 12020a9e6dcfc2213e8bbb0fec259c1ed1202f30 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Apr 2011 09:33:22 -0700 Subject: Keep doprnt.c around for now, as we might revamp and reuse it. --- src/ChangeLog | 5 +- src/doprnt.c | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 src/doprnt.c (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index d3a387d1e63..e9e9abd4876 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -38,8 +38,9 @@ * eval.c (verror): Initial buffer size is 4000 (not 200) bytes. - Remove the doprnt implementation, as Emacs now uses vsnprintf. - * doprnt.c: Remove. + Remove invocations of doprnt, as Emacs now uses vsnprintf. + But keep the doprint source code for now, as we might revamp it + and use it again (Bug#8435). * lisp.h (doprnt): Remove. * Makefile.in (base_obj): Remove doprnt.o. * deps.mk (doprnt.o): Remove. diff --git a/src/doprnt.c b/src/doprnt.c new file mode 100644 index 00000000000..36eb272caae --- /dev/null +++ b/src/doprnt.c @@ -0,0 +1,279 @@ +/* Output like sprintf to a buffer of specified size. + Also takes args differently: pass one pointer to an array of strings + in addition to the format string which is separate. + Copyright (C) 1985, 2001-2011 Free Software Foundation, Inc. + +This file is part of GNU Emacs. + +GNU Emacs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +GNU Emacs is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Emacs. If not, see . */ + + +#include +#include +#include +#include + +#ifdef STDC_HEADERS +#include +#endif + +#include + +#include "lisp.h" + +/* Since we use the macro CHAR_HEAD_P, we have to include this, but + don't have to include others because CHAR_HEAD_P does not contains + another macro. */ +#include "character.h" + +#ifndef DBL_MAX_10_EXP +#define DBL_MAX_10_EXP 308 /* IEEE double */ +#endif + +/* Generate output from a format-spec FORMAT, + terminated at position FORMAT_END. + Output goes in BUFFER, which has room for BUFSIZE chars. + If the output does not fit, truncate it to fit. + Returns the number of bytes stored into BUFFER. + ARGS points to the vector of arguments, and NARGS says how many. + A double counts as two arguments. + String arguments are passed as C strings. + Integers are passed as C integers. */ + +EMACS_INT +doprnt (char *buffer, register int bufsize, const char *format, + const char *format_end, va_list ap) +{ + const char *fmt = format; /* Pointer into format string */ + register char *bufptr = buffer; /* Pointer into output buffer.. */ + + /* Use this for sprintf unless we need something really big. */ + char tembuf[DBL_MAX_10_EXP + 100]; + + /* Size of sprintf_buffer. */ + unsigned size_allocated = sizeof (tembuf); + + /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */ + char *sprintf_buffer = tembuf; + + /* Buffer we have got with malloc. */ + char *big_buffer = 0; + + register int tem; + char *string; + char fixed_buffer[20]; /* Default buffer for small formatting. */ + char *fmtcpy; + int minlen; + char charbuf[MAX_MULTIBYTE_LENGTH + 1]; /* Used for %c. */ + + if (format_end == 0) + format_end = format + strlen (format); + + if ((format_end - format + 1) < sizeof (fixed_buffer)) + fmtcpy = fixed_buffer; + else + fmtcpy = (char *) alloca (format_end - format + 1); + + bufsize--; + + /* Loop until end of format string or buffer full. */ + while (fmt != format_end && bufsize > 0) + { + if (*fmt == '%') /* Check for a '%' character */ + { + unsigned size_bound = 0; + EMACS_INT width; /* Columns occupied by STRING. */ + + fmt++; + /* Copy this one %-spec into fmtcpy. */ + string = fmtcpy; + *string++ = '%'; + while (1) + { + *string++ = *fmt; + if ('0' <= *fmt && *fmt <= '9') + { + /* Get an idea of how much space we might need. + This might be a field width or a precision; e.g. + %1.1000f and %1000.1f both might need 1000+ bytes. + Parse the width or precision, checking for overflow. */ + unsigned n = *fmt - '0'; + while ('0' <= fmt[1] && fmt[1] <= '9') + { + if (n * 10 + fmt[1] - '0' < n) + error ("Format width or precision too large"); + n = n * 10 + fmt[1] - '0'; + *string++ = *++fmt; + } + + if (size_bound < n) + size_bound = n; + } + else if (*fmt == '-' || *fmt == ' ' || *fmt == '.' || *fmt == '+') + ; + else + break; + fmt++; + } + *string = 0; + + /* Make the size bound large enough to handle floating point formats + with large numbers. */ + if (size_bound + DBL_MAX_10_EXP + 50 < size_bound) + error ("Format width or precision too large"); + size_bound += DBL_MAX_10_EXP + 50; + + /* Make sure we have that much. */ + if (size_bound > size_allocated) + { + if (big_buffer) + big_buffer = (char *) xrealloc (big_buffer, size_bound); + else + big_buffer = (char *) xmalloc (size_bound); + sprintf_buffer = big_buffer; + size_allocated = size_bound; + } + minlen = 0; + switch (*fmt++) + { + default: + error ("Invalid format operation %%%c", fmt[-1]); + +/* case 'b': */ + case 'd': + case 'o': + case 'x': + if (sizeof (int) == sizeof (EMACS_INT)) + ; + else if (sizeof (long) == sizeof (EMACS_INT)) + /* Insert an `l' the right place. */ + string[1] = string[0], + string[0] = string[-1], + string[-1] = 'l', + string++; + else + abort (); + sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *)); + /* Now copy into final output, truncating as nec. */ + string = sprintf_buffer; + goto doit; + + case 'f': + case 'e': + case 'g': + { + double d = va_arg(ap, double); + sprintf (sprintf_buffer, fmtcpy, d); + /* Now copy into final output, truncating as nec. */ + string = sprintf_buffer; + goto doit; + } + + case 'S': + string[-1] = 's'; + case 's': + if (fmtcpy[1] != 's') + minlen = atoi (&fmtcpy[1]); + string = va_arg (ap, char *); + tem = strlen (string); + width = strwidth (string, tem); + goto doit1; + + /* Copy string into final output, truncating if no room. */ + doit: + /* Coming here means STRING contains ASCII only. */ + width = tem = strlen (string); + doit1: + /* We have already calculated: + TEM -- length of STRING, + WIDTH -- columns occupied by STRING when displayed, and + MINLEN -- minimum columns of the output. */ + if (minlen > 0) + { + while (minlen > width && bufsize > 0) + { + *bufptr++ = ' '; + bufsize--; + minlen--; + } + minlen = 0; + } + if (tem > bufsize) + { + /* Truncate the string at character boundary. */ + tem = bufsize; + while (!CHAR_HEAD_P (string[tem - 1])) tem--; + memcpy (bufptr, string, tem); + /* We must calculate WIDTH again. */ + width = strwidth (bufptr, tem); + } + else + memcpy (bufptr, string, tem); + bufptr += tem; + bufsize -= tem; + if (minlen < 0) + { + while (minlen < - width && bufsize > 0) + { + *bufptr++ = ' '; + bufsize--; + minlen++; + } + minlen = 0; + } + continue; + + case 'c': + { + /* Sometimes for %c we pass a char, which would widen + to int. Sometimes we pass XFASTINT() or XINT() + values, which would be EMACS_INT. Let's hope that + both are passed the same way, otherwise we'll need + to rewrite callers. */ + EMACS_INT chr = va_arg(ap, EMACS_INT); + tem = CHAR_STRING ((int) chr, (unsigned char *) charbuf); + string = charbuf; + string[tem] = 0; + width = strwidth (string, tem); + if (fmtcpy[1] != 'c') + minlen = atoi (&fmtcpy[1]); + goto doit1; + } + + case '%': + fmt--; /* Drop thru and this % will be treated as normal */ + } + } + + { + /* Just some character; Copy it if the whole multi-byte form + fit in the buffer. */ + char *save_bufptr = bufptr; + + do { *bufptr++ = *fmt++; } + while (--bufsize > 0 && !CHAR_HEAD_P (*fmt)); + if (!CHAR_HEAD_P (*fmt)) + { + bufptr = save_bufptr; + break; + } + } + }; + + /* If we had to malloc something, free it. */ + xfree (big_buffer); + + *bufptr = 0; /* Make sure our string end with a '\0' */ + return bufptr - buffer; +} -- cgit v1.2.1