~ubuntu-branches/ubuntu/raring/avr-libc/raring-proposed

« back to all changes in this revision

Viewing changes to libc/stdlib/realloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.1.8 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091031115210-x0mlijnegkce86fk
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
29
  POSSIBILITY OF SUCH DAMAGE.
30
30
*/
31
 
/* $Id: realloc.c,v 1.4 2005/02/08 20:34:17 joerg_wunsch Exp $ */
 
31
/* $Id: realloc.c,v 1.4.4.2 2009/04/01 23:12:11 arcanum Exp $ */
32
32
 
33
33
#include <stdlib.h>
34
34
#include <string.h>
35
 
 
 
35
#include "sectionname.h"
36
36
#include "stdlib_private.h"
37
37
 
38
38
#ifndef MALLOC_TEST
39
39
#include <avr/io.h>
40
40
#endif
41
41
 
 
42
ATTRIBUTE_CLIB_SECTION
42
43
void *
43
44
realloc(void *ptr, size_t len)
44
45
{
59
60
        if (cp < cp1)
60
61
                /* Pointer wrapped across top of RAM, fail. */
61
62
                return 0;
62
 
        fp2 = (struct __freelist *)cp;
 
63
        fp2 = (struct __freelist *)(cp - sizeof(size_t));
63
64
 
64
65
        /*
65
66
         * See whether we are growing or shrinking.  When shrinking,
84
85
         * If we get here, we are growing.  First, see whether there
85
86
         * is space in the free list on top of our current chunk.
86
87
         */
87
 
        incr = len - fp1->sz - sizeof(size_t);
 
88
        incr = len - fp1->sz;
88
89
        cp = (char *)ptr + fp1->sz;
89
 
        fp2 = (struct __freelist *)cp;
90
90
        for (s = 0, ofp3 = 0, fp3 = __flp;
91
91
             fp3;
92
92
             ofp3 = fp3, fp3 = fp3->nx) {
93
93
                if (fp3 == fp2 && fp3->sz >= incr) {
94
94
                        /* found something that fits */
95
 
                        if (incr <= fp3->sz &&
96
 
                            incr > fp3->sz - sizeof(struct __freelist)) {
 
95
                        if (incr <= fp3->sz + sizeof(size_t)) {
97
96
                                /* it just fits, so use it entirely */
98
97
                                fp1->sz += fp3->sz + sizeof(size_t);
99
98
                                if (ofp3)
104
103
                        }
105
104
                        /* split off a new freelist entry */
106
105
                        cp = (char *)ptr + len;
107
 
                        fp2 = (struct __freelist *)cp;
 
106
                        fp2 = (struct __freelist *)(cp - sizeof(size_t));
108
107
                        fp2->nx = fp3->nx;
109
108
                        fp2->sz = fp3->sz - incr - sizeof(size_t);
110
109
                        if (ofp3)