Skip to content
Snippets Groups Projects
Commit 8bc38054 authored by Luigi Scarso's avatar Luigi Scarso
Browse files

sync with trunk rev. 7065

parent 4964a8fb
No related branches found
No related tags found
No related merge requests found
#define luatex_svn_revision 7056
#define luatex_svn_revision 7064
2019-01-26 Luigi Scarso <luigi.scarso@gmail.com>
* Fixed bisection algorithm (overflow of number of bisections in decimal mode with low precision)
* Fixed to 2 the levels to the bisection algorithm for 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@gmail.com>
* Added r-mpost as an alias for mpost --restricted
......
......@@ -189,7 +189,7 @@ static int DEBUGENVELOPECOUNTER=0;
#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 mp_initialize (MP_options * opt) {
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 @@ not be typed immediately after~`\.{**}'.)
 
@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 @@ and |(pp,mp_link(pp))|, respectively.
@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 @@ CONTINUE:
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 @@ CONTINUE:
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 @@ CONTINUE:
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 @@ line and preceded by a space or at the beginning of a line.
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 @@ line and preceded by a space or at the beginning of a line.
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);
}
......@@ -1102,6 +1102,7 @@ stored in the \MP\ instance, this will be taken as the first line of
input.
@d command_line_size 256
@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 @@ input.
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment