--- liblzf/lzf_c.c 2008/05/09 12:42:50 1.32 +++ liblzf/lzf_c.c 2008/08/25 01:40:31 1.33 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2007 Marc Alexander Lehmann + * Copyright (c) 2000-2008 Marc Alexander Lehmann * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -208,7 +208,7 @@ break; } - len -= 2; + len -= 2; /* len is now #octets - 1 */ ip++; if (len < 7) @@ -223,31 +223,34 @@ *op++ = off; + if (expect_true (ip + len < in_end - 2)) + { #if ULTRA_FAST || VERY_FAST - ip += len; -#if VERY_FAST && !ULTRA_FAST - --ip; -#endif - hval = FRST (ip); + ip += len; +# if VERY_FAST && !ULTRA_FAST + --ip; +# endif + hval = FRST (ip); - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; -#if VERY_FAST && !ULTRA_FAST - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; -#endif -#else - do - { +# if VERY_FAST && !ULTRA_FAST hval = NEXT (hval, ip); htab[IDX (hval)] = ip; ip++; - } - while (len--); +# endif +#else + do + { + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; + } + while (len--); #endif + } lit = 0; op++; /* start run */ }