* fns.c (Fstring_to_unibyte): Don't rely on undefined behavior
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Apr 2011 20:22:53 +0000 (13:22 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Apr 2011 20:22:53 +0000 (13:22 -0700)
by passing a long int to a printf format expecting an int.

src/ChangeLog
src/fns.c

index 185d611..fd864a4 100644 (file)
@@ -2,6 +2,9 @@
 
        Fix more problems found by GCC 4.6.0's static checks.
 
+       * fns.c (Fstring_to_unibyte): Don't rely on undefined behavior
+       by passing a long int to a printf format expecting an int.
+
        * lisp.h (message, message_nolog, doprint, error, verror, fatal):
        Mark as printf-like functions.
 
index c45d9e3..ca18dbf 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -1076,7 +1076,10 @@ 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);
+       {
+         long lconverted = converted;
+         error ("Can't convert the %ldth character to unibyte", lconverted);
+       }
       string = make_unibyte_string ((char *) str, chars);
       xfree (str);
     }