texlive[49823] Build/source/texk/web2c: MetaPost: fixed bisection.
commits+lscarso at tug.org
commits+lscarso at tug.org
Sat Jan 26 15:27:39 CET 2019
Revision: 49823
http://tug.org/svn/texlive?view=revision&revision=49823
Author: lscarso
Date: 2019-01-26 15:27:38 +0100 (Sat, 26 Jan 2019)
Log Message:
-----------
MetaPost: fixed bisection. LuaTeX: updated dev. id.
Modified Paths:
--------------
trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
trunk/Build/source/texk/web2c/mplibdir/ChangeLog
trunk/Build/source/texk/web2c/mplibdir/mp.w
trunk/Build/source/texk/web2c/mplibdir/mpost.w
Modified: trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h 2019-01-26 01:23:50 UTC (rev 49822)
+++ trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h 2019-01-26 14:27:38 UTC (rev 49823)
@@ -1 +1 @@
-#define luatex_svn_revision 7056
+#define luatex_svn_revision 7064
Modified: trunk/Build/source/texk/web2c/mplibdir/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/mplibdir/ChangeLog 2019-01-26 01:23:50 UTC (rev 49822)
+++ trunk/Build/source/texk/web2c/mplibdir/ChangeLog 2019-01-26 14:27:38 UTC (rev 49823)
@@ -1,3 +1,10 @@
+2019-01-26 Luigi Scarso <luigi.scarso at gmail.com>
+ * Fixed bisection algorithm (overflow of number of bisections in decimal mode with low precision)
+ * Added 2 levels to the bisection algorithm for cubic intersection. Need testing.
+ * Fixed a buffer overflow on command line; for consistency with mp_reallocate_buffer,
+ now accepting input from command line of at most 0xFFFFFFF bytes.
+
+
2019-01-06 Luigi Scarso <luigi.scarso at gmail.com>
* Added r-mpost as an alias for mpost --restricted
Modified: trunk/Build/source/texk/web2c/mplibdir/mp.w
===================================================================
--- trunk/Build/source/texk/web2c/mplibdir/mp.w 2019-01-26 01:23:50 UTC (rev 49822)
+++ trunk/Build/source/texk/web2c/mplibdir/mp.w 2019-01-26 14:27:38 UTC (rev 49823)
@@ -189,7 +189,7 @@
#include "mpmath.h" /* internal header */
#include "mpmathdouble.h" /* internal header */
#include "mpmathdecimal.h" /* internal header */
-/*#include "mpmathbinary.h"*/ /* internal header */
+/*|#include "mpmathbinary.h"|*/ /* internal header */
#include "mpstrings.h" /* internal header */
/* BEGIN PATCH */
mp_number dx_ap; /* approximation of dx */
@@ -608,7 +608,7 @@
mp_reallocate_paths (mp, 1000);
mp_reallocate_fonts (mp, 8);
mp->history = mp_fatal_error_stop; /* in case we quit during initialization */
- @<Check the ``constant'' values...@>;
+ @<Check the ``constant'' values...@>; /* consider also the raise of the bits for precision */
if (mp->bad > 0) {
char ss[256];
mp_snprintf (ss, 256, "Ouch---my internal constants have been clobbered!\n"
@@ -1333,7 +1333,7 @@
@c
boolean mp_init_terminal (MP mp) { /* gets the terminal input started */
- t_open_in();
+ t_open_in();
if (mp->last != 0) {
loc = 0;
mp->first = 0;
@@ -15772,18 +15772,23 @@
@c
static void mp_cubic_intersection (MP mp, mp_knot p, mp_knot pp) {
mp_knot q, qq; /* |mp_link(p)|, |mp_link(pp)| */
- mp_number x_two_t; /* increment bit precision by x bit */
+ mp_number x_two_t; /* increment bit precision */
+ mp_number x_two_t_low_precision; /* check for low precision */
mp->time_to_go = max_patience;
set_number_from_scaled (mp->max_t, 2);
new_number (x_two_t);
+ new_number (x_two_t_low_precision);
+
number_clone (x_two_t,two_t);
- number_double(x_two_t); number_double(x_two_t); /* add x=2 bit of precision */
- number_double(x_two_t);
+ number_double(x_two_t);number_double(x_two_t); /* added 2 bit of precision */
+ set_number_from_double (x_two_t_low_precision,-0.5);
+ number_add (x_two_t_low_precision,x_two_t);
+
@<Initialize for intersections at level zero@>;
CONTINUE:
while (1) {
/* When we are in arbitrary precision math, low precisions can */
- /* lead to acces locations beyond the stack_size: in this case */
+ /* lead to acces locations beyond the |stack_size|: in this case */
/* we say that there is no intersection.*/
if ( ((x_packet (mp->xy))+4)>bistack_size ||
((u_packet (mp->uv))+4)>bistack_size ||
@@ -15793,7 +15798,16 @@
set_number_from_scaled (mp->cur_tt, 1);
goto NOT_FOUND;
}
-
+ /* Also, low precision can lead to wrong result in comparing */
+ /* so we check that the level of bisection stay low, and later */
+ /* we will also check that the bisection level are safe from */
+ /* approximations. */
+ if (number_greater (mp->max_t, x_two_t)){
+ set_number_from_scaled (mp->cur_t, 1);
+ set_number_from_scaled (mp->cur_tt, 1);
+ goto NOT_FOUND;
+ }
+
if (number_to_scaled (mp->delx) - mp->tol <=
number_to_scaled (stack_max (x_packet (mp->xy))) - number_to_scaled (stack_min (u_packet (mp->uv))))
if (number_to_scaled (mp->delx) + mp->tol >=
@@ -15803,8 +15817,8 @@
if (number_to_scaled (mp->dely) + mp->tol >=
number_to_scaled (stack_min (y_packet (mp->xy))) - number_to_scaled (stack_max (v_packet (mp->uv)))) {
if (number_to_scaled (mp->cur_t) >= number_to_scaled (mp->max_t)) {
- if (number_equal(mp->max_t, x_two_t)) { /* we've done 17+x bisections */
- number_divide_int(mp->cur_t,1<<3);number_divide_int(mp->cur_tt,1<<3);
+ if ( number_equal(mp->max_t, x_two_t) || number_greater(mp->max_t,x_two_t_low_precision)) { /* we've done 17+2 bisections */
+ number_divide_int(mp->cur_t,1<<2);number_divide_int(mp->cur_tt,1<<2); /* restore values due bit precision */
set_number_from_scaled (mp->cur_t, ((number_to_scaled (mp->cur_t) + 1)/2));
set_number_from_scaled (mp->cur_tt, ((number_to_scaled (mp->cur_tt) + 1)/2));
return;
@@ -15819,7 +15833,8 @@
if (mp->time_to_go > 0) {
decr (mp->time_to_go);
} else {
- number_divide_int(mp->appr_t,1<<3);number_divide_int(mp->appr_tt,1<<3);
+ /* we have added 2 bit of precision */
+ number_divide_int(mp->appr_t,1<<2);number_divide_int(mp->appr_tt,1<<2);
while (number_less (mp->appr_t, unity_t)) {
number_double(mp->appr_t);
number_double(mp->appr_tt);
@@ -20025,10 +20040,10 @@
if (mode <= 0) {
txt[size - 1] = ' ';
} else if (verb) {
- /* modes >= 1 permit a newline in verbatimtex */
+ /* modes $\geq 1$ permit a newline in verbatimtex */
txt[size - 1] = '\n';
} else if (mode >= 2) {
- /* modes >= 2 permit a newline in btex */
+ /* modes $\geq 2$ permit a newline in btex */
txt[size - 1] = '\n';
} else {
txt[size - 1] = ' ';
@@ -20069,8 +20084,8 @@
txt[size] = '\0';
ptr = txt;
} else {
- /* strip trailing whitespace, we have a \0 so we're one off */
- /* while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-2]] == space_class || txt[size-2] == '\n')) { */
+ /* strip trailing whitespace, we have a |'\0'| so we are off by one */
+ /* |while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-2]] == space_class| $\vbv\vbv$ |txt[size-2] == '\n')) | */
while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-1]] == space_class || txt[size-1] == '\n')) {
decr(size);
}
Modified: trunk/Build/source/texk/web2c/mplibdir/mpost.w
===================================================================
--- trunk/Build/source/texk/web2c/mplibdir/mpost.w 2019-01-26 01:23:50 UTC (rev 49822)
+++ trunk/Build/source/texk/web2c/mplibdir/mpost.w 2019-01-26 14:27:38 UTC (rev 49823)
@@ -1102,6 +1102,7 @@
input.
@d command_line_size 256
+ at d max_commad_line_size 0xFFFFFFF /* should be the same of |max_halfword| (see |mp_reallocate_buffer|) */
@<Copy the rest of the command line@>=
{
@@ -1109,18 +1110,28 @@
options->command_line = mpost_xmalloc(command_line_size);
strcpy(options->command_line,"");
if (optind<argc) {
+ int optind_aux = optind;
+ size_t buflen = 0;
+ for(;optind_aux<argc;optind_aux++) {
+ buflen +=(strlen(argv[optind_aux])+1); /* reserve space for ' ' as separator */
+ }
+ /* Last char is ' ', no need to reserve space for final '\0' */
+ if (buflen > max_commad_line_size) {
+ fprintf(stderr,"length of command line too long!\n");
+ exit(EXIT_FAILURE);
+ }
+ mpost_xfree(options->command_line);
+ options->command_line = mpost_xmalloc(buflen);
k=0;
for(;optind<argc;optind++) {
char *c = argv[optind];
while (*c != '\0') {
- if (k<(command_line_size-1)) {
- options->command_line[k++] = *c;
- }
+ options->command_line[k++] = *c;
c++;
}
options->command_line[k++] = ' ';
}
- while (k>0) {
+ while (k>0) {
if (options->command_line[(k-1)] == ' ')
k--;
else
More information about the tex-live-commits
mailing list