Fix SVACE defects 59/192059/4
authorDariusz Michaluk <d.michaluk@samsung.com>
Mon, 29 Oct 2018 10:16:05 +0000 (11:16 +0100)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 29 Oct 2018 16:48:45 +0000 (17:48 +0100)
Change-Id: I03562c56c60d3df9c5401c4d9e55f8f1342df8c0

dcm-daemon/main.cpp
tests/example_client.cpp
tools/bin2c.c

index e4ec56e..7a9b05f 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2017 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2018 Samsung Electronics All Rights Reserved.
  *
  * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
  *
@@ -136,7 +136,12 @@ int main(int argc, char ** argv)
 {
        int error = 0;
 
-       init_logging();
+       try {
+               init_logging();
+       } catch(...) {
+               std::cerr << "init_logging() failed" << std::endl;
+               return EXIT_FAILURE;
+       }
 
        BOOST_LOG_FUNCTION();
 
index b326d2e..1ea1e89 100644 (file)
 
 int main(int argc, char ** argv)
 {
-       auto connection(dcm_client_connection::create());
+       std::shared_ptr<dcm_client_connection> connection;
+       try {
+               connection = dcm_client_connection::create();
+       } catch(std::exception& ex) {
+               std::cerr << "Can't create connection: " << ex.what() << std::endl;
+               return -1;
+       }
 
        if(!connection->create_context("example_client", "test_usage", "")) {
                std::cerr << "Can't create context" << std::endl;
index b49e4b4..d99764a 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
-int main(int argc, char** argv) {
+int main(int argc, char** argv)
+{
+       int ret = 0;
+       size_t size;
+       char *buffer = NULL;
+
        if(argc != 4)
                return -1;
 
-       FILE * infile = fopen(argv[1], "rb");
-       FILE * outfile = fopen(argv[2], "wb");
-       size_t i;
-
-       fseek(infile,0,SEEK_END);
-       size_t size = ftell(infile);
-       fseek(infile,0,SEEK_SET);
+       FILE *infile = fopen(argv[1], "rb");
+       FILE *outfile = fopen(argv[2], "wb");
+       if(!infile || !outfile) {
+               perror("fopen() failed");
+               ret = -1;
+               goto exit;
+       }
 
-       char * buffer = (char *)malloc(size);
+       if(fseek(infile, 0L, SEEK_END) < 0) {
+               perror("fseek() failed");
+               ret = -1;
+               goto exit;
+       }
+       if((size = ftell(infile)) <= 0) {
+               perror("ftell() failed");
+               ret = -1;
+               goto exit;
+       }
+       if(fseek(infile, 0L, SEEK_SET) < 0) {
+               perror("fseek() failed");
+               ret = -1;
+               goto exit;
+       }
 
-       size_t readno = fread(buffer, 1, size, infile);
-       fclose(infile);
+       buffer = (char *)malloc(size);
+       if(!buffer) {
+               perror("malloc() failed");
+               ret = -1;
+               goto exit;
+       }
 
-       if(readno <= 0) {
-               printf("Fail to read a file(%s)", argv[1]);
-               return -1;
+       if(fread(buffer, 1, size, infile) <= 0) {
+               perror("fread() failed");
+               ret = -1;
+               goto exit;
        }
 
        fprintf(outfile, "#include <sys/types.h>\nsize_t %s_size = %zd;\nunsigned char %s[]= {\n",
                        argv[3], size, argv[3]);
 
-       for(i = 0 ; i < size ; ++i) {
+       for(size_t i = 0 ; i < size ; ++i) {
                if(!(i % 64)) {
                        fprintf(outfile, "\n");
                }
-
                fprintf(outfile, "0x%02X,", (unsigned char)buffer[i]);
        }
        fprintf(outfile, "0\n};\n");
-       fclose(outfile);
-       return 0;
+
+exit:
+       if(infile) fclose(infile);
+       if(outfile) fclose(outfile);
+       free(buffer);
+       return ret;
 }