/* xmbsrtowcs.c -- replacement function for mbsrtowcs */
-/* Copyright (C) 2002-2010 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2013 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
do
{
end_or_backslash = strchrnul(p, '\\');
- nms = (end_or_backslash - p);
+ nms = end_or_backslash - p;
if (*end_or_backslash == '\0')
nms++;
It may set 'p' to NULL. */
n = mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
+ if (n == 0 && p == 0)
+ {
+ wsbuf[wcnum] = L'\0';
+ break;
+ }
+
/* Compensate for taking single byte on wcs conversion failure above. */
if (wcslength == 1 && (n == 0 || n == (size_t)-1))
{
state = tmp_state;
p = tmp_p;
- wsbuf[wcnum++] = *p++;
+ wsbuf[wcnum] = *p;
+ if (*p == 0)
+ break;
+ else
+ {
+ wcnum++; p++;
+ }
}
else
wcnum += wcslength;
{
if (destp)
*destp = NULL;
+ if (indicesp)
+ *indicesp = NULL;
return (size_t)-1;
}
if (wsbuf == NULL)
{
*destp = NULL;
+ if (indicesp)
+ *indicesp = NULL;
return (size_t)-1;
}
{
free (wsbuf);
*destp = NULL;
+ *indicesp = NULL;
return (size_t)-1;
}
}
free (wsbuf);
FREE (indices);
*destp = NULL;
+ if (indicesp)
+ *indicesp = NULL;
return (size_t)-1;
}
free (wsbuf);
FREE (indices);
*destp = NULL;
+ if (indicesp)
+ *indicesp = NULL;
return (size_t)-1;
}
wsbuf = wstmp;
if (indicesp)
{
- idxtmp = (char **) realloc (indices, wsbuf_size * sizeof (char **));
+ idxtmp = (char **) realloc (indices, wsbuf_size * sizeof (char *));
if (idxtmp == NULL)
{
free (wsbuf);
free (indices);
*destp = NULL;
+ if (indicesp)
+ *indicesp = NULL;
return (size_t)-1;
}
indices = idxtmp;