]> code.delx.au - gnu-emacs/blobdiff - src/process.c
* window.c: Integer overflow fixes.
[gnu-emacs] / src / process.c
index b3c295cecde3f95865b000965a357505c3f80827..a8088322147c2dbbf29a69b335fee86ecc039076 100644 (file)
@@ -1643,7 +1643,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
 
   XPROCESS (process)->pty_flag = pty_flag;
   XPROCESS (process)->status = Qrun;
-  setup_process_coding_systems (process);
 
   /* Delay interrupts until we have a chance to store
      the new fork's pid in its process structure */
@@ -1678,6 +1677,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
      processes to get their return values scrambled.  */
   XPROCESS (process)->pid = -1;
 
+  /* This must be called after the above line because it may signal an
+     error. */
+  setup_process_coding_systems (process);
+
   BLOCK_INPUT;
 
   {
@@ -3570,45 +3573,39 @@ format; see the description of ADDRESS in `make-network-process'.  */)
   struct ifconf ifconf;
   struct ifreq *ifreq;
   void *buf = NULL;
-  int buf_size = 512, s, i;
+  ptrdiff_t buf_size = 512;
+  int s, i;
   Lisp_Object res;
 
   s = socket (AF_INET, SOCK_STREAM, 0);
   if (s < 0)
     return Qnil;
 
- again:
-  buf_size *= 2;
-  buf = xrealloc(buf, buf_size);
-  if (!buf)
-    {
-      close (s);
-      return Qnil;
-    }
-
-  ifconf.ifc_buf = buf;
-  if (ioctl (s, SIOCGIFCONF, &ifconf))
+  do
     {
-      close (s);
-      xfree (buf);
-      return Qnil;
+      buf = xpalloc (buf, &buf_size, 1, INT_MAX, 1);
+      ifconf.ifc_buf = buf;
+      ifconf.ifc_len = buf_size;
+      if (ioctl (s, SIOCGIFCONF, &ifconf))
+       {
+         close (s);
+         xfree (buf);
+         return Qnil;
+       }
     }
-
-  if (ifconf.ifc_len == buf_size)
-    goto again;
+  while (ifconf.ifc_len == buf_size);
 
   close (s);
 
   res = Qnil;
-  for (ifreq = ifconf.ifc_req;
-       (char *) ifreq < (char *) (ifconf.ifc_req) + ifconf.ifc_len;
-       )
+  ifreq = ifconf.ifc_req;
+  while ((char *) ifreq < (char *) ifconf.ifc_req + ifconf.ifc_len)
     {
       struct ifreq *ifq = ifreq;
 #ifdef HAVE_STRUCT_IFREQ_IFR_ADDR_SA_LEN
-#define SIZEOF_IFREQ(sif)                                               \
-      ((sif)->ifr_addr.sa_len < sizeof(struct sockaddr) ?               \
-       sizeof((*sif)) : sizeof ((sif)->ifr_name) + sif->ifr_addr.sa_len)
+#define SIZEOF_IFREQ(sif)                                              \
+      ((sif)->ifr_addr.sa_len < sizeof (struct sockaddr)               \
+       ? sizeof (*(sif)) : sizeof ((sif)->ifr_name) + (sif)->ifr_addr.sa_len)
 
       int len = SIZEOF_IFREQ (ifq);
 #else
@@ -3616,7 +3613,7 @@ format; see the description of ADDRESS in `make-network-process'.  */)
 #endif
       char namebuf[sizeof (ifq->ifr_name) + 1];
       i += len;
-      ifreq = (struct ifreq*) ((char*) ifreq + len);
+      ifreq = (struct ifreq *) ((char *) ifreq + len);
 
       if (ifq->ifr_addr.sa_family != AF_INET)
        continue;
@@ -3726,7 +3723,8 @@ FLAGS is the current flags of the interface.  */)
   Lisp_Object elt;
   int s;
   int any = 0;
-#if defined(HAVE_GETIFADDRS)
+#if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \
+     && defined HAVE_GETIFADDRS && defined LLADDR)
   struct ifaddrs *ifap;
 #endif
 
@@ -5163,6 +5161,9 @@ read_process_output (Lisp_Object proc, register int channel)
          p->decoding_carryover = coding->carryover_bytes;
        }
       if (SBYTES (text) > 0)
+       /* FIXME: It's wrong to wrap or not based on debug-on-error, and
+          sometimes it's simply wrong to wrap (e.g. when called from
+          accept-process-output).  */
        internal_condition_case_1 (read_process_output_call,
                                   Fcons (outstream,
                                          Fcons (proc, Fcons (text, Qnil))),