int unit_bytes = UNIT_BYTES (mt->format);
*new = *mt;
- new->allocated = (mt->nbytes + 1) * unit_bytes;
- MTABLE_MALLOC (new->data, new->allocated, MERROR_MTEXT);
- memcpy (new->data, mt->data, new->allocated);
- if (mt->plist)
- new->plist = mtext__copy_plist (mt->plist, 0, mt->nchars, new, 0);
+ if (mt->nchars > 0)
+ {
+ new->allocated = (mt->nbytes + 1) * unit_bytes;
+ MTABLE_MALLOC (new->data, new->allocated, MERROR_MTEXT);
+ memcpy (new->data, mt->data, new->allocated);
+ if (mt->plist)
+ new->plist = mtext__copy_plist (mt->plist, 0, mt->nchars, new, 0);
+ }
return new;
}
{
M_CHECK_READONLY (mt1, NULL);
- return insert (mt1, mt1->nchars, mt2, 0, mt2->nchars);
+ if (mt2->nchars > 0)
+ insert (mt1, mt1->nchars, mt2, 0, mt2->nchars);
+ return mt1;
}
M_CHECK_READONLY (mt1, NULL);
if (n < 0)
MERROR (MERROR_RANGE, NULL);
- return insert (mt1, mt1->nchars, mt2, 0, mt2->nchars < n ? mt2->nchars : n);
+ if (mt2->nchars > 0)
+ insert (mt1, mt1->nchars, mt2, 0, mt2->nchars < n ? mt2->nchars : n);
+ return mt1;
}
{
M_CHECK_READONLY (mt1, NULL);
mtext_del (mt1, 0, mt1->nchars);
- return insert (mt1, 0, mt2, 0, mt2->nchars);
+ if (mt2->nchars > 0)
+ insert (mt1, 0, mt2, 0, mt2->nchars);
+ return mt1;
}
/*=*/
if (n < 0)
MERROR (MERROR_RANGE, NULL);
mtext_del (mt1, 0, mt1->nchars);
- return insert (mt1, 0, mt2, 0, mt2->nchars < n ? mt2->nchars : n);
+ if (mt2->nchars > 0)
+ insert (mt1, 0, mt2, 0, mt2->nchars < n ? mt2->nchars : n);
+ return mt1;
}
/*=*/
{
MText *new;
- M_CHECK_RANGE (mt, from, to, NULL, new);
+ M_CHECK_RANGE_X (mt, from, to, NULL);
new = mtext ();
new->format = mt->format;
- return insert (new, 0, mt, from, to);
+ if (from < to)
+ insert (new, 0, mt, from, to);
+ return new;
}
/*=*/