summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-02-10 16:26:15 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-02-10 16:44:38 +0900
commite96532f65c13ffe11b25f7d9b384daa197d928e8 (patch)
treefdafb1c71a90bd1a9f3e3b972e4927a0f7237c81
parentd26f2237f18cf9408265a867bbba4027fc6e94a1 (diff)
efl ui format - fix format checking to be correct
the format string checking was just ... wrong. it didnt' handle %%. it didn't handle constant strings with no format in them... now it does. fixes T6697 @fix
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c
index bb40c340a8..4ee5a63590 100644
--- a/src/lib/efl/interfaces/efl_ui_format.c
+++ b/src/lib/efl/interfaces/efl_ui_format.c
@@ -10,6 +10,7 @@ typedef enum _Format_Type
10 FORMAT_TYPE_DOUBLE, 10 FORMAT_TYPE_DOUBLE,
11 FORMAT_TYPE_INT, 11 FORMAT_TYPE_INT,
12 FORMAT_TYPE_STRING, 12 FORMAT_TYPE_STRING,
13 FORMAT_TYPE_STATIC
13} Format_Type; 14} Format_Type;
14 15
15typedef struct 16typedef struct
@@ -27,26 +28,23 @@ _is_valid_digit(char x)
27static Format_Type 28static Format_Type
28_format_string_check(const char *fmt) 29_format_string_check(const char *fmt)
29{ 30{
30 const char *itr = NULL; 31 const char *itr;
31 const char *start = NULL;
32 Eina_Bool found = EINA_FALSE; 32 Eina_Bool found = EINA_FALSE;
33 Format_Type ret_type = FORMAT_TYPE_INVALID; 33 Format_Type ret_type = FORMAT_TYPE_STATIC;
34 34
35 start = strchr(fmt, '%'); 35 for (itr = fmt; *itr; itr++)
36 if (!start) return 0;
37
38 while (start)
39 { 36 {
40 if (found && start[1] != '%') 37 if (itr[0] != '%') continue;
38 if (itr[1] == '%')
41 { 39 {
42 ret_type = FORMAT_TYPE_INVALID; 40 itr++;
43 break; 41 continue;
44 } 42 }
45 43
46 if (start[1] != '%' && !found) 44 if (!found)
47 { 45 {
48 found = EINA_TRUE; 46 found = EINA_TRUE;
49 for (itr = start + 1; *itr != '\0'; itr++) 47 for (itr++; *itr; itr++)
50 { 48 {
51 // FIXME: This does not properly support int64 or unsigned. 49 // FIXME: This does not properly support int64 or unsigned.
52 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || 50 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
@@ -75,10 +73,19 @@ _format_string_check(const char *fmt)
75 break; 73 break;
76 } 74 }
77 } 75 }
76 if (!(*itr)) break;
77 }
78 else
79 {
80 ret_type = FORMAT_TYPE_INVALID;
81 break;
78 } 82 }
79 start = strchr(start + 2, '%');
80 } 83 }
81 84
85 if (ret_type == FORMAT_TYPE_INVALID)
86 {
87 ERR("Format string '%s' is invalid. It must have one and only one format element of type 's', 'f', 'F', 'd', 'u', 'i', 'o', 'x' or 'X'", fmt);
88 }
82 return ret_type; 89 return ret_type;
83} 90}
84 91
@@ -121,6 +128,10 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
121 eina_strbuf_append_printf(str, sd->template, v); 128 eina_strbuf_append_printf(str, sd->template, v);
122 free(v); 129 free(v);
123 } 130 }
131 else if (sd->format_type == FORMAT_TYPE_STATIC)
132 {
133 eina_strbuf_append_printf(str, sd->template);
134 }
124 else 135 else
125 { 136 {
126 // Error: Discard format string and just print value. 137 // Error: Discard format string and just print value.