[Tarantool-patches] [PATCH] cppcheck: box/alter.cc null pointer dereference

Sergey Kaplun skaplun at tarantool.org
Sun Sep 20 20:59:30 MSK 2020


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



More information about the Tarantool-patches mailing list