From 1299e08182b4248f2ef4441e2731946f32c0ba7f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 16 Jun 2003 11:17:55 +0000 Subject: [PATCH] Avoid quadratic running time when extracting very long strings or very long comments. --- gettext-tools/src/ChangeLog | 15 +++++++++++++++ gettext-tools/src/x-awk.c | 14 +++++++------- gettext-tools/src/x-c.c | 22 +++++++++++----------- gettext-tools/src/x-elisp.c | 6 +++--- gettext-tools/src/x-librep.c | 6 +++--- gettext-tools/src/x-lisp.c | 6 +++--- gettext-tools/src/x-php.c | 20 ++++++++++---------- gettext-tools/src/x-python.c | 10 +++++----- gettext-tools/src/x-rst.c | 10 +++++----- gettext-tools/src/x-smalltalk.c | 16 ++++++++-------- gettext-tools/src/x-tcl.c | 6 +++--- gettext-tools/src/x-ycp.c | 20 ++++++++++---------- 12 files changed, 83 insertions(+), 68 deletions(-) diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 40cf7dc2f..6f235f3bb 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,18 @@ +2003-06-15 Bruno Haible + + * x-awk.c (phase2_getc, x_awk_lex): Increase bufmax proportionally. + * x-c.c (comment_add, comment_line_end, phase5_get, phase6_get): + Likewise. + * x-elisp.c (comment_add, comment_line_end): Likewise. + * x-librep.c (comment_add, comment_line_end): Likewise. + * x-lisp.c (comment_add, comment_line_end): Likewise. + * x-php.c (comment_add, comment_line_end, x_php_lex): Likewise. + * x-python.c (comment_add, comment_line_end, phase5_get): Likewise. + * x-rst.c (extract_rst): Likewise. + * x-smalltalk.c (comment_add, comment_line_end, phase2_get): Likewise. + * x-tcl.c (comment_add, comment_line_end): Likewise. + * x-ycp.c (phase2_getc, x_ycp_lex): Likewise. + 2003-06-15 Bruno Haible * xgettext.c (current_formatstring_parser1, diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index 4d368a7fb..416d2c6bb 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -1,5 +1,5 @@ /* xgettext awk backend. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2002. @@ -201,14 +201,14 @@ phase2_getc () break; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; } if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -431,7 +431,7 @@ x_awk_lex (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -465,7 +465,7 @@ x_awk_lex (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; @@ -504,14 +504,14 @@ x_awk_lex (token_ty *tp) break; if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 16c86c07d..e26dc68a3 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -1,5 +1,5 @@ /* xgettext C/C++/ObjectiveC backend. - Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. + Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc. This file was written by Peter Miller @@ -426,7 +426,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -441,7 +441,7 @@ comment_line_end (size_t chars_to_remove) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -774,7 +774,7 @@ phase5_get (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -804,7 +804,7 @@ phase5_get (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -838,7 +838,7 @@ phase5_get (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -849,7 +849,7 @@ phase5_get (token_ty *tp) case 'E': if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -884,7 +884,7 @@ phase5_get (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -939,14 +939,14 @@ phase5_get (token_ty *tp) c = '\''; if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -1085,7 +1085,7 @@ phase6_get (token_ty *tp) /* Accumulate. */ if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buf = xrealloc (buf, bufmax * sizeof (buf[0])); } buf[bufpos++] = *tp; diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index b721ce5d1..625d79feb 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -1,5 +1,5 @@ /* xgettext Emacs Lisp backend. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2001-2002. @@ -339,7 +339,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -354,7 +354,7 @@ comment_line_end (size_t chars_to_remove) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 06cc2bf9a..3af8beb4c 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -1,5 +1,5 @@ /* xgettext librep backend. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2001. @@ -420,7 +420,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -435,7 +435,7 @@ comment_line_end (size_t chars_to_remove) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 6bf61340a..4828b8ef0 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -1,5 +1,5 @@ /* xgettext Lisp backend. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2001. @@ -831,7 +831,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -846,7 +846,7 @@ comment_line_end (size_t chars_to_remove) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index 1d2b5f7fd..b5e2d26aa 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -1,5 +1,5 @@ /* xgettext PHP backend. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2002. @@ -537,7 +537,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -552,7 +552,7 @@ comment_line_end (size_t chars_to_remove) --buflen; if (chars_to_remove == 0 && buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -773,7 +773,7 @@ x_php_lex (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -803,7 +803,7 @@ x_php_lex (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -830,14 +830,14 @@ x_php_lex (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -967,14 +967,14 @@ x_php_lex (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -1029,7 +1029,7 @@ x_php_lex (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index d19bb292d..dcf060210 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -221,7 +221,7 @@ comment_add (int c) size_t len = ((unsigned char) c < 0x80 ? 1 : 2); if (buflen + len > bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } if ((unsigned char) c < 0x80) @@ -241,7 +241,7 @@ comment_line_end () --buflen; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -716,7 +716,7 @@ phase5_get (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -745,7 +745,7 @@ phase5_get (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; @@ -847,7 +847,7 @@ phase5_get (token_ty *tp) len = (uc < 0x10000 ? 1 : 2); if (bufpos + len > bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax * sizeof (unsigned short)); } diff --git a/gettext-tools/src/x-rst.c b/gettext-tools/src/x-rst.c index 63ceb7c59..1f93b9f47 100644 --- a/gettext-tools/src/x-rst.c +++ b/gettext-tools/src/x-rst.c @@ -1,5 +1,5 @@ /* xgettext RST backend. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2001. @@ -109,7 +109,7 @@ extract_rst (FILE *f, } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } if (c == '=') @@ -143,7 +143,7 @@ extract_rst (FILE *f, break; if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -177,7 +177,7 @@ extract_rst (FILE *f, } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = (unsigned char) n; @@ -205,7 +205,7 @@ extract_rst (FILE *f, } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; diff --git a/gettext-tools/src/x-smalltalk.c b/gettext-tools/src/x-smalltalk.c index d9bdf8020..8df6a5948 100644 --- a/gettext-tools/src/x-smalltalk.c +++ b/gettext-tools/src/x-smalltalk.c @@ -1,5 +1,5 @@ /* xgettext Smalltalk backend. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2002. @@ -144,7 +144,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -158,7 +158,7 @@ comment_line_end () --buflen; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -267,14 +267,14 @@ phase2_get (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = 0; @@ -351,7 +351,7 @@ phase2_get (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -374,7 +374,7 @@ phase2_get (token_ty *tp) case ':': if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -405,7 +405,7 @@ phase2_get (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index 8cad4ead8..e9866a763 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -1,5 +1,5 @@ /* xgettext Tcl backend. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2002. @@ -364,7 +364,7 @@ comment_add (int c) { if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -378,7 +378,7 @@ comment_line_end () --buflen; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; diff --git a/gettext-tools/src/x-ycp.c b/gettext-tools/src/x-ycp.c index aa2c36fb1..d29a4fdff 100644 --- a/gettext-tools/src/x-ycp.c +++ b/gettext-tools/src/x-ycp.c @@ -1,5 +1,5 @@ /* xgettext YCP backend. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. This file was written by Bruno Haible , 2001. @@ -166,14 +166,14 @@ phase2_getc () break; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; } if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -210,7 +210,7 @@ phase2_getc () continue; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; @@ -267,14 +267,14 @@ phase2_getc () break; if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen++] = c; } if (buflen >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[buflen] = '\0'; @@ -422,7 +422,7 @@ x_ycp_lex (token_ty *tp) { if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; @@ -456,7 +456,7 @@ x_ycp_lex (token_ty *tp) } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; @@ -473,14 +473,14 @@ x_ycp_lex (token_ty *tp) break; if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos++] = c; } if (bufpos >= bufmax) { - bufmax += 100; + bufmax = 2 * bufmax + 10; buffer = xrealloc (buffer, bufmax); } buffer[bufpos] = '\0'; -- 2.47.3