aboutsummaryrefslogtreecommitdiff
path: root/gas/sb.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2012-06-07 12:47:23 +0000
committerAlan Modra <amodra@gmail.com>2012-06-07 12:47:23 +0000
commit39a45edc073226e748566b497c216830cec119c4 (patch)
treebd35d385584a6fcaca5e6a40a9933b33cafe1b2d /gas/sb.c
parentfb1b895daad773efd7dc023f913678e9c80d8c3a (diff)
downloadgdb-39a45edc073226e748566b497c216830cec119c4.zip
gdb-39a45edc073226e748566b497c216830cec119c4.tar.gz
gdb-39a45edc073226e748566b497c216830cec119c4.tar.bz2
PR gas/14201
* sb.h (sb_max_power_two): Delete. (struct sb): Delete "item" and "pot". Make "len" a size_t. Add "max". (sb_element): Delete. (sb_add_char, sb_add_buffer, sb_skip_comma, sb_skip_write): Update prototypes. * sb.c (string_count, free_list): Delete. (sb_build, sb_kill, sb_check): Rewrite. (scrub_from_sb, sb_add_char, sb_add_string, sb_add_buffer, sb_skip_white, sb_skip_comma): Replace assorted int params, vars and return types with size_t. * input-scrub.c: Likewise. * macro.c: Likewise. * macro.h: Likewise. * as.c: Likewise. * as.h: Likewise. * input-file.h: Likewise. * input-file.c: Likewise. * read.c: Likewise. * app.c: ..or ptrdiff_t. * input-file.c (input_file_get): Use ferror. (input_file_give_next_buffer): Use input_file_get.
Diffstat (limited to 'gas/sb.c')
-rw-r--r--gas/sb.c89
1 files changed, 29 insertions, 60 deletions
diff --git a/gas/sb.c b/gas/sb.c
index 8d5e8dd..f345fe1 100644
--- a/gas/sb.c
+++ b/gas/sb.c
@@ -1,5 +1,5 @@
/* sb.c - string buffer manipulation routines
- Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007, 2009
+ Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007, 2009, 2012
Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
@@ -39,47 +39,17 @@
use foo->ptr[*];
sb_kill (&foo); */
-static int dsize = 5;
-static void sb_check (sb *, int);
-
-/* Statistics of sb structures. */
-static int string_count[sb_max_power_two];
-
-/* Free list of sb structures. */
-static struct
-{
- sb_element *size[sb_max_power_two];
-} free_list;
+static size_t dsize = 32;
+static void sb_check (sb *, size_t);
/* Initializes an sb. */
static void
-sb_build (sb *ptr, int size)
+sb_build (sb *ptr, size_t size)
{
- /* See if we can find one to allocate. */
- sb_element *e;
-
- gas_assert (size < sb_max_power_two);
-
- e = free_list.size[size];
- if (!e)
- {
- /* Nothing there, allocate one and stick into the free list. */
- e = (sb_element *) xmalloc (sizeof (sb_element) + (1 << size));
- e->next = free_list.size[size];
- e->size = 1 << size;
- free_list.size[size] = e;
- string_count[size]++;
- }
-
- /* Remove from free list. */
- free_list.size[size] = e->next;
-
- /* Copy into callers world. */
- ptr->ptr = e->data;
- ptr->pot = size;
+ ptr->ptr = xmalloc (size + 1);
+ ptr->max = size;
ptr->len = 0;
- ptr->item = e;
}
void
@@ -93,9 +63,7 @@ sb_new (sb *ptr)
void
sb_kill (sb *ptr)
{
- /* Return item to free list. */
- ptr->item->next = free_list.size[ptr->pot];
- free_list.size[ptr->pot] = ptr->item;
+ free (ptr->ptr);
}
/* Add the sb at s to the end of the sb at ptr. */
@@ -112,10 +80,10 @@ sb_add_sb (sb *ptr, sb *s)
static sb *sb_to_scrub;
static char *scrub_position;
-static int
-scrub_from_sb (char *buf, int buflen)
+static size_t
+scrub_from_sb (char *buf, size_t buflen)
{
- int copy;
+ size_t copy;
copy = sb_to_scrub->len - (scrub_position - sb_to_scrub->ptr);
if (copy > buflen)
copy = buflen;
@@ -144,19 +112,20 @@ sb_scrub_and_add_sb (sb *ptr, sb *s)
and grow it if it doesn't. */
static void
-sb_check (sb *ptr, int len)
+sb_check (sb *ptr, size_t len)
{
- if (ptr->len + len >= 1 << ptr->pot)
+ size_t max = ptr->max;
+
+ while (ptr->len + len >= max)
+ {
+ max <<= 1;
+ if (max == 0)
+ as_fatal ("string buffer overflow");
+ }
+ if (max != ptr->max)
{
- sb tmp;
- int pot = ptr->pot;
-
- while (ptr->len + len >= 1 << pot)
- pot++;
- sb_build (&tmp, pot);
- sb_add_sb (&tmp, ptr);
- sb_kill (ptr);
- *ptr = tmp;
+ ptr->max = max;
+ ptr->ptr = xrealloc (ptr->ptr, max + 1);
}
}
@@ -171,7 +140,7 @@ sb_reset (sb *ptr)
/* Add character c to the end of the sb at ptr. */
void
-sb_add_char (sb *ptr, int c)
+sb_add_char (sb *ptr, size_t c)
{
sb_check (ptr, 1);
ptr->ptr[ptr->len++] = c;
@@ -182,7 +151,7 @@ sb_add_char (sb *ptr, int c)
void
sb_add_string (sb *ptr, const char *s)
{
- int len = strlen (s);
+ size_t len = strlen (s);
sb_check (ptr, len);
memcpy (ptr->ptr + ptr->len, s, len);
ptr->len += len;
@@ -191,7 +160,7 @@ sb_add_string (sb *ptr, const char *s)
/* Add string at s of length len to sb at ptr */
void
-sb_add_buffer (sb *ptr, const char *s, int len)
+sb_add_buffer (sb *ptr, const char *s, size_t len)
{
sb_check (ptr, len);
memcpy (ptr->ptr + ptr->len, s, len);
@@ -211,8 +180,8 @@ sb_terminate (sb *in)
/* Start at the index idx into the string in sb at ptr and skip
whitespace. return the index of the first non whitespace character. */
-int
-sb_skip_white (int idx, sb *ptr)
+size_t
+sb_skip_white (size_t idx, sb *ptr)
{
while (idx < ptr->len
&& (ptr->ptr[idx] == ' '
@@ -225,8 +194,8 @@ sb_skip_white (int idx, sb *ptr)
a comma and any following whitespace. returns the index of the
next character. */
-int
-sb_skip_comma (int idx, sb *ptr)
+size_t
+sb_skip_comma (size_t idx, sb *ptr)
{
while (idx < ptr->len
&& (ptr->ptr[idx] == ' '