UDF compiled but fails to run "corrupt stack frame"

Extensibility
Enthusiast

UDF compiled but fails to run "corrupt stack frame"

Hi,

I was able to create UDF, following TD_GENERAL style. But it throws error when i try to run it with message "corrup stack frame". I have shared my code. This code is to remove all characters from a string. I am new to C, please let me know if you know where the issue is.

Thankyou.

Teradata function:

REPLACE FUNCTION SYSLIB.removechar(inputString VARCHAR(70))

RETURNS VARCHAR(70)

LANGUAGE C

NO SQL

SPECIFIC removechar

RETURNS NULL ON NULL INPUT

EXTERNAL NAME 'SS!removechar!c:\function\removechar.c'

PARAMETER STYLE TD_GENERAL;

C code:

#define SQL_TEXT Latin_Text

#include "sqltypes_td.h"

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

void removechar(VARCHAR_LATIN *inputString, VARCHAR_LATIN *result, char sqlstate[6])

{

int n, i , j;

n = strlen((char *) inputString);

*result = '\0';

for( i = 0; i < n; )

{

if( inputString[i] < '0' || inputString[i] > '9' )

{

for( j =  i; j < n; j++ )

{

inputString[j] = inputString[j+1];

}

n--;

}

else

i++;

}

inputString[i] = '\0';

(void) strcpy((char *) result, (char *) inputString);

}

3 REPLIES
Teradata Employee

Re: UDF compiled but fails to run "corrupt stack frame"

The inputString parameter should be referenced only, not modified.

Enthusiast

Re: UDF compiled but fails to run "corrupt stack frame"

Thankyou Fred

Enthusiast

Re: UDF compiled but fails to run "corrupt stack frame"

Just sharing final code in C

#define SQL_TEXT Latin_Text

#include "sqltypes_td.h"

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

void removechar(VARCHAR_LATIN *inputString, VARCHAR_LATIN *result, char sqlstate[6])

{

int n, i , j;

char *target_ptr;

target_ptr = result;

n = strlen((char *) inputString);

*result = '\0';

for( i = 0; i < n; i++)

{

if( inputString[i] >= 0x30 && inputString[i] <= 0x39 )

{

*(target_ptr++) = inputString[i];

}

}

*target_ptr = '\0';

}