Revision 2722dd6e

View differences:

libavfilter/parseutils.c
183 183

  
184 184
#define ALPHA_SEP '@'
185 185

  
186
int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx)
186
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
187
                   void *log_ctx)
187 188
{
188 189
    char *tail, color_string2[128];
189 190
    const ColorEntry *entry;
......
194 195
    } else if (!strncmp(color_string, "0x", 2))
195 196
        hex_offset = 2;
196 197

  
197
    av_strlcpy(color_string2, color_string + hex_offset, sizeof(color_string2));
198
    if (slen < 0)
199
        slen = strlen(color_string);
200
    av_strlcpy(color_string2, color_string + hex_offset,
201
               FFMIN(slen-hex_offset+1, sizeof(color_string2)));
198 202
    if ((tail = strchr(color_string2, ALPHA_SEP)))
199 203
        *tail++ = 0;
200 204
    len = strlen(color_string2);
......
308 312
        av_log_set_level(AV_LOG_DEBUG);
309 313

  
310 314
        for (i = 0;  i < FF_ARRAY_ELEMS(color_names); i++) {
311
            if (av_parse_color(rgba, color_names[i], NULL) >= 0)
315
            if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
312 316
                printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
313 317
        }
314 318
    }
libavfilter/parseutils.h
40 40
 * 0xff/1.0 completely opaque).
41 41
 * If the alpha component is not specified then 0xff is assumed.
42 42
 * The string "random" will result in a random color.
43
 * @param slen length of the initial part of color_string containing the
44
 * color. It can be set to -1 if color_string is a null terminated string
45
 * containing nothing else than the color.
43 46
 * @return >= 0 in case of success, a negative value in case of
44 47
 * failure (for example if color_string cannot be parsed).
45 48
 */
46
int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx);
49
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
50
                   void *log_ctx);
47 51

  
48 52
#endif  /* AVFILTER_PARSEUTILS_H */
libavfilter/vf_drawbox.c
49 49
        sscanf(args, "%d:%d:%d:%d:%s",
50 50
               &drawbox->x, &drawbox->y, &drawbox->w, &drawbox->h, color_str);
51 51

  
52
    if (av_parse_color(rgba_color, color_str, ctx) < 0)
52
    if (av_parse_color(rgba_color, color_str, -1, ctx) < 0)
53 53
        return AVERROR(EINVAL);
54 54

  
55 55
    drawbox->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
libavfilter/vf_pad.c
143 143
    if (args)
144 144
        sscanf(args, "%d:%d:%d:%d:%s", &pad->w, &pad->h, &pad->x, &pad->y, color_string);
145 145

  
146
    if (av_parse_color(pad->color, color_string, ctx) < 0)
146
    if (av_parse_color(pad->color, color_string, -1, ctx) < 0)
147 147
        return AVERROR(EINVAL);
148 148

  
149 149
    /* sanity check params */
......
377 377
    color->time_base.num = frame_rate_q.den;
378 378
    color->time_base.den = frame_rate_q.num;
379 379

  
380
    if ((ret = av_parse_color(color->color, color_string, ctx)) < 0)
380
    if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0)
381 381
        return ret;
382 382

  
383 383
    return 0;

Also available in: Unified diff