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;
}




This is the declaration of UDF in Firebird:
DECLARE EXTERNAL FUNCTION STRPEEL
    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




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!
























  • [firebird-s... Nagy Szilveszter nagy_szilvesz...@yahoo.com [firebird-support]
    • Re: [f... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]
      • RE... Rudi Feijó rudi.fe...@multidadosti.com.br [firebird-support]
        • ... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]
    • Re: [f... Antônio Gomes acgomes2...@yahoo.com.br [firebird-support]
      • Re... Nagy Szilveszter nagy_szilvesz...@yahoo.com [firebird-support]
        • ... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]

Reply via email to