summaryrefslogtreecommitdiff
path: root/libavfilter/parseutils.c
diff options
context:
space:
mode:
authorAurelien Jacobs <aurel@gnuage.org>2010-11-13 13:55:01 +0000
committerAurelien Jacobs <aurel@gnuage.org>2010-11-13 13:55:01 +0000
commit2722dd6ebf9d93ab097c303df1d789f6074121c8 (patch)
treee43c90a7cae8457f355aa91128cbff5772819998 /libavfilter/parseutils.c
parent521b8607488966a236cee5268a8797f3ed37e1ed (diff)
improve av_parse_color() to allow for non-null terminated color string
Originally committed as revision 25744 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavfilter/parseutils.c')
-rw-r--r--libavfilter/parseutils.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libavfilter/parseutils.c b/libavfilter/parseutils.c
index ebb00614ee..4a7536f915 100644
--- a/libavfilter/parseutils.c
+++ b/libavfilter/parseutils.c
@@ -183,7 +183,8 @@ static int color_table_compare(const void *lhs, const void *rhs)
#define ALPHA_SEP '@'
-int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx)
+int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
+ void *log_ctx)
{
char *tail, color_string2[128];
const ColorEntry *entry;
@@ -194,7 +195,10 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx)
} else if (!strncmp(color_string, "0x", 2))
hex_offset = 2;
- av_strlcpy(color_string2, color_string + hex_offset, sizeof(color_string2));
+ if (slen < 0)
+ slen = strlen(color_string);
+ av_strlcpy(color_string2, color_string + hex_offset,
+ FFMIN(slen-hex_offset+1, sizeof(color_string2)));
if ((tail = strchr(color_string2, ALPHA_SEP)))
*tail++ = 0;
len = strlen(color_string2);
@@ -308,7 +312,7 @@ int main(void)
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
- if (av_parse_color(rgba, color_names[i], NULL) >= 0)
+ if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
}
}