From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4A45F469719 for ; Sun, 20 Sep 2020 20:59:53 +0300 (MSK) From: Sergey Kaplun Date: Sun, 20 Sep 2020 20:59:30 +0300 Message-Id: <20200920175930.9016-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] cppcheck: box/alter.cc null pointer dereference List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy , Mergen Imeev Cc: tarantool-patches@dev.tarantool.org Found and fixed Null pointer dereference with cppcheck: [src/box/alter.cc:395]: (error) Null pointer dereference --- cppcheck can be run from root project directory as follows: ``` $ cppcheck --force --enable=warning,performance,portability,information --error-exitcode=1 --verbose . ``` branch: https://github.com/tarantool/tarantool/tree/skaplun/cppcheck-alter-null-ptr-dereference src/box/alter.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index ba96d9c62..d106b7e0b 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -391,9 +391,9 @@ space_opts_decode(struct space_opts *opts, const char *map, if (opts->sql != NULL) { char *sql = strdup(opts->sql); if (sql == NULL) { + size_t optlen = strlen(opts->sql) + 1; opts->sql = NULL; - diag_set(OutOfMemory, strlen(opts->sql) + 1, "strdup", - "sql"); + diag_set(OutOfMemory, optlen, "strdup", "sql"); return -1; } opts->sql = sql; -- 2.28.0