Commit d9dfd78e authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Fix memcpy buf=NULL/len=0 issue in replace_part(). (closes #3790)

Calling memcpy with src or dest=NULL is technically illegal, even if
len=0.  Recent compilers seem to now be generating warnings/errors with
this.

replace_part() is currently the only place we are getting bug reports,
so for now just fix the problem in this one place.
parent 9c6e0988
......@@ -166,24 +166,32 @@ static void replace_part (ENTER_STATE *state, size_t from, char *buf)
{
/* Save the suffix */
size_t savelen = state->lastchar - state->curpos;
wchar_t *savebuf = safe_calloc (savelen, sizeof (wchar_t));
memcpy (savebuf, state->wbuf + state->curpos, savelen * sizeof (wchar_t));
wchar_t *savebuf = NULL;
if (savelen)
{
savebuf = safe_calloc (savelen, sizeof (wchar_t));
memcpy (savebuf, state->wbuf + state->curpos, savelen * sizeof (wchar_t));
}
/* Convert to wide characters */
state->curpos = my_mbstowcs (&state->wbuf, &state->wbuflen, from, buf);
/* Make space for suffix */
if (state->curpos + savelen > state->wbuflen)
if (savelen)
{
state->wbuflen = state->curpos + savelen;
safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t));
/* Make space for suffix */
if (state->curpos + savelen > state->wbuflen)
{
state->wbuflen = state->curpos + savelen;
safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t));
}
/* Restore suffix */
memcpy (state->wbuf + state->curpos, savebuf, savelen * sizeof (wchar_t));
FREE (&savebuf);
}
/* Restore suffix */
memcpy (state->wbuf + state->curpos, savebuf, savelen * sizeof (wchar_t));
state->lastchar = state->curpos + savelen;
FREE (&savebuf);
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment