Use BSET for write access to Lisp_Object members of struct buffer.
[bpt/emacs.git] / src / editfns.c
index 63e7700..60f61d0 100644 (file)
@@ -59,10 +59,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
@@ -79,7 +75,6 @@ static int tm_diff (struct tm *, struct tm *);
 static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
 
 static Lisp_Object Qbuffer_access_fontify_functions;
-static Lisp_Object Fuser_full_name (Lisp_Object);
 
 /* Symbol for the text property used to mark fields.  */
 
@@ -206,15 +201,6 @@ DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
     XSETFASTINT (val, 0);
   return val;
 }
-\f
-static Lisp_Object
-buildmark (ptrdiff_t charpos, ptrdiff_t bytepos)
-{
-  register Lisp_Object mark;
-  mark = Fmake_marker ();
-  set_marker_both (mark, Qnil, charpos, bytepos);
-  return mark;
-}
 
 DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
        doc: /* Return value of point, as an integer.
@@ -230,7 +216,7 @@ DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
        doc: /* Return value of point, as a marker object.  */)
   (void)
 {
-  return buildmark (PT, PT_BYTE);
+  return build_marker (current_buffer, PT, PT_BYTE);
 }
 
 DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
@@ -282,9 +268,10 @@ region_limit (int beginningp)
   if (NILP (m))
     error ("The mark is not set now, so there is no region");
 
-  if ((PT < XFASTINT (m)) == (beginningp != 0))
-    m = make_number (PT);
-  return m;
+  /* Clip to the current narrowing (bug#11770).  */
+  return make_number ((PT < XFASTINT (m)) == (beginningp != 0)
+                     ? PT
+                     : clip_to_bounds (BEGV, XFASTINT (m), ZV));
 }
 
 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0,
@@ -323,7 +310,7 @@ overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
   ptrdiff_t startpos, endpos;
   ptrdiff_t idx = 0;
 
-  for (tail = current_buffer->overlays_before; tail; tail = tail->next)
+  for (tail = buffer_get_overlays (NULL, OV_BEFORE); tail; tail = tail->next)
     {
       XSETMISC (overlay, tail);
 
@@ -342,7 +329,7 @@ overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
        }
     }
 
-  for (tail = current_buffer->overlays_after; tail; tail = tail->next)
+  for (tail = buffer_get_overlays (NULL, OV_AFTER); tail; tail = tail->next)
     {
       XSETMISC (overlay, tail);
 
@@ -397,14 +384,14 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
 
       /* First try with room for 40 overlays.  */
       noverlays = 40;
-      overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object));
+      overlay_vec = alloca (noverlays * sizeof *overlay_vec);
       noverlays = overlays_around (posn, overlay_vec, noverlays);
 
       /* If there are more than 40,
         make enough space for all, and try again.  */
       if (noverlays > 40)
        {
-         overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object));
+         overlay_vec = alloca (noverlays * sizeof *overlay_vec);
          noverlays = overlays_around (posn, overlay_vec, noverlays);
        }
       noverlays = sort_overlays (overlay_vec, noverlays, NULL);
@@ -895,7 +882,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 (current_buffer, mark_active, tem);
 
   /* If mark is active now, and either was not active
      or was at a different place, run the activate hook.  */
@@ -1003,7 +990,7 @@ DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0,
 This is the beginning, unless narrowing (a buffer restriction) is in effect.  */)
   (void)
 {
-  return buildmark (BEGV, BEGV_BYTE);
+  return build_marker (current_buffer, BEGV, BEGV_BYTE);
 }
 
 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0,
@@ -1023,7 +1010,7 @@ This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
 is in effect, in which case it is less.  */)
   (void)
 {
-  return buildmark (ZV, ZV_BYTE);
+  return build_marker (current_buffer, ZV, ZV_BYTE);
 }
 
 DEFUN ("gap-position", Fgap_position, Sgap_position, 0, 0, 0,
@@ -1330,7 +1317,7 @@ name, or nil if there is no such user.  */)
       Lisp_Object login;
 
       login = Fuser_login_name (make_number (pw->pw_uid));
-      r = (char *) alloca (strlen (p) + SCHARS (login) + 1);
+      r = alloca (strlen (p) + SCHARS (login) + 1);
       memcpy (r, p, q - p);
       r[q - p] = 0;
       strcat (r, SSDATA (login));
@@ -1417,10 +1404,7 @@ least significant 16 bits.  USEC and PSEC are the microsecond and
 picosecond counts.  */)
   (void)
 {
-  EMACS_TIME t;
-
-  EMACS_GET_TIME (t);
-  return make_lisp_time (t);
+  return make_lisp_time (current_emacs_time ());
 }
 
 DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
@@ -1437,7 +1421,6 @@ does the same thing as `current-time'.  */)
   struct rusage usage;
   time_t secs;
   int usecs;
-  EMACS_TIME t;
 
   if (getrusage (RUSAGE_SELF, &usage) < 0)
     /* This shouldn't happen.  What action is appropriate?  */
@@ -1451,8 +1434,7 @@ does the same thing as `current-time'.  */)
       usecs -= 1000000;
       secs++;
     }
-  EMACS_SET_SECS_USECS (t, secs, usecs);
-  return make_lisp_time (t);
+  return make_lisp_time (make_emacs_time (secs, usecs * 1000));
 #else /* ! HAVE_GETRUSAGE  */
 #ifdef WINDOWSNT
   return w32_get_internal_run_time ();
@@ -1530,16 +1512,20 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
 }
 
 /* From the time components HIGH, LOW, USEC and PSEC taken from a Lisp
-   list, generate the corresponding EMACS_TIME value *RESULT, and
-   if RESULT_PSEC is not null store into *RESULT_PSEC the
-   (nonnegative) difference in picoseconds between the input time and
-   the returned time.  Return nonzero if successful.  */
+   list, generate the corresponding time value.
+
+   If RESULT is not null, store into *RESULT the converted time;
+   this can fail if the converted time does not fit into EMACS_TIME.
+   If *DRESULT is not null, store into *DRESULT the number of
+   seconds since the start of the POSIX Epoch.
+
+   Return nonzero if successful.  */
 int
 decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
-                       Lisp_Object psec, EMACS_TIME *result, int *result_psec)
+                       Lisp_Object psec,
+                       EMACS_TIME *result, double *dresult)
 {
   EMACS_INT hi, lo, us, ps;
-  time_t sec;
   if (! (INTEGERP (high) && INTEGERP (low)
         && INTEGERP (usec) && INTEGERP (psec)))
     return 0;
@@ -1557,43 +1543,54 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
   us = us % 1000000 + 1000000 * (us % 1000000 < 0);
   lo &= (1 << 16) - 1;
 
-  /* Check for overflow in the highest-order component.  */
-  if (! ((TYPE_SIGNED (time_t) ? TIME_T_MIN >> 16 <= hi : 0 <= hi)
-        && hi <= TIME_T_MAX >> 16))
-    return 0;
+  if (result)
+    {
+      if ((TYPE_SIGNED (time_t) ? TIME_T_MIN >> 16 <= hi : 0 <= hi)
+         && hi <= TIME_T_MAX >> 16)
+       {
+         /* Return the greatest representable time that is not greater
+            than the requested time.  */
+         time_t sec = hi;
+         *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000);
+       }
+      else
+       {
+         /* Overflow in the highest-order component.  */
+         return 0;
+       }
+    }
+
+  if (dresult)
+    *dresult = (us * 1e6 + ps) / 1e12 + lo + hi * 65536.0;
 
-  sec = hi;
-  EMACS_SET_SECS_NSECS (*result, (sec << 16) + lo, us * 1000 + ps / 1000);
-  if (result_psec)
-    *result_psec = ps % 1000;
   return 1;
 }
 
 /* Decode a Lisp list SPECIFIED_TIME that represents a time.
    If SPECIFIED_TIME is nil, use the current time.
-   Round the time down to the nearest EMACS_TIME value, and
-   if PPSEC is not null store into *PPSEC the (nonnegative) difference in
-   picoseconds between the input time and the returned time.
+
+   Round the time down to the nearest EMACS_TIME value.
    Return seconds since the Epoch.
    Signal an error if unsuccessful.  */
 EMACS_TIME
-lisp_time_argument (Lisp_Object specified_time, int *ppsec)
+lisp_time_argument (Lisp_Object specified_time)
 {
   EMACS_TIME t;
   if (NILP (specified_time))
-    EMACS_GET_TIME (t);
+    t = current_emacs_time ();
   else
     {
       Lisp_Object high, low, usec, psec;
       if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
-            && decode_time_components (high, low, usec, psec, &t, ppsec)))
+            && decode_time_components (high, low, usec, psec, &t, 0)))
        error ("Invalid time specification");
     }
   return t;
 }
 
 /* Like lisp_time_argument, except decode only the seconds part,
-   and do not check the subseconds part, and always round down.  */
+   do not allow out-of-range time stamps, do not check the subseconds part,
+   and always round down.  */
 static time_t
 lisp_seconds_argument (Lisp_Object specified_time)
 {
@@ -1625,12 +1622,20 @@ If precise time stamps are required, use either `current-time',
 or (if you need time as a string) `format-time-string'.  */)
   (Lisp_Object specified_time)
 {
-  int psec;
-  EMACS_TIME t = lisp_time_argument (specified_time, &psec);
-  double ps = (1000 * 1000 * 1000 <= INTMAX_MAX / 1000
-              ? EMACS_NSECS (t) * (intmax_t) 1000 + psec
-              : EMACS_NSECS (t) * 1e3 + psec);
-  return make_float (EMACS_SECS (t) + ps / 1e12);
+  double t;
+  if (NILP (specified_time))
+    {
+      EMACS_TIME now = current_emacs_time ();
+      t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9;
+    }
+  else
+    {
+      Lisp_Object high, low, usec, psec;
+      if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
+            && decode_time_components (high, low, usec, psec, 0, &t)))
+       error ("Invalid time specification");
+    }
+  return make_float (t);
 }
 
 /* Write information into buffer S of size MAXSIZE, according to the
@@ -1739,7 +1744,7 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".
 usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL)  */)
   (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal)
 {
-  EMACS_TIME t = lisp_time_argument (timeval, 0);
+  EMACS_TIME t = lisp_time_argument (timeval);
   struct tm tm;
 
   CHECK_STRING (format_string);
@@ -1764,11 +1769,12 @@ format_time_string (char const *format, ptrdiff_t formatlen,
 
   while (1)
     {
+      time_t *taddr = emacs_secs_addr (&t);
       BLOCK_INPUT;
 
       synchronize_system_time_locale ();
 
-      tm = ut ? gmtime (EMACS_SECS_ADDR (t)) : localtime (EMACS_SECS_ADDR (t));
+      tm = ut ? gmtime (taddr) : localtime (taddr);
       if (! tm)
        {
          UNBLOCK_INPUT;
@@ -1787,7 +1793,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;
@@ -1899,7 +1905,7 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)  */)
   tm.tm_isdst = -1;
 
   if (CONSP (zone))
-    zone = Fcar (zone);
+    zone = XCAR (zone);
   if (NILP (zone))
     {
       BLOCK_INPUT;
@@ -2049,10 +2055,10 @@ the data it can't find.  */)
   Lisp_Object zone_offset, zone_name;
 
   zone_offset = Qnil;
-  EMACS_SET_SECS_NSECS (value, lisp_seconds_argument (specified_time), 0);
+  value = make_emacs_time (lisp_seconds_argument (specified_time), 0);
   zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm);
   BLOCK_INPUT;
-  t = gmtime (EMACS_SECS_ADDR (value));
+  t = gmtime (emacs_secs_addr (&value));
   if (t)
     offset = tm_diff (&localtm, t);
   UNBLOCK_INPUT;
@@ -2066,8 +2072,9 @@ the data it can't find.  */)
          int m = offset / 60;
          int am = offset < 0 ? - m : m;
          char buf[sizeof "+00" + INT_STRLEN_BOUND (int)];
-         sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
-         zone_name = build_string (buf);
+         zone_name = make_formatted_string (buf, "%c%02d%02d",
+                                            (offset < 0 ? '-' : '+'),
+                                            am / 60, am % 60);
        }
     }
 
@@ -2154,8 +2161,8 @@ set_time_zone_rule (const char *tzstring)
   for (from = environ; *from; from++)
     continue;
   envptrs = from - environ + 2;
-  newenv = to = (char **) xmalloc (envptrs * sizeof (char *)
-                                  + (tzstring ? strlen (tzstring) + 4 : 0));
+  newenv = to = xmalloc (envptrs * sizeof *newenv
+                        + (tzstring ? strlen (tzstring) + 4 : 0));
 
   /* Add TZSTRING to the end of environ, as a value for TZ.  */
   if (tzstring)
@@ -2357,11 +2364,35 @@ usage: (insert-before-markers-and-inherit &rest ARGS)  */)
   return Qnil;
 }
 \f
-DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
+DEFUN ("insert-char", Finsert_char, Sinsert_char, 1, 3,
+       "(list (read-char-by-name \"Insert character (Unicode name or hex): \")\
+        (prefix-numeric-value current-prefix-arg)\
+        t))",
        doc: /* Insert COUNT copies of CHARACTER.
-Point, and before-insertion markers, are relocated as in the function `insert'.
-The optional third arg INHERIT, if non-nil, says to inherit text properties
-from adjoining text, if those properties are sticky.  */)
+Interactively, prompt for CHARACTER.  You can specify CHARACTER in one
+of these ways:
+
+ - As its Unicode character name, e.g. \"LATIN SMALL LETTER A\".
+   Completion is available; if you type a substring of the name
+   preceded by an asterisk `*', Emacs shows all names which include
+   that substring, not necessarily at the beginning of the name.
+
+ - As a hexadecimal code point, e.g. 263A.  Note that code points in
+   Emacs are equivalent to Unicode up to 10FFFF (which is the limit of
+   the Unicode code space).
+
+ - As a code point with a radix specified with #, e.g. #o21430
+   (octal), #x2318 (hex), or #10r8984 (decimal).
+
+If called interactively, COUNT is given by the prefix argument.  If
+omitted or nil, it defaults to 1.
+
+Inserting the character(s) relocates point and before-insertion
+markers in the same ways as the function `insert'.
+
+The optional third argument INHERIT, if non-nil, says to inherit text
+properties from adjoining text, if those properties are sticky.  If
+called interactively, INHERIT is t.  */)
   (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
 {
   int i, stringlen;
@@ -2371,6 +2402,8 @@ from adjoining text, if those properties are sticky.  */)
   char string[4000];
 
   CHECK_CHARACTER (character);
+  if (NILP (count))
+    XSETFASTINT (count, 1);
   CHECK_NUMBER (count);
   c = XFASTINT (character);
 
@@ -2783,13 +2816,13 @@ 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;
+  return BSET (current_buffer, undo_list, arg);
 }
 
 static Lisp_Object
 subst_char_in_region_unwind_1 (Lisp_Object arg)
 {
-  return BVAR (current_buffer, filename) = arg;
+  return BSET (current_buffer, filename, arg);
 }
 
 DEFUN ("subst-char-in-region", Fsubst_char_in_region,
@@ -2863,11 +2896,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 (current_buffer, undo_list, 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 (current_buffer, filename, Qnil);
     }
 
   if (pos_byte < GPT_BYTE)
@@ -2949,7 +2982,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 (current_buffer, undo_list, tem);
 
              UNGCPRO;
            }
@@ -3289,8 +3322,8 @@ save_restriction_save (void)
     {
       Lisp_Object beg, end;
 
-      beg = buildmark (BEGV, BEGV_BYTE);
-      end = buildmark (ZV, ZV_BYTE);
+      beg = build_marker (current_buffer, BEGV, BEGV_BYTE);
+      end = build_marker (current_buffer, ZV, ZV_BYTE);
 
       /* END must move forward if text is inserted at its exact location.  */
       XMARKER (end)->insertion_type = 1;
@@ -3342,6 +3375,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.  */
@@ -3472,15 +3509,11 @@ usage: (message-box FORMAT-STRING &rest ARGS)  */)
       }
 #endif /* HAVE_MENUS */
       /* Copy the data so that it won't move when we GC.  */
-      if (! message_text)
-       {
-         message_text = (char *)xmalloc (80);
-         message_length = 80;
-       }
       if (SBYTES (val) > message_length)
        {
-         message_text = (char *) xrealloc (message_text, SBYTES (val));
-         message_length = SBYTES (val);
+         ptrdiff_t new_length = SBYTES (val) + 80;
+         message_text = xrealloc (message_text, new_length);
+         message_length = new_length;
        }
       memcpy (message_text, SDATA (val), SBYTES (val));
       message2 (message_text, SBYTES (val),
@@ -3653,7 +3686,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++)
       {
@@ -3900,7 +3933,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_get_intervals (args[n]))
                    info[n].intervals = arg_intervals = 1;
 
                  continue;
@@ -4244,7 +4277,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_get_intervals (args[0]) || arg_intervals)
     {
       Lisp_Object len, new_len, props;
       struct gcpro gcpro1;
@@ -4494,7 +4527,7 @@ Transposing beyond buffer boundaries is an error.  */)
   Lisp_Object buf;
 
   XSETBUFFER (buf, current_buffer);
-  cur_intv = BUF_INTERVALS (current_buffer);
+  cur_intv = buffer_get_intervals (current_buffer);
 
   validate_region (&startr1, &endr1);
   validate_region (&startr2, &endr2);
@@ -4604,7 +4637,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.  */
@@ -4612,7 +4645,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
@@ -4630,7 +4663,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);
@@ -4663,14 +4696,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);
@@ -4696,11 +4729,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);
@@ -4729,11 +4762,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);