File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -370,7 +370,7 @@ REBINT Mode_Syms[] = {
370
370
371
371
/***********************************************************************
372
372
**
373
- */ static REBCNT Set_Length (const REBVAL * ds , const REBREQ * file , const REBCNT arg )
373
+ */ static REBCNT Set_Length (const REBVAL * ds , REBREQ * file , const REBCNT arg )
374
374
/*
375
375
** Computes the length of data based on the argument number
376
376
** provided for the ARG_*_PART stack value (which, when there,
@@ -395,6 +395,16 @@ REBINT Mode_Syms[] = {
395
395
396
396
// Limit size of requested read:
397
397
cnt = VAL_INT64 (D_ARG (arg + 1 ));
398
+ if (cnt < 0 ) {
399
+ cnt = - cnt ;
400
+ if (cnt > file -> file .index ) {
401
+ Trap1 (RE_OUT_OF_RANGE , D_ARG (arg + 1 ));
402
+ //cnt = file->file.index;
403
+ }
404
+ file -> file .index -= cnt ;
405
+ len += cnt ;
406
+ SET_FLAG (file -> modes , RFM_RESEEK );
407
+ }
398
408
if (cnt > len ) return (REBCNT )len ;
399
409
return (REBCNT )cnt ;
400
410
}
Original file line number Diff line number Diff line change @@ -331,7 +331,22 @@ if system/platform = 'Windows [
331
331
port? close p
332
332
not error? try [delete %file-552 ]
333
333
]
334
-
334
+
335
+ --test-- "read/part"
336
+ ;@@ https://github.com/Oldes/Rebol-issues/issues/2505
337
+ --assert all [
338
+ file? write %12345 "12345"
339
+ port? p: open /read/seek %12345
340
+ #{ 31 } == read /part p 1 ; advances!
341
+ #{ 3233 } == read /part p 2
342
+ #{ 3132 } == read /part head p 2
343
+ #{} == read /part tail p 2
344
+ #{ 35 } == read /part tail p -1 ;- no crash!
345
+ #{ 3435 } == read /part tail p -2
346
+ all [error? e: try [read /part p -20 ] e/id = 'out-of-range]
347
+ port? close p
348
+ not error? try [delete %12345 ]
349
+ ]
335
350
336
351
--test-- "CLEAR file port"
337
352
;@@ https://github.com/Oldes/Rebol-issues/issues/812
You can’t perform that action at this time.
0 commit comments