pull/6763/head^2
Gokhan Gulbiz 2023-03-23 10:20:50 +03:00
parent 508ee987e6
commit b86f2b5607
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
1 changed files with 30 additions and 28 deletions

View File

@ -681,42 +681,43 @@ MultiTenantMonitorshmemSize(void)
static char * static char *
ExtractTopComment(const char *inputString) ExtractTopComment(const char *inputString)
{ {
int commentCharsLength = 2; int commentCharsLength = 2;
int inputStringLen = strlen(inputString); int inputStringLen = strlen(inputString);
if (inputStringLen < commentCharsLength) if (inputStringLen < commentCharsLength)
{ {
return NULL; return NULL;
} }
const char *commentStartChars = "/*"; const char *commentStartChars = "/*";
const char *commentEndChars = "*/"; const char *commentEndChars = "*/";
/* If query doesn't start with a comment, return NULL */ /* If query doesn't start with a comment, return NULL */
if (strstr(inputString, commentStartChars) != inputString) if (strstr(inputString, commentStartChars) != inputString)
{ {
return NULL; return NULL;
} }
StringInfo commentData = makeStringInfo(); StringInfo commentData = makeStringInfo();
/* Skip the comment start characters */ /* Skip the comment start characters */
const char *commentStart = inputString + commentCharsLength; const char *commentStart = inputString + commentCharsLength;
/* Find the first comment end character */ /* Find the first comment end character */
const char *commentEnd = strstr(commentStart, commentEndChars); const char *commentEnd = strstr(commentStart, commentEndChars);
if (commentEnd == NULL) if (commentEnd == NULL)
{ {
return NULL; return NULL;
} }
/* Append the comment to the StringInfo buffer */ /* Append the comment to the StringInfo buffer */
int commentLength = commentEnd - commentStart; int commentLength = commentEnd - commentStart;
appendStringInfo(commentData, "%.*s", commentLength, commentStart); appendStringInfo(commentData, "%.*s", commentLength, commentStart);
/* Return the extracted comment */ /* Return the extracted comment */
return commentData->data; return commentData->data;
} }
/* EscapeCommentChars adds a backslash before each occurrence of '*' or '/' in the input string */ /* EscapeCommentChars adds a backslash before each occurrence of '*' or '/' in the input string */
static char * static char *
EscapeCommentChars(const char *str) EscapeCommentChars(const char *str)
@ -733,11 +734,12 @@ EscapeCommentChars(const char *str)
} }
appendStringInfoChar(escapedString, str[originalStringIndex]); appendStringInfoChar(escapedString, str[originalStringIndex]);
} }
return escapedString->data; return escapedString->data;
} }
/* UnescapeCommentChars removes the backslash that precedes '*' or '/' in the input string. */ /* UnescapeCommentChars removes the backslash that precedes '*' or '/' in the input string. */
static char * static char *
UnescapeCommentChars(const char *str) UnescapeCommentChars(const char *str)