diff options
author | Aurelien Jacobs <aurel@gnuage.org> | 2010-11-13 13:55:01 +0000 |
---|---|---|
committer | Aurelien Jacobs <aurel@gnuage.org> | 2010-11-13 13:55:01 +0000 |
commit | 2722dd6ebf9d93ab097c303df1d789f6074121c8 (patch) | |
tree | e43c90a7cae8457f355aa91128cbff5772819998 | |
parent | 521b8607488966a236cee5268a8797f3ed37e1ed (diff) | |
download | ffmpeg-2722dd6ebf9d93ab097c303df1d789f6074121c8.tar.gz |
improve av_parse_color() to allow for non-null terminated color string
Originally committed as revision 25744 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavfilter/parseutils.c | 10 | ||||
-rw-r--r-- | libavfilter/parseutils.h | 6 | ||||
-rw-r--r-- | libavfilter/vf_drawbox.c | 2 | ||||
-rw-r--r-- | libavfilter/vf_pad.c | 4 |
4 files changed, 15 insertions, 7 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]); } } diff --git a/libavfilter/parseutils.h b/libavfilter/parseutils.h index a56750c02e..322afb3e76 100644 --- a/libavfilter/parseutils.h +++ b/libavfilter/parseutils.h @@ -40,9 +40,13 @@ * 0xff/1.0 completely opaque). * If the alpha component is not specified then 0xff is assumed. * The string "random" will result in a random color. + * @param slen length of the initial part of color_string containing the + * color. It can be set to -1 if color_string is a null terminated string + * containing nothing else than the color. * @return >= 0 in case of success, a negative value in case of * failure (for example if color_string cannot be parsed). */ -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); #endif /* AVFILTER_PARSEUTILS_H */ diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index 76fda584ce..17e73f5588 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -49,7 +49,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) sscanf(args, "%d:%d:%d:%d:%s", &drawbox->x, &drawbox->y, &drawbox->w, &drawbox->h, color_str); - if (av_parse_color(rgba_color, color_str, ctx) < 0) + if (av_parse_color(rgba_color, color_str, -1, ctx) < 0) return AVERROR(EINVAL); drawbox->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]); diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 2b798cc5b4..26fe1d683f 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -143,7 +143,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) if (args) sscanf(args, "%d:%d:%d:%d:%s", &pad->w, &pad->h, &pad->x, &pad->y, color_string); - if (av_parse_color(pad->color, color_string, ctx) < 0) + if (av_parse_color(pad->color, color_string, -1, ctx) < 0) return AVERROR(EINVAL); /* sanity check params */ @@ -377,7 +377,7 @@ static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaq color->time_base.num = frame_rate_q.den; color->time_base.den = frame_rate_q.num; - if ((ret = av_parse_color(color->color, color_string, ctx)) < 0) + if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0) return ret; return 0; |