summaryrefslogtreecommitdiff
path: root/src/lib/evas/common
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-12-30 18:13:32 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-02-07 15:38:42 +0900
commit160d0125593ae79706e6bffa229fcfae24e0ec49 (patch)
treee1aeabdc72486e2b42b196da51c5f5ed2fc777c9 /src/lib/evas/common
parent2928a2d2dab83343c768019fba247be65620e0af (diff)
Evas text utils: Check syntax in color parse
If the color string is not correct (ie. not #RRGGBBAA, #RGBA, #RGB, #RRGGBB), return an error.
Diffstat (limited to 'src/lib/evas/common')
-rw-r--r--src/lib/evas/common/evas_text_utils.c38
-rw-r--r--src/lib/evas/common/evas_text_utils.h2
2 files changed, 23 insertions, 17 deletions
diff --git a/src/lib/evas/common/evas_text_utils.c b/src/lib/evas/common/evas_text_utils.c
index a1ea6e5632..bb38f4876c 100644
--- a/src/lib/evas/common/evas_text_utils.c
+++ b/src/lib/evas/common/evas_text_utils.c
@@ -558,11 +558,12 @@ evas_common_text_props_content_create(void *_fi, const Eina_Unicode *text,
558 * @return numeric value of HEX. 558 * @return numeric value of HEX.
559 */ 559 */
560static int 560static int
561_hex_string_get(char ch) 561_hex_string_get(char ch, Eina_Bool *ok)
562{ 562{
563 if ((ch >= '0') && (ch <= '9')) return (ch - '0'); 563 if ((ch >= '0') && (ch <= '9')) return (ch - '0');
564 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10); 564 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
565 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10); 565 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
566 *ok = EINA_FALSE;
566 return 0; 567 return 0;
567} 568}
568 569
@@ -581,49 +582,54 @@ _hex_string_get(char ch)
581 * @param[out] b The Blue value - NOT NULL. 582 * @param[out] b The Blue value - NOT NULL.
582 * @param[out] a The Alpha value - NOT NULL. 583 * @param[out] a The Alpha value - NOT NULL.
583 */ 584 */
584void 585Eina_Bool
585evas_common_format_color_parse(const char *str, int slen, 586evas_common_format_color_parse(const char *str, int slen,
586 unsigned char *r, unsigned char *g, 587 unsigned char *r, unsigned char *g,
587 unsigned char *b, unsigned char *a) 588 unsigned char *b, unsigned char *a)
588{ 589{
590 Eina_Bool v = EINA_TRUE;
591
589 *r = *g = *b = *a = 0; 592 *r = *g = *b = *a = 0;
590 593
591 if (slen == 7) /* #RRGGBB */ 594 if (slen == 7) /* #RRGGBB */
592 { 595 {
593 *r = (_hex_string_get(str[1]) << 4) | (_hex_string_get(str[2])); 596 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
594 *g = (_hex_string_get(str[3]) << 4) | (_hex_string_get(str[4])); 597 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
595 *b = (_hex_string_get(str[5]) << 4) | (_hex_string_get(str[6])); 598 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
596 *a = 0xff; 599 *a = 0xff;
597 } 600 }
598 else if (slen == 9) /* #RRGGBBAA */ 601 else if (slen == 9) /* #RRGGBBAA */
599 { 602 {
600 *r = (_hex_string_get(str[1]) << 4) | (_hex_string_get(str[2])); 603 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
601 *g = (_hex_string_get(str[3]) << 4) | (_hex_string_get(str[4])); 604 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
602 *b = (_hex_string_get(str[5]) << 4) | (_hex_string_get(str[6])); 605 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
603 *a = (_hex_string_get(str[7]) << 4) | (_hex_string_get(str[8])); 606 *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
604 } 607 }
605 else if (slen == 4) /* #RGB */ 608 else if (slen == 4) /* #RGB */
606 { 609 {
607 *r = _hex_string_get(str[1]); 610 *r = _hex_string_get(str[1], &v);
608 *r = (*r << 4) | *r; 611 *r = (*r << 4) | *r;
609 *g = _hex_string_get(str[2]); 612 *g = _hex_string_get(str[2], &v);
610 *g = (*g << 4) | *g; 613 *g = (*g << 4) | *g;
611 *b = _hex_string_get(str[3]); 614 *b = _hex_string_get(str[3], &v);
612 *b = (*b << 4) | *b; 615 *b = (*b << 4) | *b;
613 *a = 0xff; 616 *a = 0xff;
614 } 617 }
615 else if (slen == 5) /* #RGBA */ 618 else if (slen == 5) /* #RGBA */
616 { 619 {
617 *r = _hex_string_get(str[1]); 620 *r = _hex_string_get(str[1], &v);
618 *r = (*r << 4) | *r; 621 *r = (*r << 4) | *r;
619 *g = _hex_string_get(str[2]); 622 *g = _hex_string_get(str[2], &v);
620 *g = (*g << 4) | *g; 623 *g = (*g << 4) | *g;
621 *b = _hex_string_get(str[3]); 624 *b = _hex_string_get(str[3], &v);
622 *b = (*b << 4) | *b; 625 *b = (*b << 4) | *b;
623 *a = _hex_string_get(str[4]); 626 *a = _hex_string_get(str[4], &v);
624 *a = (*a << 4) | *a; 627 *a = (*a << 4) | *a;
625 } 628 }
629 else v = EINA_FALSE;
630
626 *r = (*r * *a) / 255; 631 *r = (*r * *a) / 255;
627 *g = (*g * *a) / 255; 632 *g = (*g * *a) / 255;
628 *b = (*b * *a) / 255; 633 *b = (*b * *a) / 255;
634 return v;
629} 635}
diff --git a/src/lib/evas/common/evas_text_utils.h b/src/lib/evas/common/evas_text_utils.h
index 96f78cad56..e54046dbf2 100644
--- a/src/lib/evas/common/evas_text_utils.h
+++ b/src/lib/evas/common/evas_text_utils.h
@@ -188,6 +188,6 @@ EAPI void
188evas_common_text_props_merge(Evas_Text_Props *item1, const Evas_Text_Props *item2); 188evas_common_text_props_merge(Evas_Text_Props *item1, const Evas_Text_Props *item2);
189 189
190/* Common to Textblock and Filters */ 190/* Common to Textblock and Filters */
191void evas_common_format_color_parse(const char *str, int slen, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a); 191Eina_Bool evas_common_format_color_parse(const char *str, int slen, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a);
192 192
193#endif 193#endif