Convenient macro to check whether the buffer is live.
[bpt/emacs.git] / src / editfns.c
index 9cfd044..299cad0 100644 (file)
@@ -44,7 +44,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/resource.h>
 #endif
 
-#include <ctype.h>
 #include <float.h>
 #include <limits.h>
 #include <intprops.h>
@@ -59,14 +58,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "window.h"
 #include "blockinput.h"
 
-#ifndef USER_FULL_NAME
-#define USER_FULL_NAME pw->pw_gecos
-#endif
-
-#ifndef USE_CRT_DLL
-extern char **environ;
-#endif
-
 #define TM_YEAR_BASE 1900
 
 #ifdef WINDOWSNT
@@ -74,7 +65,7 @@ extern Lisp_Object w32_get_internal_run_time (void);
 #endif
 
 static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME,
-                                      int, struct tm *);
+                                      bool, struct tm *);
 static int tm_diff (struct tm *, struct tm *);
 static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
 
@@ -255,11 +246,11 @@ The return value is POSITION.  */)
 
 
 /* Return the start or end position of the region.
-   BEGINNINGP non-zero means return the start.
+   BEGINNINGP means return the start.
    If there is no region active, signal an error. */
 
 static Lisp_Object
-region_limit (int beginningp)
+region_limit (bool beginningp)
 {
   Lisp_Object m;
 
@@ -273,7 +264,7 @@ region_limit (int beginningp)
     error ("The mark is not set now, so there is no region");
 
   /* Clip to the current narrowing (bug#11770).  */
-  return make_number ((PT < XFASTINT (m)) == (beginningp != 0)
+  return make_number ((PT < XFASTINT (m)) == beginningp
                      ? PT
                      : clip_to_bounds (BEGV, XFASTINT (m), ZV));
 }
@@ -444,12 +435,12 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
    BEG_LIMIT and END_LIMIT serve to limit the ranged of the returned
    results; they do not effect boundary behavior.
 
-   If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first
+   If MERGE_AT_BOUNDARY is non-nil, then if POS is at the very first
    position of a field, then the beginning of the previous field is
    returned instead of the beginning of POS's field (since the end of a
    field is actually also the beginning of the next input field, this
    behavior is sometimes useful).  Additionally in the MERGE_AT_BOUNDARY
-   true case, if two fields are separated by a field with the special
+   non-nil case, if two fields are separated by a field with the special
    value `boundary', and POS lies within it, then the two separated
    fields are considered to be adjacent, and POS between them, when
    finding the beginning and ending of the "merged" field.
@@ -464,10 +455,10 @@ find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
 {
   /* Fields right before and after the point.  */
   Lisp_Object before_field, after_field;
-  /* 1 if POS counts as the start of a field.  */
-  int at_field_start = 0;
-  /* 1 if POS counts as the end of a field.  */
-  int at_field_end = 0;
+  /* True if POS counts as the start of a field.  */
+  bool at_field_start = 0;
+  /* True if POS counts as the end of a field.  */
+  bool at_field_end = 0;
 
   if (NILP (pos))
     XSETFASTINT (pos, PT);
@@ -511,19 +502,19 @@ find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
 
        xxxx.yyyy
 
-     In this situation, if merge_at_boundary is true, we consider the
+     In this situation, if merge_at_boundary is non-nil, consider the
      `x' and `y' fields as forming one big merged field, and so the end
      of the field is the end of `y'.
 
      However, if `x' and `y' are separated by a special `boundary' field
-     (a field with a `field' char-property of 'boundary), then we ignore
+     (a field with a `field' char-property of 'boundary), then ignore
      this special field when merging adjacent fields.  Here's the same
      situation, but with a `boundary' field between the `x' and `y' fields:
 
        xxx.BBBByyyy
 
      Here, if point is at the end of `x', the beginning of `y', or
-     anywhere in-between (within the `boundary' field), we merge all
+     anywhere in-between (within the `boundary' field), merge all
      three fields and consider the beginning as being the beginning of
      the `x' field, and the end as being the end of the `y' field.  */
 
@@ -667,7 +658,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.  */)
 {
   /* If non-zero, then the original point, before re-positioning.  */
   ptrdiff_t orig_point = 0;
-  int fwd;
+  bool fwd;
   Lisp_Object prev_old, prev_new;
 
   if (NILP (new_pos))
@@ -825,8 +816,8 @@ This function does not move point.  */)
 Lisp_Object
 save_excursion_save (void)
 {
-  int visible = (XBUFFER (XWINDOW (selected_window)->buffer)
-                == current_buffer);
+  bool visible = (XBUFFER (XWINDOW (selected_window)->buffer)
+                 == current_buffer);
 
   return Fcons (Fpoint_marker (),
                Fcons (Fcopy_marker (BVAR (current_buffer, mark), Qnil),
@@ -840,7 +831,7 @@ save_excursion_restore (Lisp_Object info)
 {
   Lisp_Object tem, tem1, omark, nmark;
   struct gcpro gcpro1, gcpro2, gcpro3;
-  int visible_p;
+  bool visible_p;
 
   tem = Fmarker_buffer (XCAR (info));
   /* If buffer being returned to is now deleted, avoid error */
@@ -886,7 +877,7 @@ save_excursion_restore (Lisp_Object info)
   info = XCDR (info);
   tem = XCAR (info);
   tem1 = BVAR (current_buffer, mark_active);
-  BVAR (current_buffer, mark_active) = tem;
+  bset_mark_active (current_buffer, tem);
 
   /* If mark is active now, and either was not active
      or was at a different place, run the activate hook.  */
@@ -950,18 +941,15 @@ usage: (save-excursion &rest BODY)  */)
 }
 
 DEFUN ("save-current-buffer", Fsave_current_buffer, Ssave_current_buffer, 0, UNEVALLED, 0,
-       doc: /* Save the current buffer; execute BODY; restore the current buffer.
-Executes BODY just like `progn'.
+       doc: /* Record which buffer is current; execute BODY; make that buffer current.
+BODY is executed just like `progn'.
 usage: (save-current-buffer &rest BODY)  */)
   (Lisp_Object args)
 {
-  Lisp_Object val;
   ptrdiff_t count = SPECPDL_INDEX ();
 
-  record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
-
-  val = Fprogn (args);
-  return unbind_to (count, val);
+  record_unwind_current_buffer ();
+  return unbind_to (count, Fprogn (args));
 }
 \f
 DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0,
@@ -1479,8 +1467,8 @@ make_lisp_time (EMACS_TIME t)
 
 /* Decode a Lisp list SPECIFIED_TIME that represents a time.
    Set *PHIGH, *PLOW, *PUSEC, *PPSEC to its parts; do not check their values.
-   Return nonzero if successful.  */
-static int
+   Return true if successful.  */
+static bool
 disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
                       Lisp_Object *plow, Lisp_Object *pusec,
                       Lisp_Object *ppsec)
@@ -1523,8 +1511,8 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
    If *DRESULT is not null, store into *DRESULT the number of
    seconds since the start of the POSIX Epoch.
 
-   Return nonzero if successful.  */
-int
+   Return true if successful.  */
+bool
 decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
                        Lisp_Object psec,
                        EMACS_TIME *result, double *dresult)
@@ -1644,7 +1632,7 @@ or (if you need time as a string) `format-time-string'.  */)
 
 /* Write information into buffer S of size MAXSIZE, according to the
    FORMAT of length FORMAT_LEN, using time information taken from *TP.
-   Default to Universal Time if UT is nonzero, local time otherwise.
+   Default to Universal Time if UT, local time otherwise.
    Use NS as the number of nanoseconds in the %N directive.
    Return the number of bytes written, not including the terminating
    '\0'.  If S is NULL, nothing will be written anywhere; so to
@@ -1655,7 +1643,7 @@ or (if you need time as a string) `format-time-string'.  */)
    bytes in FORMAT and it does not support nanoseconds.  */
 static size_t
 emacs_nmemftime (char *s, size_t maxsize, const char *format,
-                size_t format_len, const struct tm *tp, int ut, int ns)
+                size_t format_len, const struct tm *tp, bool ut, int ns)
 {
   size_t total = 0;
 
@@ -1760,7 +1748,7 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL)  */)
 
 static Lisp_Object
 format_time_string (char const *format, ptrdiff_t formatlen,
-                   EMACS_TIME t, int ut, struct tm *tmp)
+                   EMACS_TIME t, bool ut, struct tm *tmp)
 {
   char buffer[4000];
   char *buf = buffer;
@@ -1797,7 +1785,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
       if (STRING_BYTES_BOUND <= len)
        string_overflow ();
       size = len + 1;
-      SAFE_ALLOCA (buf, char *, size);
+      buf = SAFE_ALLOCA (size);
     }
 
   UNBLOCK_INPUT;
@@ -2076,7 +2064,7 @@ the data it can't find.  */)
          int m = offset / 60;
          int am = offset < 0 ? - m : m;
          char buf[sizeof "+00" + INT_STRLEN_BOUND (int)];
-         zone_name = make_formatted_string (buf, "%c%02d%02d", 
+         zone_name = make_formatted_string (buf, "%c%02d%02d",
                                             (offset < 0 ? '-' : '+'),
                                             am / 60, am % 60);
        }
@@ -2240,11 +2228,11 @@ general_insert_function (void (*insert_func)
                              (const char *, ptrdiff_t),
                         void (*insert_from_string_func)
                              (Lisp_Object, ptrdiff_t, ptrdiff_t,
-                              ptrdiff_t, ptrdiff_t, int),
-                        int inherit, ptrdiff_t nargs, Lisp_Object *args)
+                              ptrdiff_t, ptrdiff_t, bool),
+                        bool inherit, ptrdiff_t nargs, Lisp_Object *args)
 {
   ptrdiff_t argnum;
-  register Lisp_Object val;
+  Lisp_Object val;
 
   for (argnum = 0; argnum < nargs; argnum++)
     {
@@ -2467,7 +2455,7 @@ from adjoining text, if those properties are sticky.  */)
 /* Return a Lisp_String containing the text of the current buffer from
    START to END.  If text properties are in use and the current buffer
    has properties in the range specified, the resulting string will also
-   have them, if PROPS is nonzero.
+   have them, if PROPS is true.
 
    We don't want to use plain old make_string here, because it calls
    make_uninit_string, which can cause the buffer arena to be
@@ -2478,7 +2466,7 @@ from adjoining text, if those properties are sticky.  */)
    buffer substrings.  */
 
 Lisp_Object
-make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
+make_buffer_string (ptrdiff_t start, ptrdiff_t end, bool props)
 {
   ptrdiff_t start_byte = CHAR_TO_BYTE (start);
   ptrdiff_t end_byte = CHAR_TO_BYTE (end);
@@ -2491,7 +2479,7 @@ make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
 
    If text properties are in use and the current buffer
    has properties in the range specified, the resulting string will also
-   have them, if PROPS is nonzero.
+   have them, if PROPS is true.
 
    We don't want to use plain old make_string here, because it calls
    make_uninit_string, which can cause the buffer arena to be
@@ -2503,7 +2491,7 @@ make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
 
 Lisp_Object
 make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte,
-                        ptrdiff_t end, ptrdiff_t end_byte, int props)
+                        ptrdiff_t end, ptrdiff_t end_byte, bool props)
 {
   Lisp_Object result, tem, tem1;
 
@@ -2625,7 +2613,7 @@ They default to the values of (point-min) and (point-max) in BUFFER.  */)
   if (NILP (buf))
     nsberror (buffer);
   bp = XBUFFER (buf);
-  if (NILP (BVAR (bp, name)))
+  if (!BUFFER_LIVE_P (bp))
     error ("Selecting deleted buffer");
 
   if (NILP (start))
@@ -2689,7 +2677,7 @@ determines whether case is significant or ignored.  */)
       if (NILP (buf1))
        nsberror (buffer1);
       bp1 = XBUFFER (buf1);
-      if (NILP (BVAR (bp1, name)))
+      if (!BUFFER_LIVE_P (bp1))
        error ("Selecting deleted buffer");
     }
 
@@ -2727,7 +2715,7 @@ determines whether case is significant or ignored.  */)
       if (NILP (buf2))
        nsberror (buffer2);
       bp2 = XBUFFER (buf2);
-      if (NILP (BVAR (bp2, name)))
+      if (!BUFFER_LIVE_P (bp2))
        error ("Selecting deleted buffer");
     }
 
@@ -2795,8 +2783,8 @@ determines whether case is significant or ignored.  */)
 
       if (!NILP (trt))
        {
-         c1 = CHAR_TABLE_TRANSLATE (trt, c1);
-         c2 = CHAR_TABLE_TRANSLATE (trt, c2);
+         c1 = char_table_translate (trt, c1);
+         c2 = char_table_translate (trt, c2);
        }
       if (c1 < c2)
        return make_number (- 1 - chars);
@@ -2820,13 +2808,15 @@ determines whether case is significant or ignored.  */)
 static Lisp_Object
 subst_char_in_region_unwind (Lisp_Object arg)
 {
-  return BVAR (current_buffer, undo_list) = arg;
+  bset_undo_list (current_buffer, arg);
+  return arg;
 }
 
 static Lisp_Object
 subst_char_in_region_unwind_1 (Lisp_Object arg)
 {
-  return BVAR (current_buffer, filename) = arg;
+  bset_filename (current_buffer, arg);
+  return arg;
 }
 
 DEFUN ("subst-char-in-region", Fsubst_char_in_region,
@@ -2852,7 +2842,8 @@ Both characters must have the same length of multi-byte form.  */)
 #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
   int maybe_byte_combining = COMBINING_NO;
   ptrdiff_t last_changed = 0;
-  int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters));
+  bool multibyte_p
+    = !NILP (BVAR (current_buffer, enable_multibyte_characters));
   int fromc, toc;
 
  restart:
@@ -2900,11 +2891,11 @@ Both characters must have the same length of multi-byte form.  */)
     {
       record_unwind_protect (subst_char_in_region_unwind,
                             BVAR (current_buffer, undo_list));
-      BVAR (current_buffer, undo_list) = Qt;
+      bset_undo_list (current_buffer, Qt);
       /* Don't do file-locking.  */
       record_unwind_protect (subst_char_in_region_unwind_1,
                             BVAR (current_buffer, filename));
-      BVAR (current_buffer, filename) = Qnil;
+      bset_filename (current_buffer, Qnil);
     }
 
   if (pos_byte < GPT_BYTE)
@@ -2986,7 +2977,7 @@ Both characters must have the same length of multi-byte form.  */)
                INC_POS (pos_byte_next);
 
              if (! NILP (noundo))
-               BVAR (current_buffer, undo_list) = tem;
+               bset_undo_list (current_buffer, tem);
 
              UNGCPRO;
            }
@@ -3088,8 +3079,8 @@ It returns the number of characters changed.  */)
   int cnt;                     /* Number of changes made. */
   ptrdiff_t size;              /* Size of translate table. */
   ptrdiff_t pos, pos_byte, end_pos;
-  int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
-  int string_multibyte IF_LINT (= 0);
+  bool multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
+  bool string_multibyte IF_LINT (= 0);
 
   validate_region (&start, &end);
   if (CHAR_TABLE_P (table))
@@ -3379,6 +3370,10 @@ save_restriction_restore (Lisp_Object data)
 
          buf->clip_changed = 1; /* Remember that the narrowing changed. */
        }
+      /* These aren't needed anymore, so don't wait for GC.  */
+      free_marker (XCAR (data));
+      free_marker (XCDR (data));
+      free_cons (XCONS (data));
     }
   else
     /* A buffer, which means that there was no old restriction.  */
@@ -3615,9 +3610,13 @@ where flags is [+ #-0]+, width is [0-9]+, and precision is .[0-9]+
 The + flag character inserts a + before any positive number, while a
 space inserts a space before any positive number; these flags only
 affect %d, %e, %f, and %g sequences, and the + flag takes precedence.
+The - and 0 flags affect the width specifier, as described below.
+
 The # flag means to use an alternate display form for %o, %x, %X, %e,
-%f, and %g sequences.  The - and 0 flags affect the width specifier,
-as described below.
+%f, and %g sequences: for %o, it ensures that the result begins with
+\"0\"; for %x and %X, it prefixes the result with \"0x\" or \"0X\";
+for %e, %f, and %g, it causes a decimal point to be included even if
+the precision is zero.
 
 The width specifier supplies a lower limit for the length of the
 printed representation.  The padding, if any, normally goes on the
@@ -3641,20 +3640,20 @@ usage: (format STRING &rest OBJECTS)  */)
   ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1;
   char *p;
   Lisp_Object buf_save_value IF_LINT (= {0});
-  register char *format, *end, *format_start;
+  char *format, *end, *format_start;
   ptrdiff_t formatlen, nchars;
-  /* Nonzero if the format is multibyte.  */
-  int multibyte_format = 0;
-  /* Nonzero if the output should be a multibyte string,
+  /* True if the format is multibyte.  */
+  bool multibyte_format = 0;
+  /* True if the output should be a multibyte string,
      which is true if any of the inputs is one.  */
-  int multibyte = 0;
+  bool multibyte = 0;
   /* When we make a multibyte string, we must pay attention to the
      byte combining problem, i.e., a byte may be combined with a
      multibyte character of the previous string.  This flag tells if we
      must consider such a situation or not.  */
-  int maybe_combine_byte;
+  bool maybe_combine_byte;
   Lisp_Object val;
-  int arg_intervals = 0;
+  bool arg_intervals = 0;
   USE_SAFE_ALLOCA;
 
   /* discarded[I] is 1 if byte I of the format
@@ -3670,8 +3669,8 @@ usage: (format STRING &rest OBJECTS)  */)
   struct info
   {
     ptrdiff_t start, end;
-    int converted_to_string;
-    int intervals;
+    unsigned converted_to_string : 1;
+    unsigned intervals : 1;
   } *info = 0;
 
   /* It should not be necessary to GCPRO ARGS, because
@@ -3686,7 +3685,7 @@ usage: (format STRING &rest OBJECTS)  */)
     ptrdiff_t i;
     if ((SIZE_MAX - formatlen) / sizeof (struct info) <= nargs)
       memory_full (SIZE_MAX);
-    SAFE_ALLOCA (info, struct info *, (nargs + 1) * sizeof *info + formatlen);
+    info = SAFE_ALLOCA ((nargs + 1) * sizeof *info + formatlen);
     discarded = (char *) &info[nargs + 1];
     for (i = 0; i < nargs + 1; i++)
       {
@@ -3748,13 +3747,13 @@ usage: (format STRING &rest OBJECTS)  */)
             digits to print after the '.' for floats, or the max.
             number of chars to print from a string.  */
 
-         int minus_flag = 0;
-         int  plus_flag = 0;
-         int space_flag = 0;
-         int sharp_flag = 0;
-         int  zero_flag = 0;
+         bool minus_flag = 0;
+         bool  plus_flag = 0;
+         bool space_flag = 0;
+         bool sharp_flag = 0;
+         bool  zero_flag = 0;
          ptrdiff_t field_width;
-         int precision_given;
+         bool precision_given;
          uintmax_t precision = UINTMAX_MAX;
          char *num_end;
          char conversion;
@@ -3933,7 +3932,7 @@ usage: (format STRING &rest OBJECTS)  */)
 
                  /* If this argument has text properties, record where
                     in the result string it appears.  */
-                 if (STRING_INTERVALS (args[n]))
+                 if (string_intervals (args[n]))
                    info[n].intervals = arg_intervals = 1;
 
                  continue;
@@ -4134,7 +4133,7 @@ usage: (format STRING &rest OBJECTS)  */)
                   char *src = sprintf_buf;
                  char src0 = src[0];
                  int exponent_bytes = 0;
-                 int signedp = src0 == '-' || src0 == '+' || src0 == ' ';
+                 bool signedp = src0 == '-' || src0 == '+' || src0 == ' ';
                  int significand_bytes;
                  if (zero_flag
                      && ((src[signedp] >= '0' && src[signedp] <= '9')
@@ -4264,7 +4263,7 @@ usage: (format STRING &rest OBJECTS)  */)
     }
 
   if (bufsize < p - buf)
-    abort ();
+    emacs_abort ();
 
   if (maybe_combine_byte)
     nchars = multibyte_chars_in_text ((unsigned char *) buf, p - buf);
@@ -4277,7 +4276,7 @@ usage: (format STRING &rest OBJECTS)  */)
      arguments has text properties, set up text properties of the
      result string.  */
 
-  if (STRING_INTERVALS (args[0]) || arg_intervals)
+  if (string_intervals (args[0]) || arg_intervals)
     {
       Lisp_Object len, new_len, props;
       struct gcpro gcpro1;
@@ -4527,7 +4526,7 @@ Transposing beyond buffer boundaries is an error.  */)
   Lisp_Object buf;
 
   XSETBUFFER (buf, current_buffer);
-  cur_intv = BUF_INTERVALS (current_buffer);
+  cur_intv = buffer_intervals (current_buffer);
 
   validate_region (&startr1, &endr1);
   validate_region (&startr2, &endr2);
@@ -4604,7 +4603,7 @@ Transposing beyond buffer boundaries is an error.  */)
                                     len1_byte, end2, start2_byte + len2_byte)
          || count_combining_after (BYTE_POS_ADDR (start1_byte),
                                    len1_byte, end2, start2_byte + len2_byte))
-       abort ();
+       emacs_abort ();
     }
   else
     {
@@ -4616,7 +4615,7 @@ Transposing beyond buffer boundaries is an error.  */)
                                    len2_byte, end1, start1_byte + len1_byte)
          || count_combining_after (BYTE_POS_ADDR (start1_byte),
                                    len1_byte, end2, start2_byte + len2_byte))
-       abort ();
+       emacs_abort ();
     }
 #endif
 
@@ -4637,7 +4636,7 @@ Transposing beyond buffer boundaries is an error.  */)
       /* Don't use Fset_text_properties: that can cause GC, which can
         clobber objects stored in the tmp_intervals.  */
       tmp_interval3 = validate_interval_range (buf, &startr1, &endr2, 0);
-      if (!NULL_INTERVAL_P (tmp_interval3))
+      if (tmp_interval3)
        set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
 
       /* First region smaller than second.  */
@@ -4645,7 +4644,7 @@ Transposing beyond buffer boundaries is an error.  */)
         {
          USE_SAFE_ALLOCA;
 
-         SAFE_ALLOCA (temp, unsigned char *, len2_byte);
+         temp = SAFE_ALLOCA (len2_byte);
 
          /* Don't precompute these addresses.  We have to compute them
             at the last minute, because the relocating allocator might
@@ -4663,7 +4662,7 @@ Transposing beyond buffer boundaries is an error.  */)
         {
          USE_SAFE_ALLOCA;
 
-         SAFE_ALLOCA (temp, unsigned char *, len1_byte);
+         temp = SAFE_ALLOCA (len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
           memcpy (temp, start1_addr, len1_byte);
@@ -4696,14 +4695,14 @@ Transposing beyond buffer boundaries is an error.  */)
           tmp_interval2 = copy_intervals (cur_intv, start2, len2);
 
          tmp_interval3 = validate_interval_range (buf, &startr1, &endr1, 0);
-         if (!NULL_INTERVAL_P (tmp_interval3))
+         if (tmp_interval3)
            set_text_properties_1 (startr1, endr1, Qnil, buf, tmp_interval3);
 
          tmp_interval3 = validate_interval_range (buf, &startr2, &endr2, 0);
-         if (!NULL_INTERVAL_P (tmp_interval3))
+         if (tmp_interval3)
            set_text_properties_1 (startr2, endr2, Qnil, buf, tmp_interval3);
 
-         SAFE_ALLOCA (temp, unsigned char *, len1_byte);
+         temp = SAFE_ALLOCA (len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
           memcpy (temp, start1_addr, len1_byte);
@@ -4729,11 +4728,11 @@ Transposing beyond buffer boundaries is an error.  */)
           tmp_interval2 = copy_intervals (cur_intv, start2, len2);
 
          tmp_interval3 = validate_interval_range (buf, &startr1, &endr2, 0);
-         if (!NULL_INTERVAL_P (tmp_interval3))
+         if (tmp_interval3)
            set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
 
          /* holds region 2 */
-         SAFE_ALLOCA (temp, unsigned char *, len2_byte);
+         temp = SAFE_ALLOCA (len2_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
           memcpy (temp, start2_addr, len2_byte);
@@ -4762,11 +4761,11 @@ Transposing beyond buffer boundaries is an error.  */)
           tmp_interval2 = copy_intervals (cur_intv, start2, len2);
 
          tmp_interval3 = validate_interval_range (buf, &startr1, &endr2, 0);
-         if (!NULL_INTERVAL_P (tmp_interval3))
+         if (tmp_interval3)
            set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
 
          /* holds region 1 */
-         SAFE_ALLOCA (temp, unsigned char *, len1_byte);
+         temp = SAFE_ALLOCA (len1_byte);
          start1_addr = BYTE_POS_ADDR (start1_byte);
          start2_addr = BYTE_POS_ADDR (start2_byte);
           memcpy (temp, start1_addr, len1_byte);