]> code.delx.au - gnu-emacs/commitdiff
Prefer assignment to memcpy when either will do.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Sep 2012 22:59:50 +0000 (15:59 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Sep 2012 22:59:50 +0000 (15:59 -0700)
* lib-src/pop.c (socket_connection) [HAVE_GETADDRINFO]:
* src/bidi.c (bidi_push_it, bidi_pop_it):
* src/fns.c (copy_hash_table):
* src/image.c (define_image_type):
* src/keyboard.c (kbd_buffer_store_event_hold):
* src/process.c (Fprocess_send_eof):
* src/xfaces.c (x_create_gc) [HAVE_NS]:
* src/xgselect.c (xg_select):
Use assignment, not memcpy, as either will do here, and assignment is
more likely to catch type errors.

lib-src/ChangeLog
lib-src/pop.c
src/ChangeLog
src/bidi.c
src/fns.c
src/image.c
src/keyboard.c
src/process.c
src/xfaces.c
src/xgselect.c

index 35190fd2a8f3e47e5581be224d7ba3af8bbe3565..f584665770755380bcc52eeeab884ebe6070320a 100644 (file)
@@ -1,3 +1,8 @@
+2012-09-11  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * pop.c (socket_connection) [HAVE_GETADDRINFO]:
+       Prefer assignment to memcpy when either will do.
+
 2012-08-31  Andreas Schwab  <schwab@linux-m68k.org>
 
        * etags.c (consider_token): Always zero-terminate token buffer.
index 74054e0e1b13589b1159069ecfa134cd07f424f2..bfbcb8c94663bfc73e21e582b006483a36820708 100644 (file)
@@ -1083,7 +1083,7 @@ socket_connection (char *host, int flags)
           if (it->ai_addrlen == sizeof (addr))
             {
               struct sockaddr_in *in_a = (struct sockaddr_in *) it->ai_addr;
-              memcpy (&addr.sin_addr, &in_a->sin_addr, sizeof (addr.sin_addr));
+              addr.sin_addr = in_a->sin_addr;
               if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr)))
                 break;
             }
index 2b0686cc49e2da26fde7deb0dd3ce191809b0e4a..74a12b94b08afb92dae830b0a904f3e44950fe0c 100644 (file)
@@ -1,5 +1,14 @@
 2012-09-11  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * bidi.c (bidi_push_it, bidi_pop_it):
+       * fns.c (copy_hash_table):
+       * image.c (define_image_type):
+       * keyboard.c (kbd_buffer_store_event_hold):
+       * process.c (Fprocess_send_eof):
+       * xfaces.c (x_create_gc) [HAVE_NS]:
+       * xgselect.c (xg_select):
+       Prefer assignment to memcpy when either will do.
+
        * alloc.c (discard_killed_buffers): Tune and simplify a bit.
        Use pointer-to-a-pointer to simplify and avoid a NILP check each
        time an item is removed.  No need to mark this function 'inline';
index 73fec3533a490c1364df02f5f3ebd3007cfd998f..4186a46e19e819e09f58dd812253c25ee630ec7e 100644 (file)
@@ -612,7 +612,7 @@ bidi_push_it (struct bidi_it *bidi_it)
   /* Save the current iterator state in its entirety after the last
      used cache slot.  */
   bidi_cache_ensure_space (bidi_cache_idx);
-  memcpy (&bidi_cache[bidi_cache_idx++], bidi_it, sizeof (struct bidi_it));
+  bidi_cache[bidi_cache_idx++] = *bidi_it;
 
   /* Push the current cache start onto the stack.  */
   eassert (bidi_cache_sp < IT_STACK_SIZE);
@@ -636,7 +636,7 @@ bidi_pop_it (struct bidi_it *bidi_it)
   bidi_cache_idx = bidi_cache_start - 1;
 
   /* Restore the bidi iterator state saved in the cache.  */
-  memcpy (bidi_it, &bidi_cache[bidi_cache_idx], sizeof (struct bidi_it));
+  *bidi_it = bidi_cache[bidi_cache_idx];
 
   /* Pop the previous cache start from the stack.  */
   if (bidi_cache_sp <= 0)
index 95450c5e911dc5eb89aa2d8eeafdb0fb877e9a1d..91dc66391509fbb97f410b07d0b0b3f760bb6b8f 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -3680,7 +3680,7 @@ copy_hash_table (struct Lisp_Hash_Table *h1)
 
   h2 = allocate_hash_table ();
   next = h2->header.next.vector;
-  memcpy (h2, h1, sizeof *h2);
+  *h2 = *h1;
   h2->header.next.vector = next;
   h2->key_and_value = Fcopy_sequence (h1->key_and_value);
   h2->hash = Fcopy_sequence (h1->hash);
index 4ec6105d72db693f1e5b93d293c20e71eba9f03a..52598a41ab9cfd997abe397bc601809e36ba6484 100644 (file)
@@ -593,7 +593,7 @@ define_image_type (struct image_type *type, int loaded)
       /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
          The initialized data segment is read-only.  */
       struct image_type *p = xmalloc (sizeof *p);
-      memcpy (p, type, sizeof *p);
+      *p = *type;
       p->next = image_types;
       image_types = p;
       success = Qt;
index d26cf35e1082b322555fde0250fcbf14ab6b95ac..42c67f68edee37d921d241f94674bad0097dcd51 100644 (file)
@@ -3602,7 +3602,7 @@ kbd_buffer_store_event_hold (register struct input_event *event,
 
          if (hold_quit)
            {
-             memcpy (hold_quit, event, sizeof (*event));
+             *hold_quit = *event;
              return;
            }
 
index 0ae68567d6bab3b46d190cefb43614f698d33d11..f80b5e80c76abca2ca962e3d61a3576c1aff8f55 100644 (file)
@@ -6367,9 +6367,8 @@ process has been transmitted to the serial port.  */)
       if (!proc_encode_coding_system[new_outfd])
        proc_encode_coding_system[new_outfd]
          = xmalloc (sizeof (struct coding_system));
-      memcpy (proc_encode_coding_system[new_outfd],
-             proc_encode_coding_system[old_outfd],
-             sizeof (struct coding_system));
+      *proc_encode_coding_system[new_outfd]
+       = *proc_encode_coding_system[old_outfd];
       memset (proc_encode_coding_system[old_outfd], 0,
              sizeof (struct coding_system));
 
index aee5158036fd85ea74b40699ebdd6528f1c68447..c113c1a37b727324d96530d46381a075398035ae 100644 (file)
@@ -661,7 +661,7 @@ x_create_gc (struct frame *f,
             XGCValues *xgcv)
 {
   GC gc = xmalloc (sizeof *gc);
-  memcpy (gc, xgcv, sizeof (XGCValues));
+  *gc = *xgcv;
   return gc;
 }
 
index 0c00d815820b0e191fc91471d8372bee5ca8e097..5f4c7edfb79b05f9aae23582572fdb210d459088 100644 (file)
@@ -49,9 +49,9 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
         && g_main_context_pending (context = g_main_context_default ())))
     return pselect (fds_lim, rfds, wfds, efds, timeout, sigmask);
 
-  if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds));
+  if (rfds) all_rfds = *rfds;
   else FD_ZERO (&all_rfds);
-  if (wfds) memcpy (&all_wfds, wfds, sizeof (all_rfds));
+  if (wfds) all_wfds = *wfds;
   else FD_ZERO (&all_wfds);
 
   n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,