提交 9df2e499 编写于 作者: B Benguang Zhao

fix: remove escaping double-quotation mark for sml binary str encoding in parseSmlValue

enh: preallocate buffer for parseSmlValue
上级 c58e67b8
...@@ -2058,6 +2058,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2058,6 +2058,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
const char *start, *cur; const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
char *value = NULL; char *value = NULL;
int32_t bufSize = TSDB_FUNC_BUF_SIZE;
int16_t len = 0; int16_t len = 0;
bool kv_done = false; bool kv_done = false;
...@@ -2077,6 +2078,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2077,6 +2078,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
val_rqoute val_rqoute
} val_state; } val_state;
value = malloc(bufSize);
if (value == NULL) {
ret = TSDB_CODE_TSC_OUT_OF_MEMORY;
goto error;
}
start = cur = *idx; start = cur = *idx;
tag_state = tag_common; tag_state = tag_common;
val_state = val_common; val_state = val_common;
...@@ -2095,7 +2101,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2095,7 +2101,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
back_slash = false; back_slash = false;
cur++; cur++;
len++;
break; break;
} }
...@@ -2104,7 +2109,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2104,7 +2109,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
tag_state = tag_lqoute; tag_state = tag_lqoute;
} }
cur += 1; cur += 1;
len += 1;
break; break;
} else if (*cur == 'L') { } else if (*cur == 'L') {
line_len = strlen(*idx); line_len = strlen(*idx);
...@@ -2122,7 +2126,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2122,7 +2126,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
tag_state = tag_lqoute; tag_state = tag_lqoute;
} }
cur += 2; cur += 2;
len += 2;
break; break;
} }
} }
...@@ -2131,8 +2134,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2131,8 +2134,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
case '\\': case '\\':
back_slash = true; back_slash = true;
cur++; cur++;
len++; continue;
break;
case ',': case ',':
kv_done = true; kv_done = true;
break; break;
...@@ -2146,7 +2148,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2146,7 +2148,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
default: default:
cur++; cur++;
len++;
} }
break; break;
...@@ -2160,7 +2161,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2160,7 +2161,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
back_slash = false; back_slash = false;
cur++; cur++;
len++;
break; break;
} else if (double_quote == true) { } else if (double_quote == true) {
if (*cur != ' ' && *cur != ',' && *cur != '\0') { if (*cur != ' ' && *cur != ',' && *cur != '\0') {
...@@ -2182,13 +2182,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2182,13 +2182,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
case '\\': case '\\':
back_slash = true; back_slash = true;
cur++; cur++;
len++; continue;
break;
case '"': case '"':
double_quote = true; double_quote = true;
cur++; cur++;
len++;
break; break;
case '\0': case '\0':
...@@ -2199,7 +2197,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2199,7 +2197,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
default: default:
cur++; cur++;
len++;
} }
break; break;
...@@ -2217,9 +2214,8 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2217,9 +2214,8 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
goto error; goto error;
} }
back_slash = false; back_slash = false;
cur++; cur++;
len++;
break; break;
} }
...@@ -2235,7 +2231,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2235,7 +2231,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
} }
cur += 1; cur += 1;
len += 1;
break; break;
} else if (*cur == 'L') { } else if (*cur == 'L') {
line_len = strlen(*idx); line_len = strlen(*idx);
...@@ -2252,12 +2247,10 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2252,12 +2247,10 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
if (cur + 1 == *idx + 1) { if (cur + 1 == *idx + 1) {
val_state = val_lqoute; val_state = val_lqoute;
cur += 2; cur += 2;
len += 2;
} else { } else {
/* MUST at the end of string */ /* MUST at the end of string */
if (cur + 2 >= *idx + line_len) { if (cur + 2 >= *idx + line_len) {
cur += 2; cur += 2;
len += 2;
*is_last_kv = true; *is_last_kv = true;
kv_done = true; kv_done = true;
} else { } else {
...@@ -2271,7 +2264,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2271,7 +2264,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
} }
cur += 2; cur += 2;
len += 2;
kv_done = true; kv_done = true;
} }
} }
...@@ -2284,8 +2276,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2284,8 +2276,7 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
case '\\': case '\\':
back_slash = true; back_slash = true;
cur++; cur++;
len++; continue;
break;
case ',': case ',':
kv_done = true; kv_done = true;
...@@ -2300,7 +2291,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2300,7 +2291,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
default: default:
cur++; cur++;
len++;
} }
break; break;
...@@ -2311,10 +2301,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2311,10 +2301,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
ret = TSDB_CODE_TSC_LINE_SYNTAX_ERROR; ret = TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
goto error; goto error;
} }
if (*cur == '"') {
start++;
}
back_slash = false; back_slash = false;
cur++; cur++;
len++;
break; break;
} else if (double_quote == true) { } else if (double_quote == true) {
if (*cur != ' ' && *cur != ',' && *cur != '\0') { if (*cur != ' ' && *cur != ',' && *cur != '\0') {
...@@ -2336,13 +2327,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2336,13 +2327,11 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
case '\\': case '\\':
back_slash = true; back_slash = true;
cur++; cur++;
len++; continue;
break;
case '"': case '"':
double_quote = true; double_quote = true;
cur++; cur++;
len++;
break; break;
case '\0': case '\0':
...@@ -2353,7 +2342,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2353,7 +2342,6 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
default: default:
cur++; cur++;
len++;
} }
break; break;
...@@ -2362,24 +2350,30 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2362,24 +2350,30 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
} }
} }
if (start < cur) {
if (bufSize <= len + (cur - start)) {
bufSize *= 2;
value = realloc(value, bufSize);
}
memcpy(value + len, start, cur - start); // [start, cur)
len += cur - start;
start = cur;
}
if (kv_done == true) { if (kv_done == true) {
break; break;
} }
} }
if (len == 0 || ret != TSDB_CODE_SUCCESS) { if (len == 0 || ret != TSDB_CODE_SUCCESS) {
free(pKV->key); ret = TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
pKV->key = NULL; goto error;
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
value = calloc(len + 1, 1);
memcpy(value, start, len);
value[len] = '\0'; value[len] = '\0';
if (!convertSmlValueType(pKV, value, len, info, isTag)) { if (!convertSmlValueType(pKV, value, len, info, isTag)) {
tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type", tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type",
info->id, value); info->id, value);
free(value);
ret = TSDB_CODE_TSC_INVALID_VALUE; ret = TSDB_CODE_TSC_INVALID_VALUE;
goto error; goto error;
} }
...@@ -2389,7 +2383,8 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx, ...@@ -2389,7 +2383,8 @@ static int32_t parseSmlValue(TAOS_SML_KV *pKV, const char **idx,
return ret; return ret;
error: error:
//free previous alocated key field //free previous alocated buffer and key field
free(value);
free(pKV->key); free(pKV->key);
pKV->key = NULL; pKV->key = NULL;
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册