From f52fcaa4f399a0f96d4be0bcaa8342818f15e82b Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Thu, 15 Nov 2007 23:45:21 +0000 Subject: [PATCH] (Fformat): Correctly format EMACS_INT values. --- src/ChangeLog | 4 ++++ src/editfns.c | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1899b577f74..c6c2db23f12 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2007-11-15 Andreas Schwab + + * editfns.c (Fformat): Correctly format EMACS_INT values. + 2007-11-15 Juanma Barranquero * macfns.c (Fx_create_frame, Fx_display_pixel_width) diff --git a/src/editfns.c b/src/editfns.c index 6c6742d242e..fb9c1c96b59 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3803,23 +3803,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])); - /* Don't sign-extend for octal or hex printing. */ + 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 - sprintf (p, this_format, XUINT (args[n])); + /* Don't sign-extend for octal or hex printing. */ + 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