diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index b7cc85908c425ed711121b91ccf0835d61a24cb9..da40a6c1567adfb44b1d3c28ae947be86dbc7d9e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7339,18 +7339,19 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { bool dbIncluded = false; SStrToken tmpToken = pAlterSQL->name; - tmpToken.z= strndup(pAlterSQL->name.z, pAlterSQL->name.n); + char* z0 = strndup(pAlterSQL->name.z, pAlterSQL->name.n); + tmpToken.z = z0; if (tscValidateName(&tmpToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) { - free(tmpToken.z); + free(z0); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } code = tscSetTableFullName(&pTableMetaInfo->name, &tmpToken, pSql, dbIncluded); if (code != TSDB_CODE_SUCCESS) { - free(tmpToken.z); + free(z0); return code; } - free(tmpToken.z); + free(z0); code = tscGetTableMeta(pSql, pTableMetaInfo); if (code != TSDB_CODE_SUCCESS) { diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 649f8fa5e9697eac76f4a97eb44d5b18e06924ec..7e08178c42cbb7e34a0aec340352916d874a7094 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -225,59 +225,66 @@ char *tstrstr(char *src, char *dst, bool ignoreInEsc) { } char* strtolower(char *dst, const char *src) { - if (src == NULL || dst == NULL) { - return dst; - } - char* const ret = dst; - while (*src) { - const char ch = *(src++); - *(dst++) = (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch; - - if (ch == '\'' || ch == '"') { - char prev = ch; - while (*src) { - const char next = *(src++); - *(dst++) = next; - if (prev != '\\' && next == ch) break; - prev = next; - } - } else if (ch == '`') { - while (*src) { - const char next = *(src++); - *(dst++) = next; - if (next == ch) break; + int esc = 0; + char quote = 0, *p = dst, c; + + assert(dst != NULL); + + for (c = *src++; c; c = *src++) { + if (esc) { + esc = 0; + } else if (quote) { + if (c == '\\') { + esc = 1; + } else if (c == quote) { + quote = 0; } + } else if (c >= 'A' && c <= 'Z') { + c -= 'A' - 'a'; + } else if (c == '\'' || c == '"') { + quote = c; } + *p++ = c; } - *(dst) = 0; - return ret; + + *p = 0; + return dst; } char* strntolower(char *dst, const char *src, int32_t n) { + int esc = 0, inEsc = 0; + char quote = 0, *p = dst, c; + assert(dst != NULL); - char* const end = dst + n; - while (dst != end) { - const char ch = *(src++); - *(dst++) = (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch; - - if (ch == '\'' || ch == '"') { - char prev = ch; - while (dst != end) { - const char next = *(src++); - *(dst++) = next; - if (prev != '\\' && next == ch) break; - prev = next; + if (n == 0) { + *p = 0; + return dst; + } + for (c = *src++; n-- > 0; c = *src++) { + if (esc) { + esc = 0; + } else if (quote) { + if (c == '\\') { + esc = 1; + } else if (c == quote) { + quote = 0; } - } else if (ch == '`') { - while (dst != end) { - const char next = *(src++); - *(dst++) = next; - if (next == ch) break; + } else if (inEsc) { + if (c == '`') { + inEsc = 0; } + } else if (c >= 'A' && c <= 'Z') { + c -= 'A' - 'a'; + } else if (inEsc == 0 && (c == '\'' || c == '"')) { + quote = c; + } else if (c == '`' && quote == 0) { + inEsc = 1; } + *p++ = c; } - *(dst) = 0; - return dst - n; + + *p = 0; + return dst; } char* strntolower_s(char *dst, const char *src, int32_t n) {