/* -*-c-*-
*
- * $Id: mpx.c,v 1.13 2002/10/19 17:56:50 mdw Exp $
+ * $Id: mpx.c,v 1.14 2002/10/19 18:55:08 mdw Exp $
*
* Low-level multiprecision arithmetic
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mpx.c,v $
+ * Revision 1.14 2002/10/19 18:55:08 mdw
+ * Fix overflows in shift primitives.
+ *
* Revision 1.13 2002/10/19 17:56:50 mdw
* Fix bit operations. Test them (a bit) better.
*
/* --- Handle a shift by a multiple of the word size --- */
if (nb == 0) {
- MPX_COPY(dv + nw, dvl, av, avl);
- memset(dv, 0, MPWS(nw));
+ if (nw >= dvl - dv)
+ MPX_ZERO(dv, dvl);
+ else {
+ MPX_COPY(dv + nw, dvl, av, avl);
+ memset(dv, 0, MPWS(nw));
+ }
}
/* --- And finally the difficult case --- *
/* --- Handle a shift by a multiple of the word size --- */
- if (nb == 0)
- MPX_COPY(dv, dvl, av + nw, avl);
+ if (nb == 0) {
+ if (nw >= avl - av)
+ MPX_ZERO(dv, dvl);
+ else
+ MPX_COPY(dv, dvl, av + nw, avl);
+ }
/* --- And finally the difficult case --- */
size_t nr = MPW_BITS - nb;
av += nw;
- w = *av++;
+ w = av < avl ? *av++ : 0;
while (av < avl) {
mpw t;
if (dv >= dvl)