[MPlayer-dev-eng] [PATCH] suboption escaping
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Oct 19 14:20:39 CEST 2005
Hi,
On Wed, Oct 19, 2005 at 07:12:22AM -0400, Nicolas Plourde wrote:
> On 19-Aug-05, at 6:47 AM, Reimar Döffinger wrote:
> >Ok, I think I found the bug, and I'd like to say I'm not the only
> >one to
> >blame here (I guess I should have check the man page instead of just
> >looking at our implementation of strlcpy). Please test the attached
> >patch.
>
> This fixed the problem. Thank you.
This patch should make our strl functions conform to the specification
(I used this one:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/strlcpy.3.html).
Please check if I got it right (and please really check it this time,
the log says "reviewed by...", but I somehow doubt anyone really
reviewed it).
Greetings,
Reimar Döffinger
-------------- next part --------------
Index: m_option.c
===================================================================
RCS file: /cvsroot/mplayer/main/m_option.c,v
retrieving revision 1.42
diff -u -r1.42 m_option.c
--- m_option.c 13 Oct 2005 18:33:56 -0000 1.42
+++ m_option.c 19 Oct 2005 12:17:42 -0000
@@ -886,7 +886,7 @@
int optlen = strcspn(p, ":=");
/* clear out */
subopt[0] = subparam[0] = 0;
- strlcpy(subopt, p, optlen);
+ strlcpy(subopt, p, optlen + 1);
p = &p[optlen];
if (p[0] == '=') {
sscanf_ret = 2;
@@ -894,7 +894,7 @@
if (p[0] == '"') {
p = &p[1];
optlen = strcspn(p, "\"");
- strlcpy(subparam, p, optlen);
+ strlcpy(subparam, p, optlen + 1);
p = &p[optlen];
if (p[0] != '"') {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Terminating '\"' missing for '%s'\n", subopt);
@@ -909,11 +909,11 @@
return M_OPT_INVALID;
}
p = &p[1];
- strlcpy(subparam, p, optlen);
+ strlcpy(subparam, p, optlen + 1);
p = &p[optlen];
} else {
optlen = strcspn(p, ":");
- strlcpy(subparam, p, optlen);
+ strlcpy(subparam, p, optlen + 1);
p = &p[optlen];
}
}
Index: osdep/strl.c
===================================================================
RCS file: /cvsroot/mplayer/main/osdep/strl.c,v
retrieving revision 1.2
diff -u -r1.2 strl.c
--- osdep/strl.c 6 Apr 2005 11:57:10 -0000 1.2
+++ osdep/strl.c 19 Oct 2005 12:17:42 -0000
@@ -9,40 +9,20 @@
#ifndef HAVE_STRLCPY
unsigned int strlcpy (char *dest, const char *src, unsigned int size)
{
- register unsigned int i;
-
- for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
- dest[i] = src[i];
-
- dest[i] = '\0';
-
- return i;
+ if (size > 0) {
+ strncpy(dest, src, size - 1);
+ dest[size - 1] = 0;
+ }
+ return strlen(src);
}
#endif
#ifndef HAVE_STRLCAT
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 const char *s = src;
-
for (; size > 0 && *d != '\0'; size--, d++);
- for (; size > 0 && *s != '\0'; size--, d++, s++)
- *d = *s;
-
- *d = '\0';
- return (d - dest) + (s - src);
-#endif
+ return (d - dest) + strlcpy(d, src, size);
}
#endif
More information about the MPlayer-dev-eng
mailing list