X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/b3bf18b3b87ac8f00857b8bfc3f2c74cf0e2fb7d..7e09ef09a479731d01b1ca46e94ddadd73ac98e3:/src/doc.c diff --git a/src/doc.c b/src/doc.c index be882d4a5c..3359444215 100644 --- a/src/doc.c +++ b/src/doc.c @@ -1,6 +1,7 @@ /* Record indices of function doc strings stored in a file. -Copyright (C) 1985-1986, 1993-1995, 1997-2014 Free Software Foundation, Inc. +Copyright (C) 1985-1986, 1993-1995, 1997-2015 Free Software Foundation, +Inc. This file is part of GNU Emacs. @@ -42,6 +43,8 @@ static ptrdiff_t get_doc_string_buffer_size; static unsigned char *read_bytecode_pointer; +static char const sibling_etc[] = "../etc/"; + /* `readchar' in lread.c calls back here to fetch the next byte. If UNREADFLAG is 1, we unread a byte. */ @@ -80,7 +83,6 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) { char *from, *to, *name, *p, *p1; int fd; - ptrdiff_t minsize; int offset; EMACS_INT position; Lisp_Object file, tem, pos; @@ -113,21 +115,14 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) tem = Ffile_name_absolute_p (file); file = ENCODE_FILE (file); - if (NILP (tem)) - { - Lisp_Object docdir = ENCODE_FILE (Vdoc_directory); - minsize = SCHARS (docdir); - /* sizeof ("../etc/") == 8 */ - if (minsize < 8) - minsize = 8; - name = SAFE_ALLOCA (minsize + SCHARS (file) + 8); - strcpy (name, SSDATA (docdir)); - strcat (name, SSDATA (file)); - } - else - { - name = SSDATA (file); - } + Lisp_Object docdir + = NILP (tem) ? ENCODE_FILE (Vdoc_directory) : empty_unibyte_string; + ptrdiff_t docdir_sizemax = SBYTES (docdir) + 1; +#ifndef CANNOT_DUMP + docdir_sizemax = max (docdir_sizemax, sizeof sibling_etc); +#endif + name = SAFE_ALLOCA (docdir_sizemax + SBYTES (file)); + lispstpcpy (lispstpcpy (name, docdir), file); fd = emacs_open (name, O_RDONLY, 0); if (fd < 0) @@ -137,8 +132,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) { /* Preparing to dump; DOC file is probably not installed. So check in ../etc. */ - strcpy (name, "../etc/"); - strcat (name, SSDATA (file)); + lispstpcpy (stpcpy (name, sibling_etc), file); fd = emacs_open (name, O_RDONLY, 0); } @@ -146,8 +140,9 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) if (fd < 0) { SAFE_FREE (); - return concat3 (build_string ("Cannot open doc string file \""), - file, build_string ("\"\n")); + AUTO_STRING (cannot_open, "Cannot open doc string file \""); + AUTO_STRING (quote_nl, "\"\n"); + return concat3 (cannot_open, file, quote_nl); } } count = SPECPDL_INDEX (); @@ -579,7 +574,6 @@ the same file name is found in the `doc-directory'. */) (0) #endif /* CANNOT_DUMP */ { - static char const sibling_etc[] = "../etc/"; dirname = sibling_etc; dirlen = sizeof sibling_etc - 1; } @@ -593,8 +587,7 @@ the same file name is found in the `doc-directory'. */) count = SPECPDL_INDEX (); USE_SAFE_ALLOCA; name = SAFE_ALLOCA (dirlen + SBYTES (filename) + 1); - strcpy (name, dirname); - strcat (name, SSDATA (filename)); /*** Add this line ***/ + lispstpcpy (stpcpy (name, dirname), filename); /*** Add this line ***/ /* Vbuild_files is nil when temacs is run, and non-nil after that. */ if (NILP (Vbuild_files))