]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Avoid quadratic running time when extracting very long strings or very
authorBruno Haible <bruno@clisp.org>
Mon, 16 Jun 2003 11:17:55 +0000 (11:17 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:41 +0000 (12:10 +0200)
long comments.

12 files changed:
gettext-tools/src/ChangeLog
gettext-tools/src/x-awk.c
gettext-tools/src/x-c.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-php.c
gettext-tools/src/x-python.c
gettext-tools/src/x-rst.c
gettext-tools/src/x-smalltalk.c
gettext-tools/src/x-tcl.c
gettext-tools/src/x-ycp.c

index 40cf7dc2f0fdd5a459d990b447d3eb67f2775083..6f235f3bbdd0b4ad290e378eac9c3bb9e92ef803 100644 (file)
@@ -1,3 +1,18 @@
+2003-06-15  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * xgettext.c (current_formatstring_parser1,
index 4d368a7fbd9561f8c55e59d84af24cf1153cb04b..416d2c6bba0e36f3a84f3d7f0795011d8e1f6057 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index 16c86c07d6f0d4b0927e3d8b6825c2278615e41f..e26dc68a31bdae857cd3343e8c0b5c4573c49fe5 100644 (file)
@@ -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 <millerp@canb.auug.org.au>
 
@@ -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;
index b721ce5d118e03cf970088cab6366c4c8b62fa09..625d79febe26097913147800f6d56683c8209fab 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index 06cc2bf9a66a07e782f235a6e26733f08bccc020..3af8beb4c95ab3c488f99e37113ef7fa23442b89 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index 6bf61340a375cc0edd04f47a61614e0be60f576b..4828b8ef06e4092dd53f76c54849bce275146b28 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index 1d2b5f7fd63d6fb10687118a3cf78d0ff43d5429..b5e2d26aa08a825950296563f0237f8038b889ae 100644 (file)
@@ -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 <bruno@clisp.org>, 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;
index d19bb292dcc8c522d3d7caa26e34dce7b20a1fda..dcf060210f7fa68c9c00c88c0cc198e8513e1e0f 100644 (file)
@@ -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));
                    }
index 63ceb7c59fcfaed458fe73c2d7be96c792cb0ad9..1f93b9f472911602a65635aed6b9d082475163ec 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index d9bdf80200e4da877a429bf51c7f392654228e63..8df6a5948419489d84a300eb038c79c69b81a948 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index 8cad4ead8a5d4be0cf524aa7bb1b5e798678a754..e9866a763417b71cbd44b177796188f35293011f 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';
index aa2c36fb1ecf4047b520e7154aca74720e3f0cd0..d29a4fdffe3aa6faac66b89b40c3cbcf157940f9 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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';