From b69ee36cb166469c1fe3cb922f25509abfcfade7 Mon Sep 17 00:00:00 2001 From: Wen Yi Date: Sun, 25 Aug 2024 22:03:03 +0800 Subject: [PATCH] Fix code bug --- src/pikiwidb.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pikiwidb.cc b/src/pikiwidb.cc index 4d04bb8d..e7beae3e 100644 --- a/src/pikiwidb.cc +++ b/src/pikiwidb.cc @@ -126,8 +126,18 @@ bool PikiwiDB::ParseArgs(int argc, char* argv[]) { break; } case 's': { - master_.resize(strlen(optarg)); - sscanf(optarg, "%s:%d", master_, master_port_); + unsigned int optarg_long = strlen(optarg); + char *str = calloc(optarg_long, sizeof(char*)); + if (str) + { + sscanf(optarg, "%s:%d", str, master_port_); + master_ = str; + free(str); + } + else + { + ERROR("Memory alloc failed."); + } break; } case '?': {