@@ -699,7 +699,7 @@ private static void bm_init_skip(int[] skip, byte[] pat, int patPtr, int m) {
699699 skip [c ] = m ;
700700 }
701701 while ((--m ) > 0 ) {
702- skip [pat [patPtr ++]] = m ;
702+ skip [Byte . toUnsignedInt ( pat [patPtr ++]) ] = m ;
703703 }
704704 }
705705
@@ -716,7 +716,7 @@ private static int bm_search(byte[] little, int lstart, int llen, byte[] big, in
716716 j --;
717717 }
718718 if (j < 0 ) return k + 1 ;
719- i += skip [big [i + bstart ] & 0xFF ];
719+ i += skip [Byte . toUnsignedInt ( big [i + bstart ]) ];
720720 }
721721 return -1 ;
722722 }
@@ -762,9 +762,10 @@ public IRubyObject gets(ThreadContext context, IRubyObject[] args) {
762762 }
763763
764764 private static final Getline .Callback <StringIO , IRubyObject > GETLINE = (context , self , rs , limit , chomp , block ) -> {
765- if ( self .isEndOfString ()) return context . nil ;
765+ self .checkReadable () ;
766766
767767 if (limit == 0 ) {
768+ if (self .ptr .string == null ) return context .nil ;
768769 return RubyString .newEmptyString (context .runtime , self .getEncoding ());
769770 }
770771
@@ -913,7 +914,7 @@ private IRubyObject getline(ThreadContext context, final IRubyObject rs, int lim
913914 p = rsByteList .getBegin ();
914915 bm_init_skip (skip , rsBytes , p , n );
915916 if ((pos2 = bm_search (rsBytes , p , n , stringBytes , s , e - s , skip )) >= 0 ) {
916- e = s + pos2 + n ;
917+ e = s + pos2 + ( chomp ? 0 : n ) ;
917918 }
918919 }
919920 }
0 commit comments