#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
/**
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;
}
return -1;
xmldata = read_xmlfile( argv[2], &fsize);
+ if( fsize < 0 ) return -1;
boxsize = fsize + 8;
fputc( (boxsize>>24)&0xff, fp);
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);
fclose( fp);
return NULL;
}
+ assert( *fsize >= 0 );
if( fseek( fp, 0, SEEK_SET) == -1){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
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);
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 */
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 */
} \
\
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{ \
} \
\
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); \
} \
==========================================================
*/
-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;
@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.