* Ensure all fopen check for NULL (not -1)

* Improve test-perf cycles
This commit is contained in:
Olof hagsand 2020-12-07 09:56:07 +01:00
parent 344dcacf6f
commit e1b94d94d2
20 changed files with 24 additions and 23 deletions

View file

@ -173,7 +173,7 @@ load_extraxml(clicon_handle h,
if (filename == NULL)
return 1;
if ((fp = fopen(filename, "r")) < 0){
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}

View file

@ -811,7 +811,7 @@ load_config_file(clicon_handle h,
goto done;
}
/* Open and parse local file into xml */
if ((fp = fopen(filename, "r")) < 0){
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}

View file

@ -402,7 +402,7 @@ example_statedata(clicon_handle h,
}
else{
cxobj *x1;
if ((fp = fopen(_state_file, "r")) < 0){
if ((fp = fopen(_state_file, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
goto done;
}
@ -984,7 +984,7 @@ example_daemon(clicon_handle h)
/* Read state file (or should this be in init/start?) */
if (_state && _state_file && _state_file_init){
yspec = clicon_dbspec_yang(h);
if ((fp = fopen(_state_file, "r")) < 0){
if ((fp = fopen(_state_file, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
goto done;
}

View file

@ -453,7 +453,7 @@ xmldb_readfile(clicon_handle h,
goto done;
}
/* Parse file into internal XML tree from different formats */
if ((fp = fopen(dbfile, "r")) < 0) {
if ((fp = fopen(dbfile, "r")) == NULL) {
clicon_err(OE_UNIX, errno, "open(%s)", dbfile);
goto done;
}

View file

@ -211,7 +211,7 @@ parse_configfile_one(const char *filename,
cbuf *cbret = NULL;
int ret;
if ((fp = fopen(filename, "r")) < 0){
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open configure file: %s", filename);
return -1;
}

View file

@ -445,7 +445,7 @@ clixon_xml_changelog_init(clicon_handle h)
yspec = clicon_dbspec_yang(h);
if ((filename = clicon_option_str(h, "CLICON_XML_CHANGELOG_FILE")) != NULL){
if ((fp = fopen(filename, "r")) < 0){
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "fopen(%s)", filename);
goto done;
}

View file

@ -582,7 +582,8 @@ FSM(char *tag,
* cxobj *xt = NULL;
* cxobj *xerr = NULL;
* FILE *f;
* f = fopen(filename, "r");
* if ((f = fopen(filename, "r")) == NULL)
* err;
* if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, "</config>", &xt, &xerr)) < 0)
* err;
* xml_free(xt);

View file

@ -168,10 +168,10 @@ fi
# restconf copy
new "restconf copy-config smoketest, json"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" http://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '{"ietf-netconf:input": {"target": {"startup": [null]},"source": {"running": [null]}}}')" 0 'HTTP/1.1 204 No Content'
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '{"ietf-netconf:input": {"target": {"startup": [null]},"source": {"running": [null]}}}')" 0 'HTTP/1.1 204 No Content'
new "restconf copy-config smoketest, xml"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" http://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '<input xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><target><startup></startup></target><source><running></running></source></input>')" 0 'HTTP/1.1 204 No Content'
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" $RCPROTO://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '<input xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><target><startup></startup></target><source><running></running></source></input>')" 0 'HTTP/1.1 204 No Content'
# Here running is empty
new "Check running empty"

View file

@ -10,7 +10,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${format:=xml}
# Number of list/leaf-list entries in file
: ${perfnr:=10000}
: ${perfnr:=20000}
# Number of requests made get/put
: ${perfreq:=10}

View file

@ -14,7 +14,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
clixon_util_xpath=clixon_util_xpath
# Number of list/leaf-list entries in file
: ${perfnr:=1000} # 10000 causes timeout in valgrind test
: ${perfnr:=2000} # 10000 causes timeout in valgrind test
APPNAME=example

View file

@ -11,7 +11,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${format:=xml}
# Number of list/leaf-list entries in file
: ${perfnr:=10000}
: ${perfnr:=20000}
# Number of requests made get/put
: ${perfreq:=10}

View file

@ -11,7 +11,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${format:=xml}
# Number of list/leaf-list entries in file
: ${perfnr:=10000}
: ${perfnr:=20000}
# Number of requests made get/put
: ${perfreq:=10}

View file

@ -7,7 +7,7 @@
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# Number of list/leaf-list entries in file
: ${perfnr:=10000}
: ${perfnr:=20000}
APPNAME=example

View file

@ -13,7 +13,7 @@ fin=$dir/fin
: ${format:=xml}
# Number of list/leaf-list entries in file (cant be less than 2)
: ${perfnr:=1000}
: ${perfnr:=20000}
# Number of requests made get/put
: ${perfreq:=10}

View file

@ -13,7 +13,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${format:=xml}
# Number of list/leaf-list entries in file (cant be less than 2)
: ${perfnr:=1000}
: ${perfnr:=20000}
# Number of requests made get/put
: ${perfreq:=10}

View file

@ -251,7 +251,7 @@ main(int argc, char **argv)
}
if (argc == 2){
FILE *fp;
if ((fp = fopen(xmlfilename, "r")) < 0){
if ((fp = fopen(xmlfilename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "fopen(%s)", xmlfilename);
goto done;
}

View file

@ -135,7 +135,7 @@ main(int argc,
break;
case 'f': /* XML file */
filename = optarg;
if ((fp = fopen(filename, "r")) < 0){
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "fopen(%s)", optarg);
goto done;
}

View file

@ -138,7 +138,7 @@ main(int argc,
usage(argv[0]);
}
if (input_filename){
if ((fp = fopen(input_filename, "r")) < 0){
if ((fp = fopen(input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
goto done;
}

View file

@ -263,7 +263,7 @@ main(int argc,
* Always validated
*/
if (top_input_filename){
if ((tfp = fopen(top_input_filename, "r")) < 0){
if ((tfp = fopen(top_input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename);
goto done;
}
@ -288,7 +288,7 @@ main(int argc,
xt = xbot;
}
if (input_filename){
if ((fp = fopen(input_filename, "r")) < 0){
if ((fp = fopen(input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
goto done;
}

View file

@ -168,7 +168,7 @@ main(int argc,
break;
case 'f': /* XML file */
filename = optarg;
if ((fp = fopen(filename, "r")) < 0){
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", argv[1]);
goto done;
}