Coverity: Overrun static: CID 137, 136
authorNelson Ferreira <nelson.ferreira@ieee.org>
Sat, 21 Jan 2012 04:24:45 +0000 (23:24 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Sat, 21 Jan 2012 04:24:45 +0000 (23:24 -0500)
* 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 <nelson.ferreira@ieee.org>
src/mule/mule-charset.h

index 31f0031..c8ca0ed 100644 (file)
@@ -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;
 }
 \f
 /************************************************************************/