]> granicus.if.org Git - postgresql/blobdiff - src/backend/parser/scansup.c
pgindent run for 9.0, second run
[postgresql] / src / backend / parser / scansup.c
index f2a8f2761ab9188d4a389d81aeff9d05832401d6..f1bb4370fe99873b92daf2181a5406c450afb652 100644 (file)
@@ -4,12 +4,12 @@
  *       support routines for the lex/flex scanner, used by both the normal
  * backend as well as the bootstrap backend
  *
- * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/scansup.c,v 1.35 2007/01/05 22:19:34 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/scansup.c,v 1.42 2010/07/06 19:18:57 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -176,10 +176,20 @@ truncate_identifier(char *ident, int len, bool warn)
        {
                len = pg_mbcliplen(ident, len, NAMEDATALEN - 1);
                if (warn)
+               {
+                       /*
+                        * We avoid using %.*s here because it can misbehave if the data
+                        * is not valid in what libc thinks is the prevailing encoding.
+                        */
+                       char            buf[NAMEDATALEN];
+
+                       memcpy(buf, ident, len);
+                       buf[len] = '\0';
                        ereport(NOTICE,
                                        (errcode(ERRCODE_NAME_TOO_LONG),
-                                        errmsg("identifier \"%s\" will be truncated to \"%.*s\"",
-                                                       ident, len, ident)));
+                                        errmsg("identifier \"%s\" will be truncated to \"%s\"",
+                                                       ident, buf)));
+               }
                ident[len] = '\0';
        }
 }
@@ -197,7 +207,6 @@ bool
 scanner_isspace(char ch)
 {
        /* This must match scan.l's list of {space} characters */
-       /* and plpgsql's scan.l as well */
        if (ch == ' ' ||
                ch == '\t' ||
                ch == '\n' ||