raster pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=e96532f65c13ffe11b25f7d9b384daa197d928e8
commit e96532f65c13ffe11b25f7d9b384daa197d928e8 Author: Carsten Haitzler (Rasterman) <[email protected]> Date: Sat Feb 10 16:26:15 2018 +0900 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 --- src/lib/efl/interfaces/efl_ui_format.c | 37 ++++++++++++++++++++++------------ 1 file 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 FORMAT_TYPE_DOUBLE, FORMAT_TYPE_INT, FORMAT_TYPE_STRING, + FORMAT_TYPE_STATIC } Format_Type; typedef struct @@ -27,26 +28,23 @@ _is_valid_digit(char x) static Format_Type _format_string_check(const char *fmt) { - const char *itr = NULL; - const char *start = NULL; + const char *itr; Eina_Bool found = EINA_FALSE; - Format_Type ret_type = FORMAT_TYPE_INVALID; + Format_Type ret_type = FORMAT_TYPE_STATIC; - start = strchr(fmt, '%'); - if (!start) return 0; - - while (start) + for (itr = fmt; *itr; itr++) { - if (found && start[1] != '%') + if (itr[0] != '%') continue; + if (itr[1] == '%') { - ret_type = FORMAT_TYPE_INVALID; - break; + itr++; + continue; } - if (start[1] != '%' && !found) + if (!found) { found = EINA_TRUE; - for (itr = start + 1; *itr != '\0'; itr++) + for (itr++; *itr; itr++) { // FIXME: This does not properly support int64 or unsigned. if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || @@ -75,10 +73,19 @@ _format_string_check(const char *fmt) break; } } + if (!(*itr)) break; + } + else + { + ret_type = FORMAT_TYPE_INVALID; + break; } - start = strchr(start + 2, '%'); } + if (ret_type == FORMAT_TYPE_INVALID) + { + 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); + } return ret_type; } @@ -121,6 +128,10 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value) eina_strbuf_append_printf(str, sd->template, v); free(v); } + else if (sd->format_type == FORMAT_TYPE_STATIC) + { + eina_strbuf_append_printf(str, sd->template); + } else { // Error: Discard format string and just print value. --
