CID:226 - SECURE_CODING risky usage of strcpy
[sxemacs] / src / marker.c
1 /* Markers: examining, setting and killing.
2    Copyright (C) 1985, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3
4 This file is part of SXEmacs
5
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
18
19
20 /* Synched up with: FSF 19.30. */
21
22 /* This file has been Mule-ized. */
23
24 /* Note that markers are currently kept in an unordered list.
25    This means that marker operations may be inefficient if
26    there are a bunch of markers in the buffer.  This probably
27    won't have a significant impact on redisplay (which uses
28    markers), but if it does, it wouldn't be too hard to change
29    to an ordered gap array. (Just copy the code from extents.c.)
30    */
31
32 #include <config.h>
33 #include "lisp.h"
34
35 #include "buffer.h"
36
37 static Lisp_Object mark_marker(Lisp_Object obj)
38 {
39         Lisp_Marker *marker = XMARKER(obj);
40         Lisp_Object buf;
41         /* DO NOT mark through the marker's chain.
42            The buffer's markers chain does not preserve markers from gc;
43            Instead, markers are removed from the chain when they are freed
44            by gc.
45          */
46         if (!marker->buffer)
47                 return (Qnil);
48
49         XSETBUFFER(buf, marker->buffer);
50         return (buf);
51 }
52
53 static void
54 print_marker(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
55 {
56         Lisp_Marker *marker = XMARKER(obj);
57         char buf[200];
58
59         if (print_readably)
60                 error("printing unreadable object #<marker 0x%lx>",
61                       (long)marker);
62
63         write_c_string(GETTEXT("#<marker "), printcharfun);
64         if (!marker->buffer)
65                 write_c_string(GETTEXT("in no buffer"), printcharfun);
66         else {
67                 sprintf(buf, "at %ld in ", (long)marker_position(obj));
68                 write_c_string(buf, printcharfun);
69                 print_internal(marker->buffer->name, printcharfun, 0);
70         }
71         sprintf(buf, " 0x%lx>", (long)marker);
72         write_c_string(buf, printcharfun);
73 }
74
75 static int marker_equal(Lisp_Object obj1, Lisp_Object obj2, int depth)
76 {
77         Lisp_Marker *marker1 = XMARKER(obj1);
78         Lisp_Marker *marker2 = XMARKER(obj2);
79
80         return ((marker1->buffer == marker2->buffer) &&
81                 (marker1->memind == marker2->memind ||
82                  /* All markers pointing nowhere are equal */
83                  !marker1->buffer));
84 }
85
86 static unsigned long marker_hash(Lisp_Object obj, int depth)
87 {