Subject | Re: [firebird-support] UDF or/and maybe Charset problem |
---|---|
Author | Nagy Szilveszter |
Post date | 2017-08-24T10:00:59Z |
No, it has value of TRX12270
On Thursday, August 24, 2017, 12:56:09 PM GMT+3, Antônio Gomes acgomes2001@... [firebird-support] <firebird-support@yahoogroups.com> wrote:
there no a null string?
De: "Nagy Szilveszter nagy_szilveszter@... [firebird-support]" <firebird-support@yahoogroups.com>
Para: Firebird-support <firebird-support@yahoogroups.com>
Enviadas: Quinta-feira, 24 de Agosto de 2017 6:41
Assunto: [firebird-support] UDF or/and maybe Charset problem
Hi,
i have an UDF function that runs perfectly on Linux 64 bit systems. I wanted to port it to Windows 32 bit, but i'm having problems there.
The UDF was written in C (not C++), compiled on Linux with gcc, everything works fine.
I compiled the same C file on Windows with MinGW Developer Studio (using MinGW compiler)
Here is the function with problems (the functions returns the same string but deletes every non alphanumerical character):
char *strpeel(char *str){
unsigned int i = 0, j = 0;
char *out;
str = strupr(str);
out = (char*)calloc(strlen(str), sizeof(char));
for (i=0; i<strlen(str); i++){
if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= '0' && str[i] <= '9')) {
out[j++] = str[i];
}
}
char * result;
result = (char*)calloc(j, sizeof(char));
strcpy(result, out);
return result;
}
unsigned int i = 0, j = 0;
char *out;
str = strupr(str);
out = (char*)calloc(strlen(str), sizeof(char));
for (i=0; i<strlen(str); i++){
if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= '0' && str[i] <= '9')) {
out[j++] = str[i];
}
}
char * result;
result = (char*)calloc(j, sizeof(char));
strcpy(result, out);
return result;
}
This is the declaration of UDF in Firebird:
DECLARE EXTERNAL FUNCTION STRPEEL
CSTRING(255)
RETURNS CSTRING(255)
ENTRY_POINT 'strpeel' MODULE_NAME 'utils-udf';
CSTRING(255)
RETURNS CSTRING(255)
ENTRY_POINT 'strpeel' MODULE_NAME 'utils-udf';
When i test this function it runs correctly:
select strpeel('ABC - 123') from rdb$database ----> returns: 'ABC123'
But when i run it on my PRODUCTS table, there are some rows where this function crashes:
select product_code, strpeel(product_code) from products
The field PRODUCT_CODE is Varchar(30) charset UTF8 collate UTF8
At row 51 the string must have some invisible characters that makes the UDF to crash.
The firebird.log says:
The user defined function: STRPEEL
referencing entrypoint: strpeel
in module: utils-udf
caused the fatal exception: Access violation.
The code attempted to access a virtual
address without privilege to do so.
This exception will cause the Firebird server
to terminate abnormally.
Shutting down the server with 2 active connection(s) to 2 database(s), 0 active service(s)
Firebird shutdown is still in progress after the specified timeout
Operating system call ReleaseSemaphore failed. Error code 6
Operating system call ReleaseSemaphore failed. Error code 6
referencing entrypoint: strpeel
in module: utils-udf
caused the fatal exception: Access violation.
The code attempted to access a virtual
address without privilege to do so.
This exception will cause the Firebird server
to terminate abnormally.
Shutting down the server with 2 active connection(s) to 2 database(s), 0 active service(s)
Firebird shutdown is still in progress after the specified timeout
Operating system call ReleaseSemaphore failed. Error code 6
Operating system call ReleaseSemaphore failed. Error code 6
That code in that line is TRX12270
If i run select strpeel('TRX12270') from rdb$database - it works fine
If i copy that string from table and replace the above string then it crashes again. So there must be something wrong in that field.
Also if i edit the table and rewrite the code then it works fine.
I also checked the characters with ASCII_VAL but i can see nothing strange.
As the UDF, there are 2 memory allocations for strings and no freeing it, neither FREE_IT was used. I dont know if this is a problem since other strings work well with this UDF.
Please help me detect and correct this issue!
Thank you!