From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 1297A38133F4 for ; Mon, 30 May 2022 09:34:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1297A38133F4 Received: by mail-pf1-x435.google.com with SMTP id g67so2087478pfb.2 for ; Mon, 30 May 2022 02:34:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=werXp3ajfDKPtkObzQkD/KGLWlkWA/pXzZVsbAYVERs=; b=g4AQC50xvBlIxLlysMVIRCZp5NyroQLLj1CMIwYxUkPwfFTU5kzbhRMrYaUgoOoEfL OIUcixpaDa94CIy/lLKeVEat37kBF6wyl2f29UsVu0m5GvWa7yvNtQ6oJwJOrTqqUnbS R16vZuQrHFbXXTUAGmSkkL13gi0mFg8HN8pGNeI/Ljg9txE+tuatq4uxKTEDUShCBR8V gcRsyv9EdbVazT+3rgDY2A/AGU9PeCibEpwIRqc8RSG9Ytyz65BfQV96m8X4tr3Rtvxm 7FN10M3IvlMJtpnyacUFiXska/0kR0NnDHjWzipTtcJ6X1uyiDSYBPW6Ms68XdrBXvEA pPZg== X-Gm-Message-State: AOAM532fLguDfN82a0UBlIsHAp5N7xNzRQBxrhTsT7IxzWsTl2zcdhpX sEN33cL4VrTQYNUvwpkOCOppH/LyAWQ= X-Google-Smtp-Source: ABdhPJyC4NJLBk8caBd2RmBFar9WbjlXtWeyAmXy/uq8D4YK00Gw1uNkhZQgmzxI7EG0THy6RESSSg== X-Received: by 2002:a63:ef41:0:b0:3fb:c201:797d with SMTP id c1-20020a63ef41000000b003fbc201797dmr11713516pgk.104.1653903277676; Mon, 30 May 2022 02:34:37 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id m6-20020a635806000000b003c67e472338sm8026178pgb.42.2022.05.30.02.34.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 02:34:37 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4B75C114117E; Mon, 30 May 2022 19:04:34 +0930 (ACST) Date: Mon, 30 May 2022 19:04:34 +0930 From: Alan Modra To: binutils@sourceware.org Subject: use libiberty xmalloc in bfd/doc/chew.c Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 09:34:40 -0000 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. diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 741e08d603c..53cac75af0e 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -1301,6 +1301,7 @@ doc_bfd_TEXINFOS = $(DOCFILES) doc/bfdsumm.texi AM_MAKEINFOFLAGS = --no-split -I "$(srcdir)/doc" -I doc TEXI2DVI = texi2dvi -I "$(srcdir)/doc" -I doc MKDOC = doc/chew$(EXEEXT_FOR_BUILD) +LIBIBERTY = ../libiberty/libiberty.a # We can't replace these rules with an implicit rule, because # 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) \ $(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \ -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 \ doc/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \ touch $@ diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c index 22921e68431..9722a89f0e6 100644 --- a/bfd/doc/chew.c +++ b/bfd/doc/chew.c @@ -82,6 +82,7 @@ Foo. */ #include "ansidecl.h" +#include "libiberty.h" #include #include #include @@ -141,7 +142,7 @@ init_string_with_size (string_type *buffer, unsigned int size) { buffer->write_idx = 0; buffer->size = size; - buffer->ptr = (char *) malloc (size); + buffer->ptr = xmalloc (size); } static void @@ -201,7 +202,7 @@ catchar (string_type *buffer, int ch) if (buffer->write_idx == buffer->size) { buffer->size *= 2; - buffer->ptr = (char *) realloc (buffer->ptr, buffer->size); + buffer->ptr = xrealloc (buffer->ptr, buffer->size); } 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) 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); buffer->write_idx += len; @@ -1102,7 +1103,7 @@ nextword (char *string, char **word) } } - *word = (char *) malloc (length + 1); + *word = xmalloc (length + 1); dst = *word; src = word_start; @@ -1216,11 +1217,11 @@ perform (void) dict_type * 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->next = root; 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_end = 0; return new_d; @@ -1232,9 +1233,8 @@ add_to_definition (dict_type *entry, stinst_type word) if (entry->code_end == entry->code_length) { entry->code_length += 2; - entry->code = - (stinst_type *) realloc ((char *) (entry->code), - entry->code_length * sizeof (stinst_type)); + entry->code = xrealloc (entry->code, + entry->code_length * sizeof (*entry->code)); } entry->code[entry->code_end] = word; @@ -1244,7 +1244,7 @@ add_to_definition (dict_type *entry, stinst_type word) 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, 0); } diff --git a/bfd/doc/local.mk b/bfd/doc/local.mk index 931942f874c..8c6932802f6 100644 --- a/bfd/doc/local.mk +++ b/bfd/doc/local.mk @@ -82,12 +82,14 @@ TEXI2DVI = texi2dvi -I "$(srcdir)/%D%" -I %D% MKDOC = %D%/chew$(EXEEXT_FOR_BUILD) +LIBIBERTY = ../libiberty/libiberty.a + $(MKDOC): %D%/chew.stamp ; @true %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) \ $(LDFLAGS_FOR_BUILD) $(H_CFLAGS) \ -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 \ %D%/chw$$$$$(EXEEXT_FOR_BUILD) $(MKDOC) && \ touch $@ -- Alan Modra Australia Development Lab, IBM