Subject: bug#11380: emacs compilation fails in call to oblookup() with len=-1

From: Dov Grobgeld <[email-masked]>
Date: Sun, 29 Apr 2012 20:59:29 +0300

building emacs crashes in src/doc.c::oblookup() with len=-1. The following
patch solves the problem:

diff --git a/src/doc.c b/src/doc.c
index 9e48a4d..ce54fd2 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -655,41 +655,45 @@ the same file name is found in the `doc-directory'.
*/)
                 }
             }

-      sym = oblookup (Vobarray, p + 2,
-              multibyte_chars_in_text ((unsigned char *) p + 2,
-                           end - p - 2),
-              end - p - 2);
-      /* Check skip_file so that when a function is defined several
-         times in different files (typically, once in xterm, once in
-         w32term, ...), we only pay attention to the one that
-         matters.  */
-      if (! skip_file && SYMBOLP (sym))
-        {
-          /* Attach a docstring to a variable?  */
-          if (p[1] == 'V')
-        {
-          /* Install file-position as variable-documentation property
-             and make it negative for a user-variable
-             (doc starts with a `*').  */
-                  if (!NILP (Fboundp (sym)))
-                    Fput (sym, Qvariable_documentation,
-                          make_number ((pos + end + 1 - buf)
-                                       * (end[1] == '*' ? -1 : 1)));
-        }
-
-          /* Attach a docstring to a function?  */
-          else if (p[1] == 'F')
+          EMACS_INT len = end - p - 2;
+          if (len>0)
+            {
+              sym = oblookup (Vobarray, p + 2,
+                              multibyte_chars_in_text ((unsigned char *) p
+ 2,
+                                                       end - p - 2),
+                              len);
+              /* Check skip_file so that when a function is defined several
+                 times in different files (typically, once in xterm, once
in
+                 w32term, ...), we only pay attention to the one that
+                 matters.  */
+              if (! skip_file && SYMBOLP (sym))
                 {
-                  if (!NILP (Ffboundp (sym)))
-                    store_function_docstring (sym, pos + end + 1 - buf);
+                  /* Attach a docstring to a variable?  */
+                  if (p[1] == 'V')
+                    {
+                      /* Install file-position as variable-documentation
property
+                         and make it negative for a user-variable
+                         (doc starts with a `*').  */
+                      if (!NILP (Fboundp (sym)))
+                        Fput (sym, Qvariable_documentation,
+                              make_number ((pos + end + 1 - buf)
+                                           * (end[1] == '*' ? -1 : 1)));
+                    }
+
+                  /* Attach a docstring to a function?  */
+                  else if (p[1] == 'F')
+                    {
+                      if (!NILP (Ffboundp (sym)))
+                        store_function_docstring (sym, pos + end + 1 -
buf);
+                    }
+                  else if (p[1] == 'S')
+                    ; /* Just a source file name boundary marker.  Ignore
it.  */
+
+                  else
+                    error ("DOC file invalid at position %"pI"d", pos);
                 }
-          else if (p[1] == 'S')
-        ; /* Just a source file name boundary marker.  Ignore it.  */
-
-          else
-        error ("DOC file invalid at position %"pI"d", pos);
-        }
-    }
+            }
+      }
       pos += end - buf;
       filled -= end - buf;
       memmove (buf, end, filled);

Regards,
Dov

On Sun, Apr 29, 2012 at 20:41, Dov Grobgeld <[email-masked]> wrote:

> Chucking out git head (git commit e3e392d from git://repo.or.cz/emacs.git)
> and doing a debug build as described below
> fails. The compilation looks for the non-existing file "chkmalloc.h".
>
> Here are the steps that I performed:
>
>   ./autogen.sh
>   ./configure --prefix=/usr/local/public-dev/ CPPFLAGS=-DDEBUG CFLAGS="-g
> -O0"
>   make
>
> which fails as follows:
>
> gcc -std=gnu99     -DHAVE_CONFIG_H -I. -I../src -I../lib
> -I/space/pub-repos/emacs.git/lib-src
> -I/space/pub-repos/emacs.git/lib-src/../src
> -I/space/pub-repos/emacs.git/lib-src/../lib  -Wl,-znocombreloc  -DDEBUG -g
> -O0 -DEMACS_NAME="\"GNU Emacs\"" \
>   -DVERSION="\"24.1.50\"" /space/pub-repos/emacs.git/lib-src/etags.c \
>   regex.o ../lib/libgnu.a  -o etags
> /space/pub-repos/emacs.git/lib-src/etags.c:233:24: fatal error:
> chkmalloc.h: No such file or directory
>
> System is: Linux grower 3.3.2-6.fc16.i686 #1 SMP Sat Apr 21 13:23:12 UTC
> 2012 i686 i686 i386 GNU/Linux
>
> Regards,
> Dov
>
>