Re: Returning non-terminated string in ECPG Informix-compatible function - Mailing list pgsql-hackers

From Oleg Tselebrovskiy
Subject Re: Returning non-terminated string in ECPG Informix-compatible function
Date
Msg-id 4ab77531d15e9234ea4615dd8501078d@postgrespro.ru
Whole thread Raw
In response to Re: Returning non-terminated string in ECPG Informix-compatible function  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
Responses Re: Returning non-terminated string in ECPG Informix-compatible function
List pgsql-hackers
Here's the code for bug reproduction:
#include <stdio.h>
#include <stdlib.h>

EXEC SQL INCLUDE pgtypes_interval.h;
EXEC SQL INCLUDE ecpg_informix.h;

EXEC SQL BEGIN DECLARE SECTION;
    char dirty_str[100] = "aaaaaaaaa_bbbbbbbb_ccccccccc_ddddddddd_";
    interval *interval_ptr;
EXEC SQL END DECLARE SECTION;

int main()
{
    interval_ptr = (interval *) malloc(sizeof(interval));
    interval_ptr->time = 100000000;
    interval_ptr->month = 240;

    printf("dirty_str contents before intoasc: %s\n", dirty_str);
    intoasc(interval_ptr, dirty_str);
    printf("dirty_str contents after intoasc: %s\n", dirty_str);
    return 0;
}

And here's the output:

dirty_str contents before intoasc: 
aaaaaaaaa_bbbbbbbb_ccccccccc_ddddddddd_
dirty_str contents after intoasc: @ 20 years 1 min 40 
secscccc_ddddddddd_

I compiled it with following commands (provided for quicker 
reproduction):
/path/to/pgsql/bin/ecpg informix_bug_example.pgc
gcc -I/path/to/pgsql/include -c informix_bug_example.c
gcc -o informix_bug_example informix_bug_example.o -L/path/to/pgsql/lib 
-lecpg -lecpg_compat

I've also found at least one project that uses intoasc() in it - 
https://github.com/credativ/informix_fdw/

Oleg Tselebrovskiy, Postgres Pro



pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: MERGE ... RETURNING
Next
From: David Rowley
Date:
Subject: Re: Some revises in adding sorting path