Hello,

I'm working on modifying an postgresql extension called "cstore_fdw". My 
function is like:


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
static bool
ParsePeriod(const char *periodString, Period *result)
{
    bool isSuccess = true;
    char *dupPeriodForString;
    
    char delimiters[3][2] = { "(", ",", ")" };
    char **results[3] = {&(result->periodName), 
&(result->start_column_name), &(result->end_column_name)};
    
    dupPeriodForString = pstrdup(periodString); // !!!! pstrdup error !!!!

&nbsp; &nbsp; if (dupPeriodForString == NULL || strlen(dupPeriodForString) <= 0 
|| result == NULL)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; isSuccess = false;
&nbsp; &nbsp; }
&nbsp; &nbsp; 

&nbsp; &nbsp; for (int i = 0; i < 3; ++i)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; char *token = NULL;
&nbsp; &nbsp; &nbsp; &nbsp; Size len = 0;
&nbsp; &nbsp; &nbsp; &nbsp; int j;
&nbsp; &nbsp; &nbsp; &nbsp; if ( (token = strsep(&amp;dupPeriodForString, 
delimiters[i])) == NULL )
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isSuccess = false;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; // trim
&nbsp; &nbsp; &nbsp; &nbsp; len = strlen(token);
&nbsp; &nbsp; &nbsp; &nbsp; while(isspace(token[len - 1])) --len;
&nbsp; &nbsp; &nbsp; &nbsp; while(*token &amp;&amp; isspace(*token)) ++token, 
--len;
&nbsp; &nbsp; &nbsp; &nbsp; token = pnstrdup(token, len);

&nbsp; &nbsp; &nbsp; &nbsp; // lowercase
&nbsp; &nbsp; &nbsp; &nbsp; len = strlen(token);
&nbsp; &nbsp; &nbsp; &nbsp; for (j = 0; j < len; j++)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; token[j] = tolower(token[j]);
&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; *results[i] = token;
&nbsp; &nbsp; }
&nbsp; &nbsp; 
&nbsp; &nbsp; return isSuccess;
}
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;


pstrdup() will change source "system_time( stt , ett )" to "system_time( stt " 
and return&nbsp;"system_time( stt "&nbsp;when it is called 
in&nbsp;ValidateForeignTableOptions() and CStoreGetOptions(). But if I call it 
in somewhere else, it won't get wrong.


Here's my enviornment:
    postgresql: psql (PostgreSQL) 12.10 (Ubuntu 12.10-0ubuntu0.20.04.1) 
    compiler: clang version 10.0.0-4ubuntu1
    OS: WINDOWS sub linux GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64


How can I do to fix this problem?

Reply via email to