mirror of
https://github.com/mpv-player/mpv
synced 2025-01-02 21:12:23 +00:00
fix broken (off-by-one) behavior of our strl* functions (patch by reimar)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@16854 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
f36cc4c21b
commit
c6290a8d4b
22
osdep/strl.c
22
osdep/strl.c
@ -11,10 +11,14 @@ unsigned int strlcpy (char *dest, const char *src, unsigned int size)
|
|||||||
{
|
{
|
||||||
register unsigned int i;
|
register unsigned int i;
|
||||||
|
|
||||||
|
if (size > 0) {
|
||||||
|
size--;
|
||||||
for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
|
for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
|
||||||
dest[i] = src[i];
|
dest[i] = src[i];
|
||||||
|
|
||||||
dest[i] = '\0';
|
dest[i] = '\0';
|
||||||
|
}
|
||||||
|
while (src[i++]);
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -23,26 +27,10 @@ unsigned int strlcpy (char *dest, const char *src, unsigned int size)
|
|||||||
#ifndef HAVE_STRLCAT
|
#ifndef HAVE_STRLCAT
|
||||||
unsigned int strlcat (char *dest, const char *src, unsigned int size)
|
unsigned int strlcat (char *dest, const char *src, unsigned int size)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
register unsigned int i, j;
|
|
||||||
|
|
||||||
for(i=0; size > 0 && dest[i] != '\0'; size--, i++);
|
|
||||||
for(j=0; size > 0 && src[j] != '\0'; size--, i++, j++)
|
|
||||||
dest[i] = src[j];
|
|
||||||
|
|
||||||
dest[i] = '\0';
|
|
||||||
return i;
|
|
||||||
#else
|
|
||||||
register char *d = dest;
|
register char *d = dest;
|
||||||
register const char *s = src;
|
|
||||||
|
|
||||||
for (; size > 0 && *d != '\0'; size--, d++);
|
for (; size > 0 && *d != '\0'; size--, d++);
|
||||||
for (; size > 0 && *s != '\0'; size--, d++, s++)
|
return (d - dest) + strlcpy(d, src, size);
|
||||||
*d = *s;
|
|
||||||
|
|
||||||
*d = '\0';
|
|
||||||
return (d - dest) + (s - src);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user