@@ -56,7 +56,7 @@ static gravity_file_t *gravity_ifile_new (gravity_vm *vm, FILE *f) {
5656
5757static bool internal_file_size (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
5858 // 1 parameter of type string is required
59- if (nargs != 2 && !VALUE_ISA_STRING (args [1 ])) {
59+ if (nargs != 2 || !VALUE_ISA_STRING (args [1 ])) {
6060 RETURN_ERROR ("A path parameter of type String is required." );
6161 }
6262
@@ -67,7 +67,7 @@ static bool internal_file_size (gravity_vm *vm, gravity_value_t *args, uint16_t
6767
6868static bool internal_file_exists (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
6969 // 1 parameter of type string is required
70- if (nargs != 2 && !VALUE_ISA_STRING (args [1 ])) {
70+ if (nargs != 2 || !VALUE_ISA_STRING (args [1 ])) {
7171 RETURN_ERROR ("A path parameter of type String is required." );
7272 }
7373
@@ -78,7 +78,7 @@ static bool internal_file_exists (gravity_vm *vm, gravity_value_t *args, uint16_
7878
7979static bool internal_file_delete (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
8080 // 1 parameter of type string is required
81- if (nargs != 2 && !VALUE_ISA_STRING (args [1 ])) {
81+ if (nargs != 2 || !VALUE_ISA_STRING (args [1 ])) {
8282 RETURN_ERROR ("A path parameter of type String is required." );
8383 }
8484
@@ -89,7 +89,7 @@ static bool internal_file_delete (gravity_vm *vm, gravity_value_t *args, uint16_
8989
9090static bool internal_file_read (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
9191 // 1 parameter of type string is required
92- if (nargs != 2 && !VALUE_ISA_STRING (args [1 ])) {
92+ if (nargs != 2 || !VALUE_ISA_STRING (args [1 ])) {
9393 RETURN_ERROR ("A path parameter of type String is required." );
9494 }
9595
@@ -106,7 +106,7 @@ static bool internal_file_read (gravity_vm *vm, gravity_value_t *args, uint16_t
106106
107107static bool internal_file_write (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
108108 // 2 parameters of type string are required
109- if (nargs != 3 && !VALUE_ISA_STRING (args [1 ]) && !VALUE_ISA_STRING (args [2 ])) {
109+ if (nargs != 3 || !VALUE_ISA_STRING (args [1 ]) || !VALUE_ISA_STRING (args [2 ])) {
110110 RETURN_ERROR ("A path parameter of type String and a String parameter are required." );
111111 }
112112
@@ -119,7 +119,7 @@ static bool internal_file_write (gravity_vm *vm, gravity_value_t *args, uint16_t
119119
120120static bool internal_file_buildpath (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
121121 // 2 parameters of type string are required
122- if (nargs != 3 && !VALUE_ISA_STRING (args [1 ]) && !VALUE_ISA_STRING (args [2 ])) {
122+ if (nargs != 3 || !VALUE_ISA_STRING (args [1 ]) || !VALUE_ISA_STRING (args [2 ])) {
123123 RETURN_ERROR ("A file and path parameters of type String are required." );
124124 }
125125
@@ -137,7 +137,7 @@ static bool internal_file_buildpath (gravity_vm *vm, gravity_value_t *args, uint
137137
138138static bool internal_file_is_directory (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
139139 // 1 parameter of type string is required
140- if (nargs != 2 && !VALUE_ISA_STRING (args [1 ])) {
140+ if (nargs != 2 || !VALUE_ISA_STRING (args [1 ])) {
141141 RETURN_ERROR ("A path parameter of type String is required." );
142142 }
143143
@@ -148,7 +148,7 @@ static bool internal_file_is_directory (gravity_vm *vm, gravity_value_t *args, u
148148
149149static bool internal_file_directory_create (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
150150 // 1 parameter of type string is required
151- if (nargs != 2 && !VALUE_ISA_STRING (args [1 ])) {
151+ if (nargs != 2 || !VALUE_ISA_STRING (args [1 ])) {
152152 RETURN_ERROR ("A path parameter of type String is required." );
153153 }
154154
@@ -218,12 +218,12 @@ static bool internal_file_directory_scan (gravity_vm *vm, gravity_value_t *args,
218218 // optional bool 2nd parameter
219219 int nindex = 2 ;
220220 bool recursive = true;
221- if (VALUE_ISA_BOOL (args [2 ])) {
221+ if (nargs > 2 && VALUE_ISA_BOOL (args [2 ])) {
222222 recursive = VALUE_AS_BOOL (args [2 ]);
223223 nindex = 3 ;
224224 }
225-
226- if (!VALUE_ISA_CLOSURE (args [nindex ])) {
225+
226+ if (nargs <= ( uint16_t ) nindex || !VALUE_ISA_CLOSURE (args [nindex ])) {
227227 RETURN_ERROR ("A closure parameter is required." );
228228 }
229229
@@ -280,7 +280,7 @@ static bool internal_file_iread (gravity_vm *vm, gravity_value_t *args, uint16_t
280280 // var data = file.read(N)
281281
282282 // 1 parameter of type int is required
283- if (nargs < 1 && (!VALUE_ISA_INT (args [1 ]) && !VALUE_ISA_STRING (args [1 ]))) {
283+ if (nargs < 2 || (!VALUE_ISA_INT (args [1 ]) && !VALUE_ISA_STRING (args [1 ]))) {
284284 RETURN_ERROR ("A parameter of type Int or String is required." );
285285 }
286286
@@ -344,8 +344,8 @@ static bool internal_file_iread (gravity_vm *vm, gravity_value_t *args, uint16_t
344344static bool internal_file_iwrite (gravity_vm * vm , gravity_value_t * args , uint16_t nargs , uint32_t rindex ) {
345345 // var written = file.write(data)
346346
347- // 1 parameter of type int is required
348- if (nargs < 1 && !VALUE_ISA_STRING (args [1 ])) {
347+ // 1 parameter of type string is required
348+ if (nargs < 2 || !VALUE_ISA_STRING (args [1 ])) {
349349 RETURN_ERROR ("A parameter of type String is required." );
350350 }
351351
@@ -360,7 +360,7 @@ static bool internal_file_iseek (gravity_vm *vm, gravity_value_t *args, uint16_t
360360 // var result = file.seek(offset, whence)
361361
362362 // 2 parameters of type int are required
363- if (nargs != 3 && !VALUE_ISA_INT (args [1 ]) && !VALUE_ISA_INT (args [2 ])) {
363+ if (nargs != 3 || !VALUE_ISA_INT (args [1 ]) || !VALUE_ISA_INT (args [2 ])) {
364364 RETURN_ERROR ("An offset parameter of type Int and a whence parameter of type Int are required." );
365365 }
366366
0 commit comments