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/coding.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/coding.c') 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 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/coding.c | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'src/coding.c') 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)); } -- cgit v1.2.1