#56 UDF: Missing check for number of parameters

unclassified
pending
nobody
None
3
2014-07-28
2014-01-02
No

There is currently no check for user-defined functions comparing the number of parameters.
This results in SEGFAULTs if the UDF is called with too less params and can lead to confusion if the UDF is not called correctly (=the programmer expects the UDF to take care of all params he provided).

If the FUNCTION-ID is part of the same compilation group we should be able to add a compiler message like we have for intrinsic functions.
Patch for testing this:

Index: syn_misc.at
===================================================================
--- syn_misc.at (Revision 142)
+++ syn_misc.at (Working Copy)
@@ -156,3 +156,40 @@
 AT_CHECK([$COMPILE_ONLY prog.cob], [0])

 AT_CLEANUP
+
+AT_SETUP([User-Defined FUNCTION with wrong number of parameter])
+AT_KEYWORDS([misc functions])
+
+AT_DATA([prog.cob], [
+       IDENTIFICATION   DIVISION.
+       PROGRAM-ID.      prog.
+       REPOSITORY.
+           FUNCTION     WITHPAR.
+       DATA             DIVISION.
+       WORKING-STORAGE  SECTION.
+       01 DEST          PIC 9.
+       PROCEDURE        DIVISION.
+           MOVE FUNCTION WITHPAR(1, 2) TO DEST.
+           MOVE FUNCTION WITHPAR(1) TO DEST.
+           MOVE FUNCTION WITHPAR TO DEST.
+           STOP RUN.
+       END PROGRAM prog.
+
+       IDENTIFICATION   DIVISION.
+       FUNCTION-ID.     WITHPAR.
+       DATA             DIVISION.
+       LINKAGE          SECTION.
+       01 PAR-IN        PIC 9.
+       01 PAR-OUT       PIC 9.
+       PROCEDURE DIVISION USING PAR-IN RETURNING PAR-OUT.
+           ADD 1 TO PAR-IN GIVING PAR-OUT END-ADD.
+           GOBACK.
+       END FUNCTION WITHPAR.
+])
+
+AT_CHECK([$COMPILE_ONLY prog.cob], [1], ,
+[prog.cob: 10: Error: FUNCTION 'WITHPAR' has wrong number of arguments
+prog.cob: 12: Error: FUNCTION 'WITHPAR' has wrong number of arguments
+])
+
+AT_CLEANUP

For the case where the UDF is not part of the compilation group we may add a check for the parameter count to UDF loading (the generated function itself).

Simon

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks