Fix build warnings 26/149026/2 accepted/tizen/4.0/unified/20170913.153733 submit/tizen_4.0/20170913.030030
authorSunmin Lee <sunm.lee@samsung.com>
Mon, 11 Sep 2017 09:46:20 +0000 (18:46 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Wed, 13 Sep 2017 01:17:56 +0000 (10:17 +0900)
Change-Id: I3701c06d65674f862f5171c011bc41df5d74cecc
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
bsdiff/ss_bsdiff.c
bsdiff/ss_bspatch.c
bsdiff/ss_bspatch_common.c
bsdiff/ss_bspatch_common.h
packaging/libtota.spec
ss_engine/SS_ApplyPatch.c
ss_engine/SS_FSUpdate.c
ss_engine/SS_PatchDelta.c
ss_engine/SS_UPI.c
ss_engine/fota_tar.c

index 94ce98a..102f8ad 100755 (executable)
@@ -108,7 +108,7 @@ struct data_thread
 
 struct data_thread data;
 
-void* Function(int);
+int Function(int);
 
 
 #endif
@@ -135,18 +135,16 @@ static off_t search(saidx_t *I, u_char *old, off_t oldsize,
                }
        }
 
-       if (en - st < 2) {
-               x = matchlen(old + I[st], oldsize - I[st], new, newsize);
-               y = matchlen(old + I[en], oldsize - I[en], new, newsize);
+       x = matchlen(old + I[st], oldsize - I[st], new, newsize);
+       y = matchlen(old + I[en], oldsize - I[en], new, newsize);
 
-               if (x > y) {
-                       *pos = I[st];
-                       return x;
-               } else {
-                       *pos = I[en];
-                       return y;
-               }
-       };
+       if (x > y) {
+               *pos = I[st];
+               return x;
+       } else {
+               *pos = I[en];
+               return y;
+       }
 }
 
 static void offtout(off_t x, u_char *buf)
@@ -185,7 +183,7 @@ static void offtout(off_t x, u_char *buf)
                buf[7] |= 0x80;
 }
 
-int create_patch(int argc, char *argv[], int offset_oldscore)
+int create_patch(int argc, const char *argv[], int offset_oldscore)
 {
        data.num_threads = MULTI_THREADING;
        data.new = (u_char **)malloc(sizeof(u_char *)*data.num_threads);
@@ -284,7 +282,7 @@ int create_patch(int argc, char *argv[], int offset_oldscore)
        return ret;
 }
 
-void* Function(int offset_oldscore)
+int Function(int offset_oldscore)
 {
        unsigned int thread_num = 0;
        off_t end;
@@ -318,6 +316,7 @@ void* Function(int offset_oldscore)
        off_t lens;
        off_t i;
 
+       pos = 0;
        len = 0;
        lastscan = 0;
        lastpos = 0;
@@ -524,10 +523,7 @@ int main2(int numArgs, const char *args[], char *rs)
 {
        CFileSeqInStream inStream;
        CFileOutStream outStream;
-       char c;
        int res;
-       int encodeMode;
-       Bool useOutFile = False;
 
        FileSeqInStream_CreateVTable(&inStream);
        File_Construct(&inStream.file);
@@ -535,8 +531,6 @@ int main2(int numArgs, const char *args[], char *rs)
        FileOutStream_CreateVTable(&outStream);
        File_Construct(&outStream.file);
 
-       encodeMode = 1;
-
        size_t t4 = sizeof(UInt32);
        size_t t8 = sizeof(UInt64);
        if (t4 != 4 || t8 != 8)
index be9ef1c..2c33a09 100755 (executable)
@@ -80,11 +80,11 @@ int PrintUserError(char *buffer)
 int main2(int numArgs, const char *args[], char *rs)
 {
        CFileSeqInStream inStream;
-       ISeqOutStream  outStream;
+       CFileOutStream outStream;
        int res, fd;
        int encodeMode;
-       char * buf_res = NULL;
-       unsigned charnew_data;
+       unsigned char *buf_res = NULL;
+       unsigned char *new_data;
        ssize_t new_size;
 
        FileSeqInStream_CreateVTable(&inStream);
@@ -110,7 +110,7 @@ int main2(int numArgs, const char *args[], char *rs)
                File_GetLength(&inStream.file, &fileSize);
                //res = Encode(&outStream.s, &inStream.s, fileSize, rs);
        } else {
-               UInt64 unpackSize, i, dest_len;
+               UInt64 unpackSize, i;
                CLzmaDec state;
                unsigned char header[LZMA_PROPS_SIZE + 8];
                RINOK(SeqInStream_Read(&inStream.s, header, sizeof(header)));
@@ -119,10 +119,9 @@ int main2(int numArgs, const char *args[], char *rs)
                        unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
                buf_res = (unsigned char *)malloc(unpackSize);
                memset(buf_res, 0x0, unpackSize);
-               dest_len = unpackSize;
                LzmaDec_Construct(&state);
                RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
-               res = Decode2(&state, &outStream, &inStream.s, &unpackSize, buf_res);
+               res = Decode2(&state, &outStream.s, &inStream.s, &unpackSize, buf_res);
                LzmaDec_Free(&state, &g_Alloc);
                File_Close(&inStream.file);
                if (apply_patch(args[1], buf_res, &new_data, &new_size) != 0) {
@@ -152,6 +151,7 @@ int main2(int numArgs, const char *args[], char *rs)
                free(buf_res);
                return 0;
        }
+       return 1;
 }
 
 int main(int numArgs, const char *args[])
index baad6bf..ffb5a7e 100755 (executable)
@@ -143,7 +143,7 @@ SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
        }
 }
 
-int apply_patch(char *oldfile, char *patch_buffer, unsigned char **dest_buf, ssize_t *dest_size)
+int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char **dest_buf, ssize_t *dest_size)
 {
        int fd = -1, result = 0;
        off_t oldsize, newsize;
index bd59396..3075ea2 100644 (file)
@@ -12,6 +12,6 @@ extern ISzAlloc g_Alloc;
 SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
                UInt64 *unpackSize, unsigned char *dec_data);
 
-int apply_patch(char *oldfile, char *patch_buffer, unsigned char **dest_buf, ssize_t *dest_size);
+int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char **dest_buf, ssize_t *dest_size);
 
 #endif /* _SS_BSPATCH_COMMON_H */
index 5f4c488..5bec19f 100755 (executable)
@@ -1,7 +1,7 @@
 Name:          libtota
 Summary:       fota update library
-Version:       0.2.2
-Release:       3
+Version:       0.2.3
+Release:       4
 Group:         System
 License:       Apache-2.0 and BSD-2-Clause and BSD-3-Clause and PD
 Source0:       %{name}-%{version}.tar.gz
index 7ec6975..58ce8af 100755 (executable)
@@ -34,6 +34,7 @@
 #include "fota_common.h"
 #include "sha1.h"
 #include "SS_Engine_Errors.h"
+#include "SS_FSUpdate.h"
 
 #include "ss_bspatch_common.h"
 #include <Alloc.h>
@@ -49,7 +50,7 @@ int SS_ApplyBsdiff(char *oldfile, char *newfile, char *patch, SinkFn sink, void
     UInt64 unpackSize = 0;
     CFileSeqInStream inStream;
     ISeqOutStream outStream;
-    char *buf_res = NULL;
+    unsigned char *buf_res = NULL;
     unsigned char *new_data = NULL;
     ssize_t new_size = 0;
     int result = E_SS_FAILURE;
@@ -75,12 +76,12 @@ int SS_ApplyBsdiff(char *oldfile, char *newfile, char *patch, SinkFn sink, void
     RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
 
     //decompress the patch file into buf_res
-    buf_res = (char *)SS_Malloc(unpackSize);
+    buf_res = (unsigned char *)SS_Malloc(unpackSize);
     if (!buf_res) {
         LOGE("Bad memory allocation\n");
         goto Cleanup;
     }
-    result = Decode2(&state, &outStream, &inStream.s, &unpackSize, (unsigned char *)buf_res);
+    result = Decode2(&state, &outStream, &inStream.s, &unpackSize, buf_res);
 
     LzmaDec_Free(&state, &g_Alloc);
     File_Close(&inStream.file);
index 7dd75db..23b602f 100755 (executable)
@@ -27,6 +27,7 @@
 #include <stdarg.h>
 #include <fcntl.h>
 #include <string.h>
+#include <strings.h>
 #include <sys/smack.h>
 #include <sys/wait.h>
 
@@ -111,7 +112,7 @@ long SS_recursive_folder_creater(const char *path, const mode_t mode)
        if (ret == 0 || ((ret == -1) && (errno == EEXIST))) {
                return 0;       //meaning the depth creation is success.
        } else if ((ret == -1) && (errno == ENOENT)) {
-               if ((ret = SS_recursive_folder_creater(temppath, mode)) == 0);
+               if ((ret = SS_recursive_folder_creater(temppath, mode)) == 0)
                        ret = mkdir(temppath, mode);
                return ret;
        } else {
index fd00053..0146afa 100755 (executable)
@@ -934,8 +934,11 @@ int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *
         result = E_SS_MALLOC_ERROR;
         goto Cleanup;
     }
-    fread(buf, 1, SS_KERNEL_DELTA_HEADER, fp);
+    ssize_t bytes_read = fread(buf, 1, SS_KERNEL_DELTA_HEADER, fp);
+    if (bytes_read != SS_KERNEL_DELTA_HEADER)
+        LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)SS_KERNEL_DELTA_HEADER);
     magic = strtok(buf, ":");
+    LOGL(LOG_SSENGINE, "magic: %s\n", magic);
     file_num = atoi(strtok(NULL, ":"));
 
     //adjust offset to start of data section before proceeding
index 6a48e54..2a9dbff 100755 (executable)
@@ -123,6 +123,19 @@ static double get_time_stamp2(void)
 }
 #endif
 
+//Check SS function if available
+int file_exist(char *filename, int type)
+{
+    struct stat buf;
+    int ret = 0;
+
+    ret = lstat(filename, &buf);
+    if (ret < 0) {
+        ret = stat(filename, &buf);
+    }
+    return (ret >= 0) ? (1) : (0);
+}
+
 long SS_GetUPIVersion(unsigned char *ver_str)
 {
     if (ver_str) {
@@ -300,19 +313,6 @@ int SS_GetUpgradeState()
     return FS_UpgradeState;
 }
 
-//Check SS function if available
-int file_exist(char *filename, int type)
-{
-    struct stat buf;
-    int ret = 0;
-
-    ret = lstat(filename, &buf);
-    if (ret < 0) {
-        ret = stat(filename, &buf);
-    }
-    return (ret >= 0) ? (1) : (0);
-}
-
 int SS_rename(const char *old_file_name, const char *new_file_name)
 {
     if (link(old_file_name, new_file_name) < 0) {
@@ -1156,6 +1156,7 @@ int SS_FSSetAttributes(ua_dataSS_t * ua_dataSS)
         pfiletype = strtok(NULL, SS_TOKEN_SPACE);
         attributSize = strtok(NULL, SS_TOKEN_SPACE);
         pattribs = strtok(NULL, SS_TOKEN_NEWLINE);
+        LOG("\nSS_FSSetAttributes [%s][%s][%s]", pfiletype, attributSize, pattribs);
         if (pattribs && pfilePath && pfiletype) {
             ulAttribSize = strlen(pattribs);
             //LOG("\nSS_SetFileAttributes [%s][%s][%d][%s]",pfilePath,pfiletype,ulAttribSize, pattribs );
@@ -1962,8 +1963,11 @@ int SS_IMGUpdatemain(ua_dataSS_t * ua_dataSS, int update_type)  //SS_FSUpdatePar
 
         FILE *fp = NULL;
         char buf[14] = { 0, };  //to store zImage-delta magic keyword
+        ssize_t bytes_read;
         fp = fopen(SS_PATCHFILE_SOURCE, "r");
-        fread(buf, 1, 13, fp);        //error check not required as any delta corruption will be caught in SS_UpdateDeltaIMG
+        bytes_read = fread(buf, 1, 13, fp);        //error check not required as any delta corruption will be caught in SS_UpdateDeltaIMG
+        if (bytes_read != 13)
+            LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)13);
         fclose(fp);
 
         if (strcmp(buf, SS_KERNEL_MAGIC) == 0)
index b8bda64..8f8226e 100755 (executable)
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include "SS_Engine_Update.h"
 #include "SS_Engine_Errors.h"
+#include "SS_FSUpdate.h"
 #include "fota_common.h"
 #include "fota_tar.h"
 #include "ua.h"
@@ -826,6 +827,7 @@ int tar_extract_folder(char *tar, char *item, char *path)
     char dirPath[512] = { 0 };
     int getheader = 1;          // Asuming initial header is TAR header
     char fullname[512] = { 0 };
+    int ret;
     LOG("Extracting Folder from %s %s to %s\n", tar, item, path);
 
     data_offset = tar_get_item_offset(tar, item);
@@ -888,7 +890,9 @@ int tar_extract_folder(char *tar, char *item, char *path)
                 memset(dirPath, 0, sizeof(dirPath));
                 sprintf(dirPath, "%s/%s", path, fullname + folderpathlen);
                 LOG(" Creating Symlink [%s][%s]\n", name, dirPath);
-                symlink(name, dirPath); // use ss_link
+                ret = symlink(name, dirPath); // use ss_link
+                if (ret < 0)
+                    LOG("Error with symlink: %d\n", errno);
             }
             break;
         case '3':