comparison libiberty/objalloc.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents a06113de4d67
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* objalloc.c -- routines to allocate memory for objects 1 /* objalloc.c -- routines to allocate memory for objects
2 Copyright 1997 Free Software Foundation, Inc. 2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Solutions. 3 Written by Ian Lance Taylor, Cygnus Solutions.
4 4
5 This program is free software; you can redistribute it and/or modify it 5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the 6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any 7 Free Software Foundation; either version 2, or (at your option) any
110 } 110 }
111 111
112 /* Allocate space from an objalloc structure. */ 112 /* Allocate space from an objalloc structure. */
113 113
114 PTR 114 PTR
115 _objalloc_alloc (struct objalloc *o, unsigned long len) 115 _objalloc_alloc (struct objalloc *o, unsigned long original_len)
116 { 116 {
117 unsigned long len = original_len;
118
117 /* We avoid confusion from zero sized objects by always allocating 119 /* We avoid confusion from zero sized objects by always allocating
118 at least 1 byte. */ 120 at least 1 byte. */
119 if (len == 0) 121 if (len == 0)
120 len = 1; 122 len = 1;
121 123
122 len = (len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1); 124 len = (len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1);
125
126 /* Check for overflow in the alignment operation above and the
127 malloc argument below. */
128 if (len + CHUNK_HEADER_SIZE < original_len)
129 return NULL;
123 130
124 if (len <= o->current_space) 131 if (len <= o->current_space)
125 { 132 {
126 o->current_ptr += len; 133 o->current_ptr += len;
127 o->current_space -= len; 134 o->current_space -= len;