Add a crash gurard to pg_encoding_mblen in case of an invalid encoding
authorTatsuo Ishii <ishii@postgresql.org>
Thu, 19 Apr 2001 02:34:35 +0000 (02:34 +0000)
committerTatsuo Ishii <ishii@postgresql.org>
Thu, 19 Apr 2001 02:34:35 +0000 (02:34 +0000)
given.

src/backend/utils/mb/wchar.c

index f3d91e963f3bda78bea1071fb6fbd7dfa7159d08..43371f9477a0bc86a5ef0d94133f4b134e3c5d5a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * conversion functions between pg_wchar and multi-byte streams.
  * Tatsuo Ishii
- * $Id: wchar.c,v 1.17 2001/03/22 04:00:05 momjian Exp $
+ * $Id: wchar.c,v 1.18 2001/04/19 02:34:35 ishii Exp $
  *
  * WIN1250 client encoding updated by Pavel Behal
  *
@@ -502,5 +502,5 @@ pg_mic_mblen(const unsigned char *mbstr)
 int
 pg_encoding_mblen(int encoding, const unsigned char *mbstr)
 {
-   return ((*pg_wchar_table[encoding].mblen) (mbstr));
+   return( (encoding >= 0 && encoding < sizeof(pg_wchar_table)/sizeof(pg_wchar_tbl))? ((*pg_wchar_table[encoding].mblen) (mbstr)) : ((*pg_wchar_table[SQL_ASCII].mblen) (mbstr)));
 }