Function call by reference

ta5
Member Posts: 1,164
Hi
I have a function "myFunc" which takes 1 parameter (Text,5) by reference. When this function is called with a parameter exceeding the length of 5 I would expect an error (overflow). This does not happen.
Is this a kind of a bug or is this by design? Is it safe to call the function without regarding the length of the parameter?
Many Thanks
Thomas
I have a function "myFunc" which takes 1 parameter (Text,5) by reference. When this function is called with a parameter exceeding the length of 5 I would expect an error (overflow). This does not happen.
Is this a kind of a bug or is this by design? Is it safe to call the function without regarding the length of the parameter?
Many Thanks
Thomas
0
Comments
-
Which version you are using?
Commonly there is error "The length of the source exceeds the size of the destination buffer."
But only if the Value is longer, not the data type...0 -
Hi
I'm using Version 3.7
I also know the message "The length of the source exceeds the size of the destination buffer." , but I can't reproduce this message. What's the difference between this message and the message "Overflow"?
Thomas0 -
Sorry, I made some small test (function with one param and passing longer string) -
It seems, that the error about buffer is when size of parameters is longer than some stack size...
If I pass only longer string, there was Overflow error.
Do not forget, that you can have only 20 parameters in one function and may be there is some limit for size of all passed values (stack size)...0 -
I conducted also a few more tests.
It seems, that the "Buffer" error is produced when using Text Constants; the "Overflow" error is produced when using Text Variables.
Anyway, do you have experiences with functions calls by ref (using longer parameters than defined)?
Regards
Thomas0 -
I tested it, yes, it seems, that if you pass param by Ref, the local variable have same size as the passed... no truncate, no overflow, only if you assign bigger value than passed variable size...0
-
Thank you.
I dont understand this "only if you assign bigger value than passed variable size..."0 -
I have Text10 : text[10] F(Text10); //call the function Function F(Var Param:Text[1]) begin Param := '1234567890A'; end;
there will be error, but when I assign only '1234567890' it will be ok (the Param is Text[1], but it takes it as Text[10]);0 -
Thank you, I got it now
Do you think it's save to use longer parameters than defined? Anyway, I think its quite dangerous, because no error is produced.
Thomas0 -
I think, that you must think, that the parameter is only pointer, and the text length is only hint, but not limit... if it will check for the limit of the param, you can have problems, because you can write to memory without limit...
example:Var Text1 : text[1] begin F(Text1); end; function F(var Param: text [10]) begin Param := '1234567890'; end;
In this case, if the C/SIDE will check for the limit of the parameter type, it will write outside of the passed variable... Param is only pointer to the Text1 variable... C/SIDE correctly test for the limit of Text1...
In this way, it is first example of dynamic variable in C/AL code...0 -
I guess, things like this could be the reason for some of the mysterious errors "error xy in module xy".
Its ok for me now, thank you again for your input.
Thomas0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions