From patchwork Wed May 5 08:18:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1474147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FZqP22S80z9sRR for ; Wed, 5 May 2021 18:19:02 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A202F3C5795 for ; Wed, 5 May 2021 10:18:59 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 538463C2170 for ; Wed, 5 May 2021 10:18:47 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 786EF600076 for ; Wed, 5 May 2021 10:18:47 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 93391B18A for ; Wed, 5 May 2021 08:18:46 +0000 (UTC) From: Martin Doucha To: ltp@lists.linux.it Date: Wed, 5 May 2021 10:18:40 +0200 Message-Id: <20210505081845.7024-1-mdoucha@suse.cz> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/6] Add SAFE_REALLOC() helper function to LTP library X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Martin Doucha Reviewed-by: Cyril Hrubis Reviewed-by: Petr Vorel --- Sorry for resubmitting so soon, I forgot to include the gitignore/runfile paperwork for the new test. Fixed in patch 6. Changes since v1: None include/tst_safe_macros.h | 5 +++++ lib/tst_safe_macros.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index b9d9baa1a..d6f32ef4c 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -67,6 +67,11 @@ int safe_dup2(const char *file, const int lineno, int oldfd, int newfd); #define SAFE_MALLOC(size) \ safe_malloc(__FILE__, __LINE__, NULL, (size)) +void *safe_realloc(const char *file, const int lineno, void *ptr, size_t size); + +#define SAFE_REALLOC(ptr, size) \ + safe_realloc(__FILE__, __LINE__, (ptr), (size)) + #define SAFE_MKDIR(pathname, mode) \ safe_mkdir(__FILE__, __LINE__, NULL, (pathname), (mode)) diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c index 182b690bb..fd5f1704b 100644 --- a/lib/tst_safe_macros.c +++ b/lib/tst_safe_macros.c @@ -5,6 +5,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -433,6 +434,20 @@ int safe_dup2(const char *file, const int lineno, int oldfd, int newfd) return rval; } +void *safe_realloc(const char *file, const int lineno, void *ptr, size_t size) +{ + void *ret; + + ret = realloc(ptr, size); + + if (!ret) { + tst_brk_(file, lineno, TBROK | TERRNO, + "realloc(%p, %zu) failed", ptr, size); + } + + return ret; +} + sighandler_t safe_signal(const char *file, const int lineno, int signum, sighandler_t handler) {