]> granicus.if.org Git - openjpeg/commitdiff
[trunk] Remove old function tgt_create
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 1 Oct 2012 15:29:36 +0000 (15:29 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 1 Oct 2012 15:29:36 +0000 (15:29 +0000)
Fix some warnings about size_t

src/bin/jpip/opj_jpip_addxml.c
src/lib/openjp2/event.c
src/lib/openjp2/tcd.c
src/lib/openjp2/tgt.c
src/lib/openjp2/tgt.h

index f136e913a13917e235889af841f692773203d78e..84890b558ee2fad5588d679f9acdb85726f776d4 100644 (file)
@@ -51,6 +51,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 
 /**
@@ -78,7 +79,7 @@ int main(int argc, char *argv[])
   long fsize, boxsize;
 
   if( argc<3){
-    fprintf( stderr, "USAGE: ./addXMLinJP2 modifing.jp2 adding.xml\n");
+    fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] );
     return -1;
   }
 
@@ -87,6 +88,7 @@ int main(int argc, char *argv[])
     return -1;
   
   xmldata = read_xmlfile( argv[2], &fsize);
+  if( fsize < 0 ) return -1;
   boxsize = fsize + 8;
 
   fputc( (boxsize>>24)&0xff, fp);
@@ -94,7 +96,7 @@ int main(int argc, char *argv[])
   fputc( (boxsize>>8)&0xff, fp);
   fputc( boxsize&0xff, fp);
   fwrite( type, 4, 1, fp);
-  fwrite( xmldata, fsize, 1, fp);
+  fwrite( xmldata, (size_t)fsize, 1, fp);
   
   free( xmldata);
   fclose(fp);
@@ -159,6 +161,7 @@ char * read_xmlfile( const char filename[], long *fsize)
     fclose( fp);
     return NULL;
   }
+  assert( *fsize >= 0 );
 
   if( fseek( fp, 0, SEEK_SET) == -1){
     fprintf( stderr, "XML file %s broken (seek error)\n", filename);
@@ -166,9 +169,9 @@ char * read_xmlfile( const char filename[], long *fsize)
     return NULL;
   }
 
-  data = (char *)malloc( *fsize);
+  data = (char *)malloc( (size_t)*fsize);
   
-  if( fread( data, *fsize, 1, fp) != 1){
+  if( fread( data, (size_t)*fsize, 1, fp) != 1){
     fprintf( stderr, "XML file %s broken (read error)\n", filename);
     free( data);
     fclose(fp);
index 23978b5b0dffe83ed4c3c76ccb46ccfbdcb012b9..fa5056194ffe8751339eb03e09389a97b4036746 100644 (file)
@@ -97,7 +97,7 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ..
 
        if ((fmt != NULL) && (event_mgr != NULL)) {
                va_list arg;
-               int str_length/*, i, j*/; /* UniPG */
+               size_t str_length/*, i, j*/; /* UniPG */
                char message[MSG_SIZE];
                memset(message, 0, MSG_SIZE);
                /* initialize the optional parameter list */
@@ -148,7 +148,7 @@ opj_bool opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_type, const ch
 
        if ((fmt != 00) && (p_event_mgr != 00)) {
                va_list arg;
-               int str_length/*, i, j*/; /* UniPG */
+               size_t str_length/*, i, j*/; /* UniPG */
                char message[MSG_SIZE];
                memset(message, 0, MSG_SIZE);
                /* initialize the optional parameter list */
index d7725141e01f2c4171fe0fd5c4414e9d29766b3a..e7ad80315dbddfbfc2f3a97ce92ecf2199cd2986 100644 (file)
@@ -919,7 +919,7 @@ opj_bool FUNCTION (     opj_tcd_v2_t *p_tcd,                        \
                                         }                                                                                                                                                                         \
                                                                                                                                                                                                                   \
                                         if (! l_current_precinct->incltree) {                                                                                                                                     \
-                                                l_current_precinct->incltree = tgt_create_v2(l_current_precinct->cw,                                                                                              \
+                                                l_current_precinct->incltree = tgt_create(l_current_precinct->cw,                                                                                              \
                                                                 l_current_precinct->ch);                                                                                                                          \
                                         }                                                                                                                                                                         \
                                         else{                                                                                                                                                                     \
@@ -934,7 +934,7 @@ opj_bool FUNCTION (     opj_tcd_v2_t *p_tcd,                        \
                                         }                                                                                                                                                                         \
                                                                                                                                                                                                                   \
                                         if (! l_current_precinct->imsbtree) {                                                                                                                                     \
-                                                l_current_precinct->imsbtree = tgt_create_v2(                                                                                                                     \
+                                                l_current_precinct->imsbtree = tgt_create(                                                                                                                     \
                                                                 l_current_precinct->cw,                                                                                                                           \
                                                                 l_current_precinct->ch);                                                                                                                          \
                                         }                                                                                                                                                                         \
index 54bf536b06cdb3554fa3cc27d444e7b4a29982b5..4b7dfa5326c0a3d93a943c4a6919e950b03c338a 100644 (file)
 ==========================================================
 */
 
-opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) {
-        int nplh[32];
-        int nplv[32];
-        opj_tgt_node_t *node = NULL;
-        opj_tgt_node_t *parentnode = NULL;
-        opj_tgt_node_t *parentnode0 = NULL;
-        opj_tgt_tree_t *tree = NULL;
-        int i, j, k;
-        int numlvls;
-        int n;
-
-        tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
-        if(!tree) return NULL;
-        tree->numleafsh = numleafsh;
-        tree->numleafsv = numleafsv;
-
-        numlvls = 0;
-        nplh[0] = numleafsh;
-        nplv[0] = numleafsv;
-        tree->numnodes = 0;
-        do {
-                n = nplh[numlvls] * nplv[numlvls];
-                nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
-                nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
-                tree->numnodes += n;
-                ++numlvls;
-        } while (n > 1);
-        
-        /* ADD */
-        if (tree->numnodes == 0) {
-                opj_free(tree);
-                return NULL;
-        }
-
-        tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
-        if(!tree->nodes) {
-                opj_free(tree);
-                return NULL;
-        }
-
-        node = tree->nodes;
-        parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv];
-        parentnode0 = parentnode;
-        
-        for (i = 0; i < numlvls - 1; ++i) {
-                for (j = 0; j < nplv[i]; ++j) {
-                        k = nplh[i];
-                        while (--k >= 0) {
-                                node->parent = parentnode;
-                                ++node;
-                                if (--k >= 0) {
-                                        node->parent = parentnode;
-                                        ++node;
-                                }
-                                ++parentnode;
-                        }
-                        if ((j & 1) || j == nplv[i] - 1) {
-                                parentnode0 = parentnode;
-                        } else {
-                                parentnode = parentnode0;
-                                parentnode0 += nplh[i];
-                        }
-                }
-        }
-        node->parent = 0;
-        
-        tgt_reset(tree);
-        
-        return tree;
-}
-
-opj_tgt_tree_t *tgt_create_v2(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
+opj_tgt_tree_t *tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
         OPJ_INT32 nplh[32];
         OPJ_INT32 nplv[32];
         opj_tgt_node_t *node = 00;
index d3880f1363e85cab69c5408525d7c8e938457f75..415eee2d28fc06af3f6af9730150f1696c5ff2d3 100644 (file)
@@ -75,8 +75,7 @@ Create a tag-tree
 @param numleafsv Height of the array of leafs of the tree
 @return Returns a new tag-tree if successful, returns NULL otherwise
 */
-opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
-opj_tgt_tree_t *tgt_create_v2(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv);
+opj_tgt_tree_t *tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv);
 
 /**
  * Reinitialises a tag-tree from an exixting one.