- if (lo == mp->lowoff) {
- /*
- * We are just extending (or shrinking) the end of message
- * status array. So we don't have to move anything and can
- * just realloc the message status array.
- */
- if (!(mp->msgstats = realloc (mp->msgstats, MSGSTATSIZE(mp, lo, hi)))) {
- advise (NULL, "unable to reallocate message storage");
- return NULL;
- }
- } else {
- /*
- * We are changing the offset of the message status
- * array. So we will need to shift everything.
- */
- seqset_t *tmpstats;
+ if (lo == mp->lowoff) {
+ /*
+ ** We are just extending (or shrinking) the end of message
+ ** status array. So we don't have to move anything and can
+ ** just realloc the message status array.
+ */
+ mp->msgstats = mh_xrealloc(mp->msgstats, MSGSTATSIZE(mp, lo, hi));
+ /*
+ ** Clear the newly allocated msg flag space. The lowoff and
+ ** hghoff are the old messagenumber range. So the calculation
+ ** of the first new element has to subtract lowoff.
+ */
+ memset(mp->msgstats + mp->hghoff - lo + 1, 0, hi - mp->hghoff);
+ } else {
+ /*
+ ** We are changing the offset of the message status
+ ** array. So we will need to shift everything.
+ */
+ seqset_t *tmpstats;