Hi Cyril, Your reminding is very helpful for me. I agree with you. I have sent a new patch. Many thanks. Yuan
On 2015/6/4 0:58, Cyril Hrubis wrote: > Hi! >> See the following in the read_file function. >> *value = read_shares_file(filepath); >> if (*value == -1) >> return -1; >> Since the return value of read_shares_file and the variable value are >> unsigned int, it is impossible that *value == -1. >> >> Signed-off-by: Yuan Sun <sunyu...@huawei.com> >> --- >> testcases/kernel/controllers/libcontrollers/libcontrollers.c | 6 ++++-- >> testcases/kernel/controllers/libcontrollers/libcontrollers.h | 2 +- >> 2 files changed, 5 insertions(+), 3 deletions(-) >> >> diff --git a/testcases/kernel/controllers/libcontrollers/libcontrollers.c >> b/testcases/kernel/controllers/libcontrollers/libcontrollers.c >> index b01e1b8..80a90b9 100644 >> --- a/testcases/kernel/controllers/libcontrollers/libcontrollers.c >> +++ b/testcases/kernel/controllers/libcontrollers/libcontrollers.c >> @@ -115,11 +115,14 @@ int read_file(char *filepath, int action, unsigned int >> *value) >> { >> int num_line = 0; >> FILE *fp; >> + int tmp; >> switch (action) { >> case GET_SHARES: >> - *value = read_shares_file(filepath); >> + tmp = read_shares_file(filepath); >> if (*value == -1) >> return -1; >> + else >> + *value = (unsigned int)tmp; >> break; >> >> case GET_TASKS: >> @@ -159,7 +162,6 @@ inline int error_function(char *msg1, char *msg2) >> * the given pointer location. Returns 0 if success >> */ >> >> -unsigned >> int read_shares_file(char *filepath) >> { >> FILE *fp; >> diff --git a/testcases/kernel/controllers/libcontrollers/libcontrollers.h >> b/testcases/kernel/controllers/libcontrollers/libcontrollers.h >> index 4001555..78a7fed 100644 >> --- a/testcases/kernel/controllers/libcontrollers/libcontrollers.h >> +++ b/testcases/kernel/controllers/libcontrollers/libcontrollers.h >> @@ -72,7 +72,7 @@ enum{ >> >> inline int error_function(char *msg1, char *msg2); >> >> -unsigned int read_shares_file (char *filepath); >> +int read_shares_file(char *filepath); >> >> int read_file(char *filepath, int action, unsigned int *value); > Looking at the code, it's more broken than this. > > The read_shares_file() function, as well as rest of the functions, > cannot return -1 as they are now. > > If you look at the code carefuly: > > inline int error_function(char *msg1, char *msg2) > { > fprintf(stdout, "ERROR: %s ", msg1); > fprintf(stdout, "%s\n", msg2); > return -1; > } > > unsigned > int read_shares_file(char *filepath) > { > FILE *fp; > unsigned int shares; > fp = fopen(filepath, "r"); > if (fp == NULL) > error_function("Could not open file", filepath); > fscanf(fp, "%u", &shares); > > The return value from error_function() would be ingnored here and, if the file > cannot be open, the code will crash while passing NULL to fscanf. > ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list