Fixed memory corruption in optionless binaries.
This commit is contained in:
parent
61246062fb
commit
2705af4012
1 changed files with 31 additions and 29 deletions
|
@ -28,7 +28,7 @@ std::string Util::Config::libver = PACKAGE_VERSION;
|
||||||
/// Creates a new configuration manager.
|
/// Creates a new configuration manager.
|
||||||
Util::Config::Config(std::string cmd, std::string version){
|
Util::Config::Config(std::string cmd, std::string version){
|
||||||
vals.null();
|
vals.null();
|
||||||
long_count = 0;
|
long_count = 2;
|
||||||
vals["cmd"]["value"].append(cmd);
|
vals["cmd"]["value"].append(cmd);
|
||||||
vals["version"]["long"] = "version";
|
vals["version"]["long"] = "version";
|
||||||
vals["version"]["short"] = "v";
|
vals["version"]["short"] = "v";
|
||||||
|
@ -173,6 +173,7 @@ void Util::Config::parseArgs(int argc, char ** argv){
|
||||||
struct option * longOpts = (struct option*)calloc(long_count + 1, sizeof(struct option));
|
struct option * longOpts = (struct option*)calloc(long_count + 1, sizeof(struct option));
|
||||||
int long_i = 0;
|
int long_i = 0;
|
||||||
int arg_count = 0;
|
int arg_count = 0;
|
||||||
|
if (vals.size()){
|
||||||
for (JSON::ObjIter it = vals.ObjBegin(); it != vals.ObjEnd(); it++){
|
for (JSON::ObjIter it = vals.ObjBegin(); it != vals.ObjEnd(); it++){
|
||||||
if (it->second.isMember("short")){
|
if (it->second.isMember("short")){
|
||||||
shortopts += it->second["short"].asString();
|
shortopts += it->second["short"].asString();
|
||||||
|
@ -208,6 +209,7 @@ void Util::Config::parseArgs(int argc, char ** argv){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
while ((opt = getopt_long(argc, argv, shortopts.c_str(), longOpts, 0)) != -1){
|
while ((opt = getopt_long(argc, argv, shortopts.c_str(), longOpts, 0)) != -1){
|
||||||
switch (opt){
|
switch (opt){
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
Loading…
Add table
Reference in a new issue