@@ -50,6 +50,8 @@ downcase_identifier(const char *ident, int len, bool warn, bool truncate)
5050 char * result ;
5151 int i ;
5252 bool enc_is_single_byte ;
53+ Assert (ident != NULL );
54+ Assert (len >= 0 );
5355
5456 result = palloc (len + 1 );
5557 enc_is_single_byte = pg_database_encoding_max_length () == 1 ;
@@ -63,15 +65,18 @@ downcase_identifier(const char *ident, int len, bool warn, bool truncate)
6365 * aren't part of a multi-byte character, and use an ASCII-only approach
6466 * for 7-bit characters.
6567 */
66- strncpy (result , ident , len );
68+ memcpy (result , ident , len );
6769 for (i = 0 ; i < len ; i ++ )
6870 {
6971 unsigned char ch = (unsigned char ) ident [i ];
70- int mblen = pg_mblen (ident + i );
71- if (mblen > 1 )
72+ if (!enc_is_single_byte )
7273 {
73- i += mblen - 1 ;
74- continue ;
74+ int mblen = pg_mblen (ident + i );
75+ if (mblen > 1 )
76+ {
77+ i += (mblen - 1 );
78+ continue ;
79+ }
7580 }
7681
7782 if (ch >= 'A' && ch <= 'Z' )
@@ -94,6 +99,8 @@ upcase_identifier(const char *ident, int len, bool warn, bool truncate)
9499 char * result ;
95100 int i ;
96101 bool enc_is_single_byte ;
102+ Assert (ident != NULL );
103+ Assert (len >= 0 );
97104
98105 result = palloc (len + 1 );
99106 enc_is_single_byte = pg_database_encoding_max_length () == 1 ;
@@ -108,15 +115,18 @@ upcase_identifier(const char *ident, int len, bool warn, bool truncate)
108115 * the high bit set, as long as they aren't part of a multi-byte
109116 * character, and use an ASCII-only downcasing for 7-bit characters.
110117 */
111- strncpy (result , ident , len );
118+ memcpy (result , ident , len );
112119 for (i = 0 ; i < len ; i ++ )
113120 {
114121 unsigned char ch = (unsigned char ) ident [i ];
115- int mblen = pg_mblen (ident + i );
116- if (mblen > 1 )
122+ if (!enc_is_single_byte )
117123 {
118- i += mblen - 1 ;
119- continue ;
124+ int mblen = pg_mblen (ident + i );
125+ if (mblen > 1 )
126+ {
127+ i += (mblen - 1 );
128+ continue ;
129+ }
120130 }
121131
122132 if (ch >= 'a' && ch <= 'z' )
@@ -227,7 +237,7 @@ scanner_isspace(char ch)
227237 if (mblen > 1 )
228238 {
229239 s += mblen ;
230- i += mblen - 1 ;
240+ i += ( mblen - 1 ) ;
231241 continue ;
232242 }
233243
@@ -256,7 +266,7 @@ scanner_isspace(char ch)
256266 if (mblen > 1 )
257267 {
258268 s += mblen ;
259- i += mblen - 1 ;
269+ i += ( mblen - 1 ) ;
260270 continue ;
261271 }
262272
0 commit comments