Received: by 10.223.176.5 with SMTP id f5csp2097144wra; Thu, 8 Feb 2018 08:23:49 -0800 (PST) X-Google-Smtp-Source: AH8x225MdWhov9lEbsETOCh5z7oRP5RFdY0F3a7WGi3i2NyF773WUHNWzsieLWkcznytAhFHLidP X-Received: by 2002:a17:902:1c1:: with SMTP id b59-v6mr1122807plb.325.1518107029416; Thu, 08 Feb 2018 08:23:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518107029; cv=none; d=google.com; s=arc-20160816; b=TZ8b0J7C2GxiwTsqAaBihWe3QTo8uG7P8Gb1zNaFjWEcWky5Of8Da7bjYrHsJvLF+V sx5A8/PNUguYWSVbJ7PU4iOuGFhAvZfZaIGULz2OG0CsG9PTvGaGR4Ciubcp7ZkM/yBG 2EsKyMssi/k5+GKZQK3mhInLmS9HmotNCg4oxXp7clIHFb4d7nuzvOc/hobM7uzVb/Yf pDTVRJss26/YV6f+S+jQWK8Cy0ghin0CGev6nkr4S+7W/G2beJrR/iL9srJkAcCjWq+h zxU0Wyja6TO/mvnms2mXg4Cuc0j/ZQOVkYEodcmDumvXtHBOSUrzCgfCgDRllz06jcoK 6apA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=u39XhiSy2FIvQt8O3MtdRJJg6CV6UlnbVTrzkUrASnw=; b=eEHUSOjUxJTPUWr46fK8GK0w/iyTTtKwCZ0kSsTUOVlYJSDqCCU7GEwqvLgKxgKP65 +4KpJUy95115Y7Am4qMI35fxZSjDtNwSwkq14aRuk2wywYAQTu+P3srm9SzgCJoDCimB VHwFL/9avpSPWKlMgqviAzPcJ7TOA1bDDVQilZ5Erm5YNDFyUk2qwlOOaVpk7AgbF61t QYyIzQlXHDFNI7c7VzrkKi3ftRvHekePxyFm+dLlaSj0PSXk3pncBv/cmG8ci2sC0Zpq zFeLjB0vtbvZeXDJYJZJuBxfIdrWyjNmMB5hl+pBwq8sbMkBI/iPkIWLyU9ZRBSzH4yB 5duA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=rDT1CHPk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t29si174883pfa.359.2018.02.08.08.23.34; Thu, 08 Feb 2018 08:23:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=rDT1CHPk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752583AbeBHQW2 (ORCPT + 99 others); Thu, 8 Feb 2018 11:22:28 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19359 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752255AbeBHQVh (ORCPT ); Thu, 8 Feb 2018 11:21:37 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1E021191; Fri, 9 Feb 2018 01:19:27 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1E021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106768; bh=u39XhiSy2FIvQt8O3MtdRJJg6CV6UlnbVTrzkUrASnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rDT1CHPksHL97rtD3gKbYcuLdO0xFE51CFZkSF2zrJ3u8gUKNh1kO7mtL1W9aSOKP e4EBO+askpCIA49RRdH6tVX63xqLcv9UzQFInRcNwmUdORkvFABdndJlSqc36xwp3d 1qRimeaOIg/uFyr94IKsr3T1ta0OPJlfTIsICmuFlbuJb0kkvUFP9V3gS5PhQMysuc PPnlXhIuNYH/IZukiNYwMAp3RNWfgWF9thWkaJmH9Ny3mYEyjSI3A9UQXm356gH0mt fQoSagiR6HaEQbgL6STywwipu30/vLnxBIW+3LWuPg+3YEee7hudLWO4k0WGesE+a4 0DEjUHSknAggw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/7] kconfig: add xrealloc() helper Date: Fri, 9 Feb 2018 01:19:07 +0900 Message-Id: <1518106752-29228-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have xmalloc(), xcalloc() already. Add xrealloc() as well to save tedious error handling. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 2 +- scripts/kconfig/lkc.h | 1 + scripts/kconfig/nconf.gui.c | 2 +- scripts/kconfig/symbol.c | 2 +- scripts/kconfig/util.c | 11 ++++++++++- scripts/kconfig/zconf.l | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f792739..5c12dc9 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -201,7 +201,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n) if (new_size > *n) { new_size += LINE_GROWTH - 1; new_size *= 2; - nline = realloc(*lineptr, new_size); + nline = xrealloc(*lineptr, new_size); if (!nline) return -1; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 16cb62b..4e23feb 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -114,6 +114,7 @@ struct file *file_lookup(const char *name); int file_write_dep(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); +void *xrealloc(void *p, size_t size); struct gstr { size_t len; diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index a64b1c3..93e3d0c 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -374,7 +374,7 @@ int dialog_inputbox(WINDOW *main_window, if (strlen(init)+1 > *result_len) { *result_len = strlen(init)+1; - *resultp = result = realloc(result, *result_len); + *resultp = result = xrealloc(result, *result_len); } /* find the widest line of msg: */ diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c9123ed..bc3ec6a 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -938,7 +938,7 @@ const char *sym_expand_string_value(const char *in) newlen = strlen(res) + strlen(symval) + strlen(src) + 1; if (newlen > reslen) { reslen = newlen; - res = realloc(res, reslen); + res = xrealloc(res, reslen); } strcat(res, symval); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 0e76042..01ead28 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -104,7 +104,7 @@ void str_append(struct gstr *gs, const char *s) if (s) { l = strlen(gs->s) + strlen(s) + 1; if (l > gs->len) { - gs->s = realloc(gs->s, l); + gs->s = xrealloc(gs->s, l); gs->len = l; } strcat(gs->s, s); @@ -145,3 +145,12 @@ void *xcalloc(size_t nmemb, size_t size) fprintf(stderr, "Out of memory.\n"); exit(1); } + +void *xrealloc(void *p, size_t size) +{ + p = realloc(p, size); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +} diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 07e074d..0bc43db 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -52,7 +52,7 @@ static void append_string(const char *str, int size) if (new_size > text_asize) { new_size += START_STRSIZE - 1; new_size &= -START_STRSIZE; - text = realloc(text, new_size); + text = xrealloc(text, new_size); text_asize = new_size; } memcpy(text + text_size, str, size); -- 2.7.4