Thu Nov 3 10:12:58 2011 UTC ()
Use memmove as we are effectively moving memory from left to right so
that the use=foo capability is removed when merging foo.


(roy)
diff -r1.10 -r1.11 src/usr.bin/tic/tic.c

cvs diff -r1.10 -r1.11 src/usr.bin/tic/tic.c (expand / switch to unified diff)

--- src/usr.bin/tic/tic.c 2010/02/22 23:05:39 1.10
+++ src/usr.bin/tic/tic.c 2011/11/03 10:12:57 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tic.c,v 1.10 2010/02/22 23:05:39 roy Exp $ */ 1/* $NetBSD: tic.c,v 1.11 2011/11/03 10:12:57 roy Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Roy Marples. 7 * by Roy Marples.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#if HAVE_NBTOOL_CONFIG_H 30#if HAVE_NBTOOL_CONFIG_H
31#include "nbtool_config.h" 31#include "nbtool_config.h"
32#endif 32#endif
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__RCSID("$NetBSD: tic.c,v 1.10 2010/02/22 23:05:39 roy Exp $"); 35__RCSID("$NetBSD: tic.c,v 1.11 2011/11/03 10:12:57 roy Exp $");
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38 38
39#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H 39#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
40#include <sys/endian.h> 40#include <sys/endian.h>
41#endif 41#endif
42 42
43#include <ctype.h> 43#include <ctype.h>
44#include <err.h> 44#include <err.h>
45#include <errno.h> 45#include <errno.h>
46#include <getopt.h> 46#include <getopt.h>
47#include <limits.h> 47#include <limits.h>
48#include <fcntl.h> 48#include <fcntl.h>
@@ -347,27 +347,27 @@ merge_use(int flags) @@ -347,27 +347,27 @@ merge_use(int flags)
347 remove: 347 remove:
348 /* The pointers may have changed, find the use again */ 348 /* The pointers may have changed, find the use again */
349 cap = _ti_find_extra(&rtic->extras, "use"); 349 cap = _ti_find_extra(&rtic->extras, "use");
350 if (cap == NULL) 350 if (cap == NULL)
351 dowarn("%s: use no longer exists - impossible", 351 dowarn("%s: use no longer exists - impossible",
352 rtic->name); 352 rtic->name);
353 else { 353 else {
354 scap = cap - (4 + sizeof(uint16_t)); 354 scap = cap - (4 + sizeof(uint16_t));
355 cap++; 355 cap++;
356 num = le16dec(cap); 356 num = le16dec(cap);
357 cap += sizeof(uint16_t) + num; 357 cap += sizeof(uint16_t) + num;
358 memn = rtic->extras.bufpos - 358 memn = rtic->extras.bufpos -
359 (cap - rtic->extras.buf); 359 (cap - rtic->extras.buf);
360 memcpy(scap, cap, memn); 360 memmove(scap, cap, memn);
361 rtic->extras.bufpos -= cap - scap; 361 rtic->extras.bufpos -= cap - scap;
362 cap = scap; 362 cap = scap;
363 rtic->extras.entries--; 363 rtic->extras.entries--;
364 merged++; 364 merged++;
365 } 365 }
366 } 366 }
367 } 367 }
368 368
369 if (merged == 0 && skipped != 0) 369 if (merged == 0 && skipped != 0)
370 dowarn("circular use detected"); 370 dowarn("circular use detected");
371 return merged; 371 return merged;
372} 372}
373 373