File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1452,20 +1452,18 @@ f_readfile(typval_T *argvars, typval_T *rettv)
14521452 maxline = (long )tv_get_number (& argvars [2 ]);
14531453 }
14541454
1455- if (blob )
1456- {
1457- if (rettv_blob_alloc (rettv ) == FAIL )
1458- return ;
1459- }
1460- else
1461- {
1462- if (rettv_list_alloc (rettv ) == FAIL )
1463- return ;
1464- }
1455+ if ((blob ? rettv_blob_alloc (rettv ) : rettv_list_alloc (rettv )) == FAIL )
1456+ return ;
14651457
14661458 // Always open the file in binary mode, library functions have a mind of
14671459 // their own about CR-LF conversion.
14681460 fname = tv_get_string (& argvars [0 ]);
1461+
1462+ if (mch_isdir (fname ))
1463+ {
1464+ semsg (_ (e_isadir2 ), fname );
1465+ return ;
1466+ }
14691467 if (* fname == NUL || (fd = mch_fopen ((char * )fname , READBIN )) == NULL )
14701468 {
14711469 semsg (_ (e_notopen ), * fname == NUL ? (char_u * )_ ("<empty>" ) : fname );
@@ -1476,8 +1474,10 @@ f_readfile(typval_T *argvars, typval_T *rettv)
14761474 {
14771475 if (read_blob (fd , rettv -> vval .v_blob ) == FAIL )
14781476 {
1479- emsg ("cannot read file" );
1477+ semsg (_ (e_notread ), fname );
1478+ // An empty blob is returned on error.
14801479 blob_free (rettv -> vval .v_blob );
1480+ rettv -> vval .v_blob = NULL ;
14811481 }
14821482 fclose (fd );
14831483 return ;
Original file line number Diff line number Diff line change @@ -257,6 +257,9 @@ func Test_blob_read_write()
257257 let br = readfile (' Xblob' , ' B' )
258258 call assert_equal (b , br )
259259 call delete (' Xblob' )
260+
261+ " This was crashing when calling readfile() with a directory.
262+ call assert_fails (" call readfile('.', 'B')" , ' E17: "." is a directory' )
260263endfunc
261264
262265" filter() item in blob
Original file line number Diff line number Diff line change @@ -738,6 +738,8 @@ static char *(features[]) =
738738
739739static int included_patches [] =
740740{ /* Add new patch number below this line */
741+ /**/
742+ 521 ,
741743/**/
742744 520 ,
743745/**/
You can’t perform that action at this time.
0 commit comments