]> www.wagner.pp.ru Git - oss/catdoc.git/commitdiff
Make clang static analyzer 3.5 happy
authorVictor Wagner <vitus@wagner.pp.ru>
Tue, 26 Apr 2016 07:01:20 +0000 (10:01 +0300)
committerVictor Wagner <vitus@wagner.pp.ru>
Tue, 26 Apr 2016 07:01:20 +0000 (10:01 +0300)
src/charsets.c
src/fileutil.c
src/ole.c
src/sheet.c
src/xlsparse.c

index 4ee0f4c09902a63ff792451b1584d7b9461ec5a2..a81ceebe1a1bb6f8f7e1d38a1379a8c85e7fac77 100644 (file)
@@ -46,13 +46,14 @@ CHARSET make_reverse_map(short int *charset) {
        int i,j,k,l;
        short int *p;   
        if (! charset) {
+               free(newmap);
                return NULL;
        }       
        for (i=0;i<256;i++) {
                k= charset[i];
                j=  (unsigned)k>>8;
                if (!newmap[j]) {
-                       newmap[j] = malloc(sizeof(short int *)*256);
+                       newmap[j] = (short int *)malloc(sizeof(short int)*256);
                        if (!newmap[j]) {
                                fprintf(stderr,"Insufficient memory for  charset\n");
                                exit(1);
@@ -72,7 +73,7 @@ CHARSET make_reverse_map(short int *charset) {
 short int * read_charset(const char *filename) {
        char *path;
        FILE *f;
-       short int *new=calloc(sizeof(short int),256);
+       short int *new;
        int c;
        long int uc;
        path= find_file(stradd(filename,CHARSET_EXT),charset_path);
@@ -89,6 +90,7 @@ short int * read_charset(const char *filename) {
        if (input_buffer)
                setvbuf(f,input_buffer,_IOFBF,FILE_BUFFER);
        /* defaults */
+       new = calloc(sizeof(short int),256);
        for (c=0;c<32;c++) {
                new[c]=c;
        }
index ce616c2ea112d170894a7d95dbf7679d00437e1c..86139ecdb833e332679d5ec03078b7198319713c 100644 (file)
@@ -180,14 +180,16 @@ void list_charsets(void) {
        char *q;
        char path_buf[PATH_BUF_SIZE];
        char dir_sep[2]={DIR_SEP,0};
+       char **ptr;
 #ifdef __MSDOS__
        struct ffblk ffblock;
        int res,col;
 #else
        glob_t glob_buf;
        int count,glob_flags=GLOB_ERR;
+
+       memset(&glob_buf,0,sizeof(glob_t));
 #endif
-       char **ptr;
        for (p=charset_path;p;p=(q?(q+1):NULL)) {
                q=strchr(p,LIST_SEP);
                if (q) {
index 5267dfa29f1b0bb0e000bbb0a0cf417e8fac0ca7..d1c731ddf8a309127428d168096e1ec38c1fba7f 100644 (file)
--- a/src/ole.c
+++ b/src/ole.c
@@ -328,6 +328,7 @@ FILE *ole_readdir(FILE *f) {
                (e->startBlock <=
                 fileLength/(e->isBigBlock ? sectorSize : shortSectorSize))) {
                if((e->blocks=malloc(chainMaxLen*sizeof(long int))) == NULL ) {
+                       free(e);
                        return NULL;
                }
                while(1) {
index 6d798c88d6a150467f5baf88a89f907a3cd77c63..ec1f0c3fe7be1892fd7d353da5e6a5ded9976ed1 100644 (file)
@@ -34,7 +34,9 @@ unsigned char **allocate (int row,int col) {
        }
        if (col>=rowptr[row].end) {
                newcol=(col/16+1)*16;
-               rowptr[row].cells=realloc(rowptr[row].cells,newcol*sizeof(char *));
+               rowptr[row].cells=
+                  (unsigned char**)realloc(rowptr[row].cells,
+                                           newcol*sizeof(unsigned char *));
                if (rowptr[row].cells == NULL) {
                        perror("allocating row");
                        exit(1);
index 372eb087bbeefbd6f8b132c424514f86410469de..5dd9b3845bbc6ac3116f215a54739a17983b4517 100644 (file)
@@ -49,11 +49,13 @@ void do_table(FILE *input,char *filename) {
                        if (reclen==8 || reclen==16) {
                                if (biff_version == 0x0809 ) {
                                        itemsread=catdoc_read(rec,4,1,input);
+                                       if (itemsread == 0) 
+                                               break;
                                        build_year=getshort(rec+2,0);
                                        build_rel=getshort(rec,0);
                                        (void) build_rel;
                                        if(build_year > 5 ) {
-                                               itemsread=catdoc_read(rec,8,1,input);
+                                               catdoc_read(rec,8,1,input);
                                                biff_version=8;
                                                offset=12;
                                        }
@@ -86,19 +88,20 @@ void do_table(FILE *input,char *filename) {
        }    
        while(itemsread){
                unsigned char buffer[2];
-               rectype = 0;
+
                itemsread = catdoc_read(buffer, 2, 1, input);
                if (catdoc_eof(input)) {
                        process_item(MSEOF,0,NULL);
                        return;
                }
                
-               rectype=getshort(buffer,0);
                if(itemsread == 0)
                        break;
-               reclen=0;
 
+               rectype=getshort(buffer,0);
                itemsread = catdoc_read(buffer, 2, 1, input);
+               if(itemsread == 0)
+                       break;
                reclen=getshort(buffer,0);
                if (reclen && reclen <MAX_MS_RECSIZE &&reclen >0){
                        itemsread = catdoc_read(rec, 1, reclen, input);
@@ -440,7 +443,6 @@ unsigned char *copy_unicode_string (unsigned char **src) {
                count=**src;
                flags = *(*src+offset);
                offset --;
-               flags = *(*src+1+offset);
                if (! ( flags == 0 || flags == 1 || flags == 8 || flags == 9 ||
                                                flags == 4 || flags == 5 || flags == 0x0c || flags == 0x0d ) ) {
                        /*                      fprintf(stderr,"Strange flags = %d, returning NULL\n", flags); */
@@ -520,7 +522,6 @@ unsigned char *copy_unicode_string (unsigned char **src) {
                        }
                        d=dest+l;
                        strcpy((char *)d,(char *)c);
-                       d+=dl;
                        l+=dl;
                }      
        }
@@ -761,7 +762,7 @@ void parse_sst(unsigned char *sstbuf,int bufsize) {
        unsigned char **parsedString;/*pointer into parsed array*/ 
                        
        sstsize = getlong(sstbuf+4,0);
-       sst=malloc(sstsize*sizeof(char *));
+       sst=(unsigned char **)malloc(sstsize*sizeof(unsigned char *));
        
        if (sst == NULL) {
                perror("SST allocation error");