aboutsummaryrefslogtreecommitdiff
path: root/gas/frags.c
diff options
context:
space:
mode:
authorTristan Gingold <gingold@adacore.com>2011-08-01 08:05:49 +0000
committerTristan Gingold <gingold@adacore.com>2011-08-01 08:05:49 +0000
commit8d8385cfb84fae7b0959b77fe287d97795415194 (patch)
tree301de171151ecef605cecd9ccb79728f80c60763 /gas/frags.c
parentd2421a70c155d87281b215b0fdbbb6e02e563da0 (diff)
downloadgdb-8d8385cfb84fae7b0959b77fe287d97795415194.zip
gdb-8d8385cfb84fae7b0959b77fe287d97795415194.tar.gz
gdb-8d8385cfb84fae7b0959b77fe287d97795415194.tar.bz2
2011-08-01 Tristan Gingold <gingold@adacore.com>
* frags.c (frag_grow): Simplify the code.
Diffstat (limited to 'gas/frags.c')
-rw-r--r--gas/frags.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/gas/frags.c b/gas/frags.c
index a6553bb..fb3c02d 100644
--- a/gas/frags.c
+++ b/gas/frags.c
@@ -85,31 +85,38 @@ frag_grow (unsigned int nchars)
{
if (obstack_room (&frchain_now->frch_obstack) < nchars)
{
- unsigned int n;
long oldc;
+ long newc;
- frag_wane (frag_now);
- frag_new (0);
- oldc = frchain_now->frch_obstack.chunk_size;
/* Try to allocate a bit more than needed right now. But don't do
this if we would waste too much memory. Especially necessary
- for extremely big (like 2GB initialized) frags. */
+ for extremely big (like 2GB initialized) frags. */
if (nchars < 0x10000)
- frchain_now->frch_obstack.chunk_size = 2 * nchars;
+ newc = 2 * nchars;
else
- frchain_now->frch_obstack.chunk_size = nchars + 0x10000;
- frchain_now->frch_obstack.chunk_size += SIZEOF_STRUCT_FRAG;
- if (frchain_now->frch_obstack.chunk_size > 0)
- while ((n = obstack_room (&frchain_now->frch_obstack)) < nchars
- && (unsigned long) frchain_now->frch_obstack.chunk_size > nchars)
- {
- frag_wane (frag_now);
- frag_new (0);
- }
- frchain_now->frch_obstack.chunk_size = oldc;
+ newc = nchars + 0x10000;
+ newc += SIZEOF_STRUCT_FRAG;
+
+ /* Check for possible overflow. */
+ if (newc < 0)
+ as_fatal (_("can't extend frag %u chars"), nchars);
+
+ /* Force to allocate at least NEWC bytes. */
+ oldc = obstack_chunk_size (&frchain_now->frch_obstack);
+ obstack_chunk_size (&frchain_now->frch_obstack) = newc;
+
+ while (obstack_room (&frchain_now->frch_obstack) < nchars)
+ {
+ /* Not enough room in this frag. Close it and start a new one.
+ This must be done in a loop because the created frag may not
+ be big enough if the current obstack chunk is used. */
+ frag_wane (frag_now);
+ frag_new (0);
+ }
+
+ /* Restore the old chunk size. */
+ obstack_chunk_size (&frchain_now->frch_obstack) = oldc;
}
- if (obstack_room (&frchain_now->frch_obstack) < nchars)
- as_fatal (_("can't extend frag %u chars"), nchars);
}
/* Call this to close off a completed frag, and start up a new (empty)