From a9e05811d1d1a04b467aac0678e8f3fdbb2c7ab1 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 12 Jun 2016 18:19:07 +0000 Subject: \pdflastmatch: more checks if no preceding match, from pdftex r759 git-svn-id: svn://tug.org/texlive/trunk@41418 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/pdftexdir/ChangeLog | 14 ++++++++++++++ Build/source/texk/web2c/pdftexdir/NEWS | 5 ++++- Build/source/texk/web2c/pdftexdir/utils.c | 30 ++++++++++++++++++++++------- 3 files changed, 41 insertions(+), 8 deletions(-) (limited to 'Build/source/texk/web2c/pdftexdir') diff --git a/Build/source/texk/web2c/pdftexdir/ChangeLog b/Build/source/texk/web2c/pdftexdir/ChangeLog index bdc4f56dbff..05f7aa7ede1 100644 --- a/Build/source/texk/web2c/pdftexdir/ChangeLog +++ b/Build/source/texk/web2c/pdftexdir/ChangeLog @@ -1,3 +1,17 @@ +2016-06-12 Karl Berry + and Akira Kakuto + + * 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 + + * TeX Live 2016 release. + 2016-04-06 Karl Berry * pdftexextra.h (COPYRIGHT_HOLDER): don't specifically mention peb diff --git a/Build/source/texk/web2c/pdftexdir/NEWS b/Build/source/texk/web2c/pdftexdir/NEWS index 5e035092352..e35738463ef 100644 --- a/Build/source/texk/web2c/pdftexdir/NEWS +++ b/Build/source/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. diff --git a/Build/source/texk/web2c/pdftexdir/utils.c b/Build/source/texk/web2c/pdftexdir/utils.c index 88b8f09e11c..67ff8e9db46 100644 --- a/Build/source/texk/web2c/pdftexdir/utils.c +++ b/Build/source/texk/web2c/pdftexdir/utils.c @@ -817,12 +817,16 @@ void printmoddate(void) 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 @@ void matchstrings(strnumber s, strnumber t, int subcount, boolean icase) 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 @@ void getmatch(int i) strpool[poolptr++] = '>'; } + /* function strips trailing zeros in string with numbers; */ /* leading zeros are not stripped (as in real life) */ char *stripzeros(char *a) -- cgit v1.2.3