Failed [7502 : HY000] A system trap was caused by UDF/XSP/UDM TESTER."UDF call" for SIGSEGV

Database

Failed [7502 : HY000] A system trap was caused by UDF/XSP/UDM TESTER."UDF call" for SIGSEGV

I am getting following error when I am trying to compile my UDF

Failed [7502 : HY000] A system trap was caused by UDF/XSP/UDM TESTER.TESTER.UDACL_CONTRACT  for SIGSEGV

My Code:

#define byte unsigned char

#define boolean int

#define false 0

#define true 1

#define OK 0

#define SQL_TEXT Latin_Text

#define _CRT_SECURE_NO_DEPRECATE

#include <limits.h>

#include <stddef.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sqltypes_td.h>

#define FALSE 0

#define TRUE 1

#define MAX_KEY_LEN 100

void udacl_contract (

INTEGER *result,

int *indicator_Result,

char sqlstate[6],

SQL_TEXT extname[129],

SQL_TEXT specific_name[129],

SQL_TEXT error_message[257])

{

FNC_TblOpColumnDef_t *Output_columns; // column definition for output stream

FNC_TblOpColumnDef_t *Input_columns; // column definition for input stream

int colcount; // number of columns in output

int i;

char key[MAX_KEY_LEN]; // key in custom clause

int keylen; // actual key length

Key_info_t valuesKEY; // values associated with key SUM

// Key_info_t valuesAVG; // values associated with key AVG

int *index; // indices of columns in input stream to

// apply aggregates

boolean_t found;

char colname[FNC_MAXNAMELEN_EON];

/* -------- process custom clause information -------- */

FNC_TblOpGetCustomKeyInfoOf("KEY", &valuesKEY);

valuesKEY.values_r = FNC_malloc( sizeof(Values_t) * valuesKEY.numOfVal );

// compute number of columns in output stream

colcount = FNC_TblOpGetColCount(0, 'W');

FNC_TblOpGetCustomValuesOf(&valuesKEY);

// Allocate memory for the output columns

Output_columns = FNC_malloc ( TblOpSIZECOLDEF(colcount) );

// initialize output columns

TblOpINITCOLDEF(Output_columns, colcount);

// Allocate memory for input columns

Input_columns = FNC_malloc ( TblOpSIZECOLDEF( FNC_TblOpGetColCount(0, 'R') ) );

// initialize input columns

TblOpINITCOLDEF( Input_columns, FNC_TblOpGetColCount(0, 'R') );

FNC_TblOpGetColDef(0, 'R', Input_columns);

strncpy( Output_columns->column_types[i].column, strncat(colname, (char *) valuesKEY.values_r[i].value, valuesKEY.values_r[i].valueLen),FNC_MAXNAMELEN_EON);

Output_columns->column_types[i].datatype = REAL_DT;

Output_columns->column_types[i].bytesize = SIZEOF_FLOAT;

FNC_TblOpSetOutputColDef(0, Output_columns);

// pass indices to table operator in the contract context

FNC_TblOpSetContractDef(index, sizeof(int) * colcount );

// release memory

*result = Output_columns->num_columns;

FNC_free(Output_columns);

FNC_free(Input_columns);

FNC_free(valuesKEY.values_r);

//FNC_free(valuesAVG.values_r);

FNC_free(index);

}

void udacl ()

{

int null_ind, length;

FNC_TblOpHandle_t *Input_handle; // input stream handle

FNC_TblOpHandle_t *Output_handle; // output stream handle

FNC_TblOpColumnDef_t *Input_columns; // input stream column definitions

FNC_TblOpColumnDef_t *Output_columns; // output stream column definitions

double *aggregates; // aggregates computation

int *index; // columns index in input stream of aggregates

int rowcount = 0 ; // number of rows

int i, j, k, tmp;

BYTE *ptr;

int colcount;

/* Allocate memory for the output columns */

colcount = FNC_TblOpGetColCount(0, 'W');

/* FNC_TblOpGetColCount This function retrieves the number of columns in the stream*/

Output_columns = FNC_malloc ( TblOpSIZECOLDEF( colcount ) );

/* TblOpSIZECOLDEF = sizeof(parm_tx)*colcount + 2*sizeof(int) */

/* initialize output columns */

TblOpINITCOLDEF(Output_columns, colcount);

/* TblOpINITCOLDEF = if (coldef != NULL) {coldef->num_columns = colcount; coldef->length = sizeof(parm_tx)*colcount; memset(coldef->column_types,0,coldef->length);} */

FNC_TblOpGetColDef(0, 'W', Output_columns);

/* Allocate memory for input columns */

Input_columns = FNC_malloc ( TblOpSIZECOLDEF( FNC_TblOpGetColCount(0, 'R') ) );

/* initialize input columns */

TblOpINITCOLDEF( Input_columns, FNC_TblOpGetColCount(0, 'R') );

FNC_TblOpGetColDef(0, 'R', Input_columns);

/* initialize aggregated values for group */

aggregates = FNC_malloc( sizeof(float) * Output_columns->num_columns );

for (i=0; i<Output_columns->num_columns; i++)

{

aggregates[i] = 0;

}

/* get indices from contract context */

index = FNC_malloc( FNC_TblOpGetContractLength() );

FNC_TblOpGetContractDef(index, FNC_TblOpGetContractLength(), &tmp );

/* FNC_TblOpGetContractDef Retrieve the contract context */

/* FNC_TblOpGetContractLength Retrieve the length of contract context.*/

/* The basic row iterator would be structured as follows */

Input_handle = FNC_TblOpOpen(0, 'R', TBLOP_NOOPTIONS); // start iterator for input stream

Output_handle = FNC_TblOpOpen(0, 'W', TBLOP_NOOPTIONS); // start iterator for output stream

/* FNC_TblOpRead = return SUCCESS,  EOF (no more data), ABORT or ERROR. */

while ( FNC_TblOpRead(Input_handle) == TBLOP_SUCCESS)

{

rowcount++;

// update aggregate for each column

for (i=0; i<Output_columns->num_columns; i++)

{

/* increment aggregated values */

FNC_TblOpGetAttributeByNdx(Input_handle, index[i], (void **) &ptr, &null_ind,

&length);

switch (Input_columns->column_types[index[i]].datatype)

{

case BYTEINT_DT: aggregates[i] += *((signed char *) ptr); break;

case SMALLINT_DT: aggregates[i] += *((short *) ptr); break;

case INTEGER_DT: aggregates[i] += *((int *) ptr); break;

case BIGINT_DT: aggregates[i] += *((long long *) ptr); break;

}

}

}

/* set output values */

for (i=0; i<Output_columns->num_columns; i++)

{

if (Output_columns->column_types[i].column[0] == 'A')

{

if (rowcount != 0)

{

aggregates[i] = aggregates[i] / ((double) rowcount);

}

}

FNC_TblOpBindAttributeByNdx(Output_handle, i, aggregates+i, 0, sizeof(double));

}

/* write output row */

FNC_TblOpWrite(Output_handle);

FNC_TblOpClose(Input_handle);

FNC_TblOpClose(Output_handle);

// release memory

FNC_free(Output_columns);

FNC_free(Input_columns);

FNC_free(aggregates);

FNC_free(index);

}

Can you please tell me what is causing this error?

Thanks in advace