Package: texlive-bin / 2016.20160513.41080.dfsg-2+deb9u1

upstream-svn41418-pdftex-match-fix Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
fix pdftex match segfaults
---
 texk/web2c/pdftexdir/ChangeLog |   14 ++++++++++++++
 texk/web2c/pdftexdir/NEWS      |    5 ++++-
 texk/web2c/pdftexdir/utils.c   |   30 +++++++++++++++++++++++-------
 3 files changed, 41 insertions(+), 8 deletions(-)

--- texlive-bin.orig/texk/web2c/pdftexdir/ChangeLog
+++ texlive-bin/texk/web2c/pdftexdir/ChangeLog
@@ -1,3 +1,17 @@
+2016-06-12  Karl Berry  <karl@freefriends.org>
+        and Akira Kakuto  <kakuto@fuk.kindai.ac.jp>
+
+	* utils.c (last_match_succeeded): new static boolean.
+	(matchstrings): set it.
+	(getmatch): use it, plus check for non-NULL match_string sooner,
+	plus check that rm_eo >= rm_so.
+	Original bug report from David Carlisle,
+        http://tug.org/pipermail/tex-live/2016-June/038664.html
+
+2016-05-20  Karl Berry  <karl@tug.org>
+
+	* TeX Live 2016 release.
+
 2016-04-06  Karl Berry  <karl@tug.org>
 
 	* pdftexextra.h (COPYRIGHT_HOLDER): don't specifically mention peb
--- texlive-bin.orig/texk/web2c/pdftexdir/NEWS
+++ texlive-bin/texk/web2c/pdftexdir/NEWS
@@ -1,8 +1,11 @@
 - changes:
   - rename envvar SOURCE_DATE_EPOCH_TEX_PRIMITIVES to FORCE_SOURCE_DATE;
     no changes in functionality.
+
+- bugfixes:
+  - \pdflastmatch more reliable when there was no match
 ---------------------------------------------------
-pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016)
+pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016)  (May 20, 2016)
 - changes:
   - if the environment variable SOURCE_DATE_EPOCH is set, use its value for
     the PDF CreationDate and ModDate values, and to seed the trailer /ID.
--- texlive-bin.orig/texk/web2c/pdftexdir/utils.c
+++ texlive-bin/texk/web2c/pdftexdir/utils.c
@@ -817,12 +817,16 @@
     pdf_printf("/ModDate (%s)\n", start_time_str);
 }
 
+
 #define DEFAULT_SUB_MATCH_COUNT 10
 static int sub_match_count = DEFAULT_SUB_MATCH_COUNT;
 static regmatch_t *pmatch = NULL;
 static char *match_string = NULL;
+static int last_match_succeeded = 0;
 
-void matchstrings(strnumber s, strnumber t, int subcount, boolean icase)
+/* Implements \pdfmatch */
+void
+matchstrings(strnumber s, strnumber t, int subcount, boolean icase)
 {
     regex_t preg;
     int cflags = REG_EXTENDED;
@@ -857,20 +861,31 @@
             pmatch = xtalloc(sub_match_count, regmatch_t);
         }
         ret = regexec(&preg, str, sub_match_count, pmatch, eflags);
+        
         xfree(match_string);
-        match_string = xstrdup(str);
-        strpool[poolptr++] = ((ret == 0) ? '1' : '0');
+        match_string = xstrdup(str);  /* save searched-in string, used below */
+        last_match_succeeded = ret == 0;     /* save whether match succeeded */
+        strpool[poolptr++] = ((ret == 0) ? '1' : '0'); /* in string pool too */
     }
 
     regfree(&preg);
 }
 
-void getmatch(int i)
+/* Implements \pdflastmatch */
+
+void
+getmatch(int i)
 {
-    int size, len = 0;          /* to avoid warning about uninitialized use of len */
+    int size;
+    int len = 0;                /* avoid spurious uninitialized warning */
 
-    boolean found = i < sub_match_count
-        && match_string != NULL && pmatch[i].rm_so >= 0 && i >= 0;
+    boolean found
+      = i >= 0                  /* should always be so due to pdftex.web */
+        && i < sub_match_count  /* if >subcount, not found by definition */
+        && match_string != NULL /* first call, and just in case */
+        && last_match_succeeded /* if no match, not found */
+        && pmatch[i].rm_so >= 0 /* if no starting position, not found */
+        && pmatch[i].rm_eo >= pmatch[i].rm_so; /* just in case */
 
     if (found) {
         len = pmatch[i].rm_eo - pmatch[i].rm_so;
@@ -903,6 +918,7 @@
     strpool[poolptr++] = '>';
 }
 
+
 /* function strips trailing zeros in string with numbers; */
 /* leading zeros are not stripped (as in real life) */
 char *stripzeros(char *a)