commit fa21808ee837ae75aa11594b38695b422fe272dd
Author: Takuji Tanaka <ttk@t-lab.opal.ne.jp>
Date:   Sun Sep 16 05:36:36 2018 +0000

    upbibtex: Fix bug of substring$ (T. Sakai)
    
    git-svn-id: svn://tug.org/texlive/trunk@48676 c570f23f-e606-0410-a88d-b1316a301751

---
 texk/web2c/ptexdir/kanji.h      |    2 -
 texk/web2c/uptexdir/ChangeLog   |    7 +++++
 texk/web2c/uptexdir/upbibtex.ch |   48 +++++++++-------------------------------
 3 files changed, 19 insertions(+), 38 deletions(-)

--- texlive-bin.orig/texk/web2c/ptexdir/kanji.h
+++ texlive-bin/texk/web2c/ptexdir/kanji.h
@@ -28,7 +28,7 @@
 #define Hi(x) (((x) >> 8) & 0xff)
 #define Lo(x) ((x) & 0xff)
 
-extern int check_kanji (integer c);
+extern boolean check_kanji (integer c);
 #define checkkanji check_kanji
 extern boolean is_char_ascii (integer c);
 #define ischarascii is_char_ascii
--- texlive-bin.orig/texk/web2c/uptexdir/ChangeLog
+++ texlive-bin/texk/web2c/uptexdir/ChangeLog
@@ -1,3 +1,10 @@
+2018-09-16  TANAKA Takuji  <ttk@t-lab.opal.ne.jp>
+
+	* upbibtex.ch: Fix bug of substring$
+	from Takashi Sakai:
+	https://github.com/texjporg/tex-jp-build/issues/64
+	https://github.com/texjporg/tex-jp-build/pull/66
+
 2018-09-03  Hironobu Yamashita  <h.y.acetaminophen@gmail.com>
 
 	* gkhuge.test: Export TEXMFCNF beforehand, instead of setting
--- texlive-bin.orig/texk/web2c/uptexdir/upbibtex.ch
+++ texlive-bin/texk/web2c/uptexdir/upbibtex.ch
@@ -258,35 +258,18 @@ end;
 @y
 { |2..4| bytes Kanji code break check }
 tps:=str_start[pop_lit3];
-while (tps < sp_ptr) do begin
-    tps := tps + multibytelen(str_pool[tps])
-end;
 tpe:=tps;
-while (tpe < sp_end) do begin
-    tpe := tpe + multibytelen(str_pool[tpe])
-end;
-if tps<>sp_ptr then begin
-    if (is_internalUPTEX) then begin
-        if tps>str_start[pop_lit3]
-        then while (multibytelen(str_pool[sp_ptr])<0) do decr(sp_ptr)
-        else while (multibytelen(str_pool[sp_ptr])<0) do incr(sp_ptr)
-    end else begin
-        if tps>str_start[pop_lit3]
-        then decr(sp_ptr)
-        else incr(sp_ptr)
-    end;
-end;
-if tpe<>sp_end then begin
-    if (is_internalUPTEX) then begin
-        if tpe<str_start[pop_lit3+1]
-        then while (multibytelen(str_pool[sp_end])<0) do incr(sp_end)
-        else while (multibytelen(str_pool[sp_end])<0) do decr(sp_end)
-    end else begin
-        if tpe<str_start[pop_lit3+1]
-        then incr(sp_end)
-        else decr(sp_end)
-    end;
+while tpe < str_start[pop_lit3+1] do begin
+    if multibytelen(str_pool[tpe])<0
+        or (str_start[pop_lit3+1] < tpe+multibytelen(str_pool[tpe])) then
+        break;
+    tpe := tpe + multibytelen(str_pool[tpe]);
+    if tpe<=sp_ptr then
+        tps := tpe;
+    if sp_end<=tpe then break;
 end;
+sp_ptr := tps;
+sp_end := tpe;
 @z
 
 @x
@@ -299,16 +282,7 @@ end;
          end;
 @y
     append_char (str_pool[sp_ptr]);
-    if multibytelen(str_pool[sp_ptr]) > 1 then
-        append_char (str_pool[sp_ptr+1]);
-    if multibytelen(str_pool[sp_ptr]) > 2 then
-        append_char (str_pool[sp_ptr+2]);
-    if multibytelen(str_pool[sp_ptr]) > 3 then
-        append_char (str_pool[sp_ptr+3]);
-    if multibytelen(str_pool[sp_ptr]) > 0 then
-        sp_ptr := sp_ptr + multibytelen(str_pool[sp_ptr])
-    else
-        incr(sp_ptr);
+    incr(sp_ptr);
 @z
 
 @x
