forked from Imagelibrary/binutils-gdb
use libiberty xmalloc in bfd/doc/chew.c
Catch out of memory. * doc/chew.c: Include libibery.h. (init_string_with_size, nextword): Replace malloc with xmalloc. (newentry, add_to_definition): Likewise. (catchar, catbuf): Replace realloc with xrealloc. (add_intrinsic): Replace strdup with xstrdup. * doc/local.mk (LIBIBERTY): Define. (chew): Link against libiberty. * Makefile.in: Regenerate.
This commit is contained in:
@@ -1301,6 +1301,7 @@ doc_bfd_TEXINFOS = $(DOCFILES) doc/bfdsumm.texi
|
|||||||
AM_MAKEINFOFLAGS = --no-split -I "$(srcdir)/doc" -I doc
|
AM_MAKEINFOFLAGS = --no-split -I "$(srcdir)/doc" -I doc
|
||||||
TEXI2DVI = texi2dvi -I "$(srcdir)/doc" -I doc
|
TEXI2DVI = texi2dvi -I "$(srcdir)/doc" -I doc
|
||||||
MKDOC = doc/chew$(EXEEXT_FOR_BUILD)
|
MKDOC = doc/chew$(EXEEXT_FOR_BUILD)
|
||||||
|
LIBIBERTY = ../libiberty/libiberty.a
|
||||||
|
|
||||||
# We can't replace these rules with an implicit rule, because
|
# We can't replace these rules with an implicit rule, because
|
||||||
# makes without VPATH support couldn't find the .h files in `..'.
|
# makes without VPATH support couldn't find the .h files in `..'.
|
||||||
@@ -2487,7 +2488,7 @@ doc/chew.stamp: $(srcdir)/doc/chew.c doc/$(am__dirstamp)
|
|||||||
$(AM_V_CCLD)$(CC_FOR_BUILD) -o doc/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
|
$(AM_V_CCLD)$(CC_FOR_BUILD) -o doc/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
|
||||||
$(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \
|
$(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \
|
||||||
-I. -I$(srcdir) -Idoc -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \
|
-I. -I$(srcdir) -Idoc -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \
|
||||||
$(srcdir)/doc/chew.c && \
|
$(srcdir)/doc/chew.c $(LIBIBERTY) && \
|
||||||
$(SHELL) $(srcdir)/../move-if-change \
|
$(SHELL) $(srcdir)/../move-if-change \
|
||||||
doc/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \
|
doc/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \
|
||||||
touch $@
|
touch $@
|
||||||
|
|||||||
@@ -82,6 +82,7 @@
|
|||||||
Foo. */
|
Foo. */
|
||||||
|
|
||||||
#include "ansidecl.h"
|
#include "ansidecl.h"
|
||||||
|
#include "libiberty.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -141,7 +142,7 @@ init_string_with_size (string_type *buffer, unsigned int size)
|
|||||||
{
|
{
|
||||||
buffer->write_idx = 0;
|
buffer->write_idx = 0;
|
||||||
buffer->size = size;
|
buffer->size = size;
|
||||||
buffer->ptr = (char *) malloc (size);
|
buffer->ptr = xmalloc (size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -201,7 +202,7 @@ catchar (string_type *buffer, int ch)
|
|||||||
if (buffer->write_idx == buffer->size)
|
if (buffer->write_idx == buffer->size)
|
||||||
{
|
{
|
||||||
buffer->size *= 2;
|
buffer->size *= 2;
|
||||||
buffer->ptr = (char *) realloc (buffer->ptr, buffer->size);
|
buffer->ptr = xrealloc (buffer->ptr, buffer->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->ptr[buffer->write_idx++] = ch;
|
buffer->ptr[buffer->write_idx++] = ch;
|
||||||
@@ -223,7 +224,7 @@ catbuf (string_type *buffer, char *buf, unsigned int len)
|
|||||||
{
|
{
|
||||||
while (buffer->write_idx + len >= buffer->size)
|
while (buffer->write_idx + len >= buffer->size)
|
||||||
buffer->size *= 2;
|
buffer->size *= 2;
|
||||||
buffer->ptr = (char *) realloc (buffer->ptr, buffer->size);
|
buffer->ptr = xrealloc (buffer->ptr, buffer->size);
|
||||||
}
|
}
|
||||||
memcpy (buffer->ptr + buffer->write_idx, buf, len);
|
memcpy (buffer->ptr + buffer->write_idx, buf, len);
|
||||||
buffer->write_idx += len;
|
buffer->write_idx += len;
|
||||||
@@ -1102,7 +1103,7 @@ nextword (char *string, char **word)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*word = (char *) malloc (length + 1);
|
*word = xmalloc (length + 1);
|
||||||
|
|
||||||
dst = *word;
|
dst = *word;
|
||||||
src = word_start;
|
src = word_start;
|
||||||
@@ -1216,11 +1217,11 @@ perform (void)
|
|||||||
dict_type *
|
dict_type *
|
||||||
newentry (char *word)
|
newentry (char *word)
|
||||||
{
|
{
|
||||||
dict_type *new_d = (dict_type *) malloc (sizeof (dict_type));
|
dict_type *new_d = xmalloc (sizeof (*new_d));
|
||||||
new_d->word = word;
|
new_d->word = word;
|
||||||
new_d->next = root;
|
new_d->next = root;
|
||||||
root = new_d;
|
root = new_d;
|
||||||
new_d->code = (stinst_type *) malloc (sizeof (stinst_type));
|
new_d->code = xmalloc (sizeof (*new_d->code));
|
||||||
new_d->code_length = 1;
|
new_d->code_length = 1;
|
||||||
new_d->code_end = 0;
|
new_d->code_end = 0;
|
||||||
return new_d;
|
return new_d;
|
||||||
@@ -1232,9 +1233,8 @@ add_to_definition (dict_type *entry, stinst_type word)
|
|||||||
if (entry->code_end == entry->code_length)
|
if (entry->code_end == entry->code_length)
|
||||||
{
|
{
|
||||||
entry->code_length += 2;
|
entry->code_length += 2;
|
||||||
entry->code =
|
entry->code = xrealloc (entry->code,
|
||||||
(stinst_type *) realloc ((char *) (entry->code),
|
entry->code_length * sizeof (*entry->code));
|
||||||
entry->code_length * sizeof (stinst_type));
|
|
||||||
}
|
}
|
||||||
entry->code[entry->code_end] = word;
|
entry->code[entry->code_end] = word;
|
||||||
|
|
||||||
@@ -1244,7 +1244,7 @@ add_to_definition (dict_type *entry, stinst_type word)
|
|||||||
void
|
void
|
||||||
add_intrinsic (char *name, void (*func) (void))
|
add_intrinsic (char *name, void (*func) (void))
|
||||||
{
|
{
|
||||||
dict_type *new_d = newentry (strdup (name));
|
dict_type *new_d = newentry (xstrdup (name));
|
||||||
add_to_definition (new_d, func);
|
add_to_definition (new_d, func);
|
||||||
add_to_definition (new_d, 0);
|
add_to_definition (new_d, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,12 +82,14 @@ TEXI2DVI = texi2dvi -I "$(srcdir)/%D%" -I %D%
|
|||||||
|
|
||||||
MKDOC = %D%/chew$(EXEEXT_FOR_BUILD)
|
MKDOC = %D%/chew$(EXEEXT_FOR_BUILD)
|
||||||
|
|
||||||
|
LIBIBERTY = ../libiberty/libiberty.a
|
||||||
|
|
||||||
$(MKDOC): %D%/chew.stamp ; @true
|
$(MKDOC): %D%/chew.stamp ; @true
|
||||||
%D%/chew.stamp: $(srcdir)/%D%/chew.c %D%/$(am__dirstamp)
|
%D%/chew.stamp: $(srcdir)/%D%/chew.c %D%/$(am__dirstamp)
|
||||||
$(AM_V_CCLD)$(CC_FOR_BUILD) -o %D%/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
|
$(AM_V_CCLD)$(CC_FOR_BUILD) -o %D%/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
|
||||||
$(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \
|
$(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \
|
||||||
-I. -I$(srcdir) -I%D% -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \
|
-I. -I$(srcdir) -I%D% -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \
|
||||||
$(srcdir)/%D%/chew.c && \
|
$(srcdir)/%D%/chew.c $(LIBIBERTY) && \
|
||||||
$(SHELL) $(srcdir)/../move-if-change \
|
$(SHELL) $(srcdir)/../move-if-change \
|
||||||
%D%/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \
|
%D%/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \
|
||||||
touch $@
|
touch $@
|
||||||
|
|||||||
Reference in New Issue
Block a user