From: Nelson Ferreira Date: Sat, 21 Jan 2012 04:24:45 +0000 (-0500) Subject: Coverity: Overrun static: CID 137, 136 X-Git-Tag: v22.1.15~32^2~12 X-Git-Url: http://cgit.sxemacs.org/?p=sxemacs;a=commitdiff_plain;h=057eb2987cc8d99ca98a6e11d66c555c82c5b22a Coverity: Overrun static: CID 137, 136 * src/mule/mule-charset.h (CHARSET_BY_ATTRIBUTES): Do paranoid bounds checking... * src/mule/mule-charset.h (REP_BYTES_BY_FIRST_BYTE): Make sure to not dereference in fatal crash scenario where assert flows through... Signed-off-by: Nelson Ferreira --- diff --git a/src/mule/mule-charset.h b/src/mule/mule-charset.h index 31f0031..c8ca0ed 100644 --- a/src/mule/mule-charset.h +++ b/src/mule/mule-charset.h @@ -572,7 +572,13 @@ CHARSET_BY_ATTRIBUTES(unsigned int type, unsigned char final, int dir) final < countof(chlook->charset_by_attributes[0]) && dir < countof(chlook->charset_by_attributes[0][0])); - return chlook->charset_by_attributes[type][final][dir]; +#if defined(SXEMACS_DEBUG) && SXEMACS_DEBUG + if( dir < 0 || ! final < 128 || ! type < 4 ) { + abort(); + return Qnil; + } else +#endif + return chlook->charset_by_attributes[type][final][dir]; } /* Table of number of bytes in the string representation of a character @@ -587,8 +593,12 @@ extern const Bytecount rep_bytes_by_first_byte[0xA0]; extern_inline int REP_BYTES_BY_FIRST_BYTE(Bufbyte fb); extern_inline int REP_BYTES_BY_FIRST_BYTE(Bufbyte fb) { - type_checking_assert(fb < 0xA0); - return rep_bytes_by_first_byte[fb]; + int inbounds = (fb < (sizeof(rep_bytes_by_first_byte)/sizeof(Bytecount))); + type_checking_assert(inbounds); + if(inbounds) + return rep_bytes_by_first_byte[fb]; + else + return 1; } /************************************************************************/