From 0f860bd79348a8d857cbf61d114bf689c6af5279 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Thu, 15 Nov 2007 23:38:14 +0000 Subject: [PATCH] (Fformat): Correctly format EMACS_UINT values. --- src/ChangeLog | 2 ++ src/editfns.c | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 82f5f3790fa..6c22f16b189 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2007-11-15 Andreas Schwab + * editfns.c (Fformat): Correctly format EMACS_INT values. + * keyboard.c (Fevent_symbol_parse_modifiers): Fix declaration. 2007-11-15 Stefan Monnier diff --git a/src/editfns.c b/src/editfns.c index 98ab2f90081..74261947d0e 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3801,23 +3801,35 @@ usage: (format STRING &rest OBJECTS) */) format - this_format_start); this_format[format - this_format_start] = 0; - if (INTEGERP (args[n])) + if (format[-1] == 'e' || format[-1] == 'f' || format[-1] == 'g') + sprintf (p, this_format, XFLOAT_DATA (args[n])); + else { - if (format[-1] == 'd') - sprintf (p, this_format, XINT (args[n])); + if (sizeof (EMACS_INT) > sizeof (int)) + { + /* Insert 'l' before format spec. */ + this_format[format - this_format_start] + = this_format[format - this_format_start - 1]; + this_format[format - this_format_start - 1] = 'l'; + this_format[format - this_format_start + 1] = 0; + } + + if (INTEGERP (args[n])) + { + if (format[-1] == 'd') + sprintf (p, this_format, XINT (args[n])); + /* Don't sign-extend for octal or hex printing. */ + else + sprintf (p, this_format, XUINT (args[n])); + } + else if (format[-1] == 'd') + /* Maybe we should use "%1.0f" instead so it also works + for values larger than MAXINT. */ + sprintf (p, this_format, (EMACS_INT) XFLOAT_DATA (args[n])); + else /* Don't sign-extend for octal or hex printing. */ - else - sprintf (p, this_format, XUINT (args[n])); + sprintf (p, this_format, (EMACS_UINT) XFLOAT_DATA (args[n])); } - else if (format[-1] == 'e' || format[-1] == 'f' || format[-1] == 'g') - sprintf (p, this_format, XFLOAT_DATA (args[n])); - else if (format[-1] == 'd') - /* Maybe we should use "%1.0f" instead so it also works - for values larger than MAXINT. */ - sprintf (p, this_format, (EMACS_INT) XFLOAT_DATA (args[n])); - else - /* Don't sign-extend for octal or hex printing. */ - sprintf (p, this_format, (EMACS_UINT) XFLOAT_DATA (args[n])); if (p > buf && multibyte -- 2.39.2