From: SeokYeon Hwang Date: Thu, 27 Nov 2014 06:25:18 +0000 (+0900) Subject: emulator: detecting some error cases X-Git-Tag: Tizen_Studio_1.3_Release_p2.3~41^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18f3ad8c807f17a590a086fea8ea47bade86ccd1;p=sdk%2Femulator%2Fqemu.git emulator: detecting some error cases Detecting some error cases in profile conf file. Quotes can be used in default value section from now. Change-Id: Ib58676dcf1527b0e1d808aa079f25283b716b007 Signed-off-by: SeokYeon Hwang --- diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index e2eff580e9..0cda59b4c3 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -34,7 +34,7 @@ #include "emul_state.h" #define LINE_LIMIT 1024 -#define TOKEN_LIMIT 128 +#define TOKEN_LIMIT 1024 #define OPTION_LIMIT 256 struct variable { @@ -94,6 +94,7 @@ void set_variable(const char * const arg1, const char * const arg2, var->name = name; var->value = value; + QTAILQ_INSERT_TAIL(&variables, var, entry); } @@ -138,7 +139,16 @@ static char *substitute_variables(char *src, bool recursive) int i = 0; int start_index = -1; int end_index = -1; - char *str = g_strdup(src); + char *str; + + // strip "" + int len = strlen(src); + if (src[0] == '"' && src[len - 1] == '"') { + src[len - 1] = '\0'; + str = g_strdup(src + 1); + } else { + str = g_strdup(src); + } for (i = 0; str[i]; ++i) { if(str[i] == '$' && str[i + 1] && str[i + 1] == '{') { @@ -204,7 +214,7 @@ static char *substitute_variables(char *src, bool recursive) bool load_conf(const char * const conf) { - int classification = 0; + int classification = -1; char str[LINE_LIMIT]; char *filename; FILE *file = NULL; @@ -234,21 +244,24 @@ bool load_conf(const char * const conf) do { if (!str[i] || - (!in_quote && - (str[i] == ' ' || str[i] == '\t' || str[i] == '#' - || str[i] == '\r' || str[i] == '\n')) || - (in_quote && str[i] == '"')) { + (!in_quote && + (str[i] == ' ' || str[i] == '\t' || str[i] == '#' + || str[i] == '\r' || str[i] == '\n'))) { if (start_index != -1) { - g_strlcpy(token, str + start_index, - i - start_index + 1); + int len = i - start_index + 1; + if (len < TOKEN_LIMIT) { + g_strlcpy(token, str + start_index, len); + } + else { + // TODO: error handling... + } } } + else if (str[i] == '"') { + in_quote = in_quote ? false : true; + } else { if (start_index < 0) { - if (str[i] == '"') { - in_quote = true; - ++i; - } start_index = i; } } @@ -276,6 +289,10 @@ bool load_conf(const char * const conf) // process line switch (classification) { + case -1: // error + fprintf(stderr, "conf file error !!!\n"); + // TODO: assert ?? + break; case 0: // default variables { gchar **splitted = g_strsplit(token, "=", 2);