Subject odd CSTRING in UDF
Author Rick Roen
FB 1.5

I have a UDF declared like this:

DECLARE EXTERNAL FUNCTION F_ENCODE_HTML
CSTRING(4096)
RETURNS CSTRING(4096) FREE_IT
ENTRY_POINT 'Str_EncodeHTML' MODULE_NAME 'Primavera_UDF';

Its function is to escape protected HTML chars like "&" or "<".

If I use it like this:

**********
Select F_ENCODE_HTML( Substring(<some memo field> from 1 for 4096)
from <some table>

***********

it works ok until I get to a memo that contains more than 256
characters where it fails with "...string overflow". This happens
even with the memo is well below 4096 but greater than 256.

if I change the substring part to "from 1 to 256" it runs ok,
but "from 1 to 257" fails.

Then I read something about how another substring UDF function did
not work properly until the max size of CSTRING was used in the
UDF. So I changed the definition to:

DECLARE EXTERNAL FUNCTION F_ENCODE_HTML
CSTRING(32767)
RETURNS CSTRING(32767) FREE_IT
ENTRY_POINT 'Str_EncodeHTML' MODULE_NAME 'Primavera_UDF';

and it works with memos larger than 256.

Can anyone explain this?

Rick