This is an automated email from the git hooks/post-receive script.

a_valentino-guest pushed a commit to branch master
in repository epr-api.

commit d0083a904accb6276c84fdf472a943b523550ab4
Author: Antonio Valentino <antonio.valent...@tiscali.it>
Date:   Thu Aug 14 20:50:23 2014 +0200

    Imported Upstream version 2.3~dev20140814
---
 CMakeLists.txt     | 141 +++++++++++++++++++++++++++--------------------------
 src/CMakeLists.txt |  10 ++--
 src/epr_api.h      |   2 +-
 src/epr_band.c     |  61 ++++++++++++++---------
 src/epr_bitmask.c  |  13 +++--
 src/epr_core.c     |   2 +-
 src/epr_dsd.c      |  48 +++++++++---------
 src/epr_msph.c     |  12 ++---
 src/epr_param.c    |  12 ++---
 src/epr_product.c  |  14 +++---
 10 files changed, 169 insertions(+), 146 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a6266e9..ba7d824 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,68 +1,73 @@
-# Copyright (c) 2013 Antonio Valentino <antonio.valent...@tiscali.it>
-
-
-cmake_minimum_required(VERSION 2.8)
-project(epr-api)
-
-
-# set version number
-set(EPR_API_VERSION_MAJOR 2)
-set(EPR_API_VERSION_MINOR 3)
-set(EPR_API_VERSION_PATCH 0)
-set(EPR_API_VERSION_STRING
-    
"${EPR_API_VERSION_MAJOR}.${EPR_API_VERSION_MINOR}.${EPR_API_VERSION_PATCH}")
-
-
-# options
-option(BUILD_STATIC_LIB "build the static version of the library" ON)
-option(BUILD_TESTS "build test programs" OFF)
-option(BUILD_DOCS "build Doxygen documentation" OFF)
-option(DISABLE_SYMBOL_CONTROL
-    "Do not try to control symbols that are exported by the dynamic library.
-This option can be used to fix some build issue with non standard linkers."
-    OFF)
-
-
-# testing
-enable_testing()
-
-
-# sub-directories
-add_subdirectory(src)
-
-if(BUILD_TESTS)
-    add_subdirectory(bccunit)
-endif(BUILD_TESTS)
-
-if(BUILD_DOCS)
-    add_subdirectory(docs)
-endif(BUILD_DOCS)
-
-
-# uninstall target
-configure_file(
-    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
-    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
-    IMMEDIATE @ONLY)
-
-add_custom_target(uninstall
-    COMMAND ${CMAKE_COMMAND} -P 
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
-
-
-# packaging
-include(InstallRequiredSystemLibraries)
-
-set(CPACK_GENERATOR TGZ ZIP STGZ)
-set(CPACK_SOURCE_GENERATOR TGZ ZIP)
-set(CPACK_PACKAGE_VERSION_MAJOR ${EPR_API_VERSION_MAJOR})
-set(CPACK_PACKAGE_VERSION_MINOR ${EPR_API_VERSION_MINOR})
-set(CPACK_PACKAGE_VERSION_PATCH ${EPR_API_VERSION_PATCH})
-set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt")
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
-    "Delft object-oriented radar interferometric software")
-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
-set(CPACK_SOURCE_IGNORE_FILES 
"/build.*;.*~;\\\\.git.*;\\\\.user$;\\\\.DS_Store")
-set(CPACK_STRIP_FILES TRUE)
-set(CPACK_SOURCE_STRIP_FILES TRUE)
-
-include(CPack)
+# Copyright (c) 2013-2014 Antonio Valentino <antonio.valent...@tiscali.it>
+
+
+cmake_minimum_required(VERSION 2.8)
+project(epr-api)
+
+
+# set version number
+set(EPR_API_VERSION_MAJOR 2)
+set(EPR_API_VERSION_MINOR 3)
+set(EPR_API_VERSION_PATCH 0)
+set(EPR_API_VERSION_STRING
+    
"${EPR_API_VERSION_MAJOR}.${EPR_API_VERSION_MINOR}.${EPR_API_VERSION_PATCH}")
+
+
+# NOTE: only change this when an ABI change happens
+set(EPR_API_SOVERSION 2)
+
+
+# options
+option(BUILD_STATIC_LIB "build the static version of the library" ON)
+option(BUILD_TESTS "build test programs" OFF)
+option(BUILD_DOCS "build Doxygen documentation" OFF)
+option(DISABLE_SYMBOL_CONTROL
+    "Do not try to control symbols that are exported by the dynamic library.
+This option can be used to fix some build issue with non standard linkers."
+    OFF)
+
+
+# testing
+enable_testing()
+
+
+# sub-directories
+add_subdirectory(src)
+
+if(BUILD_TESTS)
+    add_subdirectory(bccunit)
+endif(BUILD_TESTS)
+
+if(BUILD_DOCS)
+    add_subdirectory(docs)
+endif(BUILD_DOCS)
+
+
+# uninstall target
+configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+    IMMEDIATE @ONLY)
+
+add_custom_target(uninstall
+    COMMAND ${CMAKE_COMMAND} -P 
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
+
+
+# packaging
+include(InstallRequiredSystemLibraries)
+
+set(CPACK_GENERATOR TGZ ZIP STGZ)
+set(CPACK_SOURCE_GENERATOR TGZ ZIP)
+set(CPACK_PACKAGE_VERSION_MAJOR ${EPR_API_VERSION_MAJOR})
+set(CPACK_PACKAGE_VERSION_MINOR ${EPR_API_VERSION_MINOR})
+set(CPACK_PACKAGE_VERSION_PATCH ${EPR_API_VERSION_PATCH})
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
+    "Delft object-oriented radar interferometric software")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
+set(CPACK_SOURCE_IGNORE_FILES 
"/build.*;.*~;\\\\.git.*;\\\\.user$;\\\\.DS_Store")
+set(CPACK_STRIP_FILES TRUE)
+set(CPACK_SOURCE_STRIP_FILES TRUE)
+
+include(CPack)
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dae0ae3..52a0a07 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2013 Antonio Valentino <antonio.valent...@tiscali.it>
+# Copyright (c) 2013-2014 Antonio Valentino <antonio.valent...@tiscali.it>
 
 
 # sources
@@ -53,8 +53,10 @@ endif(CMAKE_C_COMPILER_ID STREQUAL GNU OR 
CMAKE_C_COMPILER_ID STREQUAL Clang)
 add_library(epr_api SHARED ${SOURCES})
 set_target_properties(epr_api PROPERTIES
     VERSION ${EPR_API_VERSION_STRING}
-    SOVERSION ${EPR_API_VERSION_MAJOR})
-target_link_libraries(epr_api m)
+    SOVERSION ${EPR_API_SOVERSION})
+if(NOT MSVC)
+    target_link_libraries(epr_api m)
+endif()
 
 
 if(BUILD_STATIC_LIB)
@@ -72,7 +74,7 @@ endif(BUILD_TESTS)
 
 # install
 install(FILES epr_api.h epr_ptrarray.h DESTINATION include COMPONENT lib)
-install(TARGETS epr_api LIBRARY DESTINATION lib COMPONENT dev)
+install(TARGETS epr_api DESTINATION lib COMPONENT dev)
 if(BUILD_STATIC_LIB)
     install(TARGETS epr_api_static ARCHIVE DESTINATION lib COMPONENT dev)
 endif(BUILD_STATIC_LIB)
diff --git a/src/epr_api.h b/src/epr_api.h
index 6dc625b..28cab3d 100644
--- a/src/epr_api.h
+++ b/src/epr_api.h
@@ -31,7 +31,7 @@ extern "C"
 #include "epr_ptrarray.h"
 
 #define EPR_PRODUCT_API_NAME_STR         "ENVISAT Product Reader API"
-#define EPR_PRODUCT_API_VERSION_STR      "2.3"
+#define EPR_PRODUCT_API_VERSION_STR      "2.3dev_pyepr082"
 
 /* needed by Doxygen */
 /** \mainpage
diff --git a/src/epr_band.c b/src/epr_band.c
index a7eb46b..133b325 100644
--- a/src/epr_band.c
+++ b/src/epr_band.c
@@ -105,9 +105,9 @@ EPR_SPtrArray* epr_create_band_ids(EPR_SProductId* 
product_id) {
         /* 2: dataset_name */
         band_id->dataset_ref = epr_get_ref_struct(product_id, 
b_tables[bt_index].descriptors[i].rec_name);
         if (band_id->dataset_ref.dataset_id == NULL) {
+            epr_free_band_id(band_id);
             epr_set_err(e_err_invalid_dataset_name,
                         "epr_create_band_ids: invalid dataset name in DDDB");
-            epr_free_band_id(band_id);
             return NULL;
         }
         /* 3: sample_offset */
@@ -134,9 +134,9 @@ EPR_SPtrArray* epr_create_band_ids(EPR_SProductId* 
product_id) {
                 } else {
                     scaling_offset = epr_get_scaling_params(product_id, 
test_block);
                     if (scaling_offset == -909.909) { /* @todo what an ugly 
return value. Eeeek!*/
+                        epr_free_band_id(band_id);
                         epr_set_err(e_err_invalid_dataset_name,
                                     "epr_create_band_ids: invalid dataset name 
in dddb");
-                        epr_free_band_id(band_id);
                         return NULL;
                     }
                     band_id->scaling_offset = scaling_offset;
@@ -153,9 +153,9 @@ EPR_SPtrArray* epr_create_band_ids(EPR_SProductId* 
product_id) {
                 } else {
                     scaling_factor = epr_get_scaling_params(product_id, 
test_block);
                     if (scaling_factor == -909.909) { /* @todo what an ugly 
return value. Eeeek!*/
+                        epr_free_band_id(band_id);
                         epr_set_err(e_err_invalid_dataset_name,
                                     "epr_create_band_ids: invalid dataset name 
in dddb");
-                        epr_free_band_id(band_id);
                         return NULL;
                     }
                     band_id->scaling_factor = scaling_factor;
@@ -168,9 +168,9 @@ EPR_SPtrArray* epr_create_band_ids(EPR_SProductId* 
product_id) {
         if (b_tables[bt_index].descriptors[i].flag_coding_name != NULL) {
             band_id->flag_coding = epr_create_flag_coding(product_id, 
b_tables[bt_index].descriptors[i].flag_coding_name);
             if (band_id->flag_coding == NULL) {
+                epr_free_band_id(band_id);
                 epr_set_err(e_err_out_of_memory,
                             "epr_create_band_ids: out of memory");
-                epr_free_band_id(band_id);
                 return NULL;
             }
         } else {
@@ -644,8 +644,10 @@ int epr_read_band_raster(EPR_SBandId* band_id,
                                            offset_x,
                                            offset_y,
                                            raster) != 0) {
+            /* Do not shadow the original error message that appears to be 
more informative
             epr_set_err(e_err_file_read_error,
                         "epr_read_band_raster: unsuccessfully reading band 
measurement data");
+            */
             return epr_get_last_err_code();
         }
         if (band_id->bm_expr != NULL) {
@@ -658,7 +660,6 @@ int epr_read_band_raster(EPR_SBandId* band_id,
                                           raster->source_step_x,
                                           raster->source_step_y);
 
-
             /* rd_bm = */ epr_read_bitmask_raster(product_id,
                                             band_id->bm_expr,
                                             offset_x,
@@ -747,16 +748,16 @@ int epr_read_band_measurement_data(EPR_SBandId* band_id,
     datatype_id = field_info->data_type_id;
 
     /* if the user raster (or part of) is outside bbox in source coordinates*/
-    if (offset_x + raster->raster_width > (int)scan_line_length) {
+    if (offset_x + raster->source_width > (int)scan_line_length) {
+        epr_free_record(record);
         epr_set_err(e_err_illegal_arg,
                     "epr_read_band_measurement_data: raster x co-ordinates out 
of bounds");
-        epr_free_record(record);
         return epr_get_last_err_code();
     }
-    if (offset_y + raster->raster_height > (int)(rec_numb)) {
+    if (offset_y + raster->source_height > (int)(rec_numb)) {
+        epr_free_record(record);
         epr_set_err(e_err_illegal_arg,
                     "epr_read_band_measurement_data: raster y co-ordinates out 
of bounds");
-        epr_free_record(record);
         return epr_get_last_err_code();
     }
     raster_pos = 0;
@@ -765,15 +766,21 @@ int epr_read_band_measurement_data(EPR_SBandId* band_id,
     /*select the correspondent function to scaling and transform data type*/
     decode_func = select_line_decode_function(band_datatype, band_smod, 
datatype_id);
     if (decode_func == NULL) {
+        epr_free_record(record);
         epr_set_err(e_err_illegal_data_type,
                     "epr_read_band_measurement_data: internal error: unknown 
data type");
-        epr_free_record(record);
         return epr_get_last_err_code();
     }
 
     scene_width = band_id->product_id->scene_width;
     if (band_id->lines_mirrored) {
         offset_x_mirrored = (scene_width - 1) - (offset_x + 
raster->source_width - 1);
+        /* the extra offset is used to accomodate the the effect of sampling 
step
+         * greather than one in case of mirrored lines */
+        {
+            int extra_offset = raster->source_width - ((raster->raster_width - 
1) * raster->source_step_x + 1);
+            offset_x_mirrored += extra_offset;
+        }
     } else {
         offset_x_mirrored = offset_x;
     }
@@ -803,9 +810,9 @@ int epr_read_band_measurement_data(EPR_SBandId* band_id,
         } else if (band_datatype == e_tid_uint || band_datatype == e_tid_int) {
             mirror_uint_array((uint*)raster->buffer, raster->raster_width, 
raster->raster_height);
         } else {
+            epr_free_record(record);
             epr_set_err(e_err_illegal_data_type,
                         "epr_read_band_measurement_data: internal error: 
unknown data type");
-            epr_free_record(record);
             return epr_get_last_err_code();
         }
     }
@@ -848,13 +855,14 @@ int epr_read_band_annotation_data(EPR_SBandId* band_id,
     int iY, raster_pos, delta_raster_pos;
     EPR_FArrayTransformer transform_array_func = NULL;
     int y_beg, y_end, y_beg_old, y_end_old;
-    /* int offset_x_mirrored = 0; */
+    int offset_x_mirrored = 0;
     uint num_elems = 0;
     float y_mod = 0;
     float scan_offset_x = 0;
     float scan_offset_y = 0;
     void* line_beg_buffer = NULL;
     void* line_end_buffer = NULL;
+    uint scene_width = 0;
 
     product_id = band_id->product_id;
 
@@ -897,8 +905,8 @@ int epr_read_band_annotation_data(EPR_SBandId* band_id,
             scan_offset_x = 6.0F;
             samples_per_tie_pt = 50;
         } else {
-            epr_set_err(e_err_invalid_value, "epr_read_band_annotation_data: 
internal error: illegal value for samples_per_tie_pt");
             epr_free_record(record);
+            epr_set_err(e_err_invalid_value, "epr_read_band_annotation_data: 
internal error: illegal value for samples_per_tie_pt");
             return epr_get_last_err_code();
         }
     } else if ((strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 
0) ||
@@ -914,42 +922,42 @@ int epr_read_band_annotation_data(EPR_SBandId* band_id,
         lines_per_tie_pt = epr_get_scene_height(product_id) / (num_rec - 1);
         num_elems = field_info->num_elems;
     } else {
+        epr_free_record(record);
         epr_set_err(e_err_illegal_arg,
                     "epr_read_band_annotation_data: unhandled ENVISAT product 
type");
-        epr_free_record(record);
         return epr_get_last_err_code();
     }
 
     /*memory allocate for the increasingly begin tie point line*/
     line_beg_buffer = calloc(sizeof(float), num_elems);
     if (line_beg_buffer == NULL) {
-        epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out 
of memory");
         epr_free_record(record);
+        epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out 
of memory");
         return epr_get_last_err_code();
     }
     /*memory allocate for the increasingly end tie point line*/
     line_end_buffer = calloc(sizeof(float), num_elems);
     if (line_end_buffer == NULL)  {
-        epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out 
of memory");
         epr_free_record(record);
         free(line_beg_buffer);
+        epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out 
of memory");
         return epr_get_last_err_code();
     }
     /* if the user raster (or its part) is outside of orbit in source 
coordinates*/
     if (offset_x + raster->raster_width > (int)scan_line_length) {
-        epr_set_err(e_err_illegal_arg,
-                    "epr_read_band_data: raster x co-ordinates out of bounds");
         epr_free_record(record);
         free(line_beg_buffer);
         free(line_end_buffer);
+        epr_set_err(e_err_illegal_arg,
+                    "epr_read_band_data: raster x co-ordinates out of bounds");
         return epr_get_last_err_code();
     }
     if (offset_y + raster->raster_height > (int)(rec_numb * lines_per_tie_pt)) 
{
-        epr_set_err(e_err_illegal_arg,
-                    "epr_read_band_data: raster y co-ordinates out of bounds");
         epr_free_record(record);
         free(line_beg_buffer);
         free(line_end_buffer);
+        epr_set_err(e_err_illegal_arg,
+                    "epr_read_band_data: raster y co-ordinates out of bounds");
         return epr_get_last_err_code();
     }
     raster_pos = 0;
@@ -969,13 +977,18 @@ int epr_read_band_annotation_data(EPR_SBandId* band_id,
     y_beg_old = 9999;
     y_end_old = 9999;
 
-    /* TODO: check
+    scene_width = band_id->product_id->scene_width;
     if (band_id->lines_mirrored) {
-        offset_x_mirrored = num_elems - (offset_x + raster->source_width - 1) 
- 1;
+        offset_x_mirrored = (scene_width - 1) - (offset_x + 
raster->source_width - 1);
+        /* the extra offset is used to accomodate the the effect of sampling 
step
+         * greather than one in case of mirrored lines */
+        {
+            int extra_offset = raster->source_width - ((raster->raster_width - 
1) * raster->source_step_x + 1);
+            offset_x_mirrored += extra_offset;
+        }
     } else {
         offset_x_mirrored = offset_x;
     }
-    */
 
     for (iY = offset_y; (uint)iY < offset_y + raster->source_height; iY += 
raster->source_step_y ) {
 
@@ -1013,7 +1026,7 @@ int epr_read_band_annotation_data(EPR_SBandId* band_id,
 
         /*get the "line" of interpolated physical values from tie point data*/
         decode_tiepoint_band(line_beg_buffer, line_end_buffer,
-                             samples_per_tie_pt, num_elems, band_id, offset_x, 
scan_offset_x, y_mod,
+                             samples_per_tie_pt, num_elems, band_id, 
offset_x_mirrored, scan_offset_x, y_mod,
                              raster->source_width, raster->source_step_x, 
raster->buffer, raster_pos);
         /*locate "data point" for the next "line"*/
         raster_pos += delta_raster_pos;
diff --git a/src/epr_bitmask.c b/src/epr_bitmask.c
index c87038a..ddefa17 100644
--- a/src/epr_bitmask.c
+++ b/src/epr_bitmask.c
@@ -258,10 +258,13 @@ void epr_resolve_bm_ref(EPR_SBmEvalContext* context, 
EPR_SBmTerm* term) {
                                             
context->bitmask_raster->source_height,
                                             
context->bitmask_raster->source_step_x,
                                             
context->bitmask_raster->source_step_y);
-            epr_read_band_raster(flag_band_id,
-                                 context->offset_x,
-                                 context->offset_y,
-                                 flag_raster);
+            if (epr_read_band_raster(flag_band_id,
+                                     context->offset_x,
+                                     context->offset_y,
+                                     flag_raster) != 0) {
+                return;
+            }
+
             /* register flag_band_id and flag_raster for later use */
             epr_add_ptr_array_elem(context->flag_band_ids, flag_band_id);
             epr_add_ptr_array_elem(context->flag_rasters, flag_raster);
@@ -373,8 +376,8 @@ EPR_SPtrArray* epr_create_flag_coding(EPR_SProductId* 
product_id, const char* fl
         /* 1: flag_name */
         epr_assign_string(&flag_def->name, 
fc_tables[fct_index].descriptors[i].id);
         if (flag_def->name == NULL) {
-            epr_set_err(e_err_out_of_memory, "epr_get_flag_coding: out of 
memory");
             epr_free_flag_def(flag_def);
+            epr_set_err(e_err_out_of_memory, "epr_get_flag_coding: out of 
memory");
             return NULL;
         }
         /* 2: dataset_name */
diff --git a/src/epr_core.c b/src/epr_core.c
index 247fa96..cc87ed0 100644
--- a/src/epr_core.c
+++ b/src/epr_core.c
@@ -235,7 +235,7 @@ void epr_set_err(EPR_EErrCode err_code, const char* 
err_message)
 }
 
 /*
-   Function:    epr_set_error
+   Function:    epr_clear_err
    Access:      public API implementation helper
    Changelog:   2002/01/05  mp initial version
  */
diff --git a/src/epr_dsd.c b/src/epr_dsd.c
index b1913ef..6a986a9 100644
--- a/src/epr_dsd.c
+++ b/src/epr_dsd.c
@@ -290,17 +290,17 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, 
int* pos)
             /* DS_NAME to be searched for */
             if (((uint)strlen(code_block) != (uint)(EPR_LENGTH_DS_NAME_FIELD)) 
|| ((uint)(strrchr(code_block, ch) - code_block) != (uint)(strlen(code_block) - 
2)))
             {
+                epr_free_dsd(dsd);
                 epr_set_err(e_err_invalid_data_format,
                     "epr_read_each_dsd: invalid dataset name format");
-                epr_free_dsd(dsd);
                 return NULL;
             }
             dsd->ds_name = epr_sub_string(code_block, 
EPR_LENGTH_DS_NAME_IDENTIFIER, strlen(code_block) - 
EPR_LENGTH_DS_NAME_IDENTIFIER - 2);
             if (dsd->ds_name == NULL)
             {
+                epr_free_dsd(dsd);
                 epr_set_err(e_err_invalid_value,
                     "epr_read_each_dsd: invalid DS_NAME value");
-                epr_free_dsd(dsd);
                 return NULL;
             }
 
@@ -311,9 +311,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
                 dsd->ds_type = epr_sub_string(code_block, 
EPR_LENGTH_DS_TYPE_IDENTIFIER, strlen(code_block) - 
EPR_LENGTH_DS_TYPE_IDENTIFIER - 1);
                 if (dsd->ds_type == NULL)
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_value,
                         "epr_read_each_dsd: invalid DS_TYPE value");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
             }
@@ -324,17 +324,17 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, 
int* pos)
             {
                 if (((uint)strlen(code_block) != 
(uint)(EPR_LENGTH_DS_FILENAME_FIELD)) || ((uint)(strrchr(code_block, ch) - 
code_block) != (uint)(strlen(code_block) - 2)))
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid dataset filename format");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
                 dsd->filename = epr_sub_string(code_block, 
EPR_LENGTH_FILENAME_IDENTIFIER, strlen(code_block) - 
EPR_LENGTH_FILENAME_IDENTIFIER - 1);
                 if (dsd->ds_name == NULL)
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid file name");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
             }
@@ -345,9 +345,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
             {
                 if (((uint)strlen(code_block) != 
(uint)(EPR_LENGTH_DS_OFFSEN_FIELD)) || (strncmp(code_block + strlen(code_block) 
- strlen("<bytes>") - 1, "<bytes>", strlen("<bytes>")) != 0))
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid dataset filename format");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
 
@@ -356,9 +356,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
                 epr_free_string(tmp);
                 if (dsd->ds_offset == -1)
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid OFFSET value");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
             }
@@ -369,9 +369,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
             {
                 if (((uint)strlen(code_block) != 
(uint)(EPR_LENGTH_DS_SIZE_FIELD)) || (strncmp(code_block + strlen(code_block) - 
strlen("<bytes>") - 1, "<bytes>", strlen("<bytes>")) != 0))
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid dataset filename format");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
                 tmp = epr_sub_string(code_block, 
EPR_LENGTH_DS_SIZE_IDENTIFIER, strlen(code_block) - strlen("<bytes>") - 
EPR_LENGTH_DS_SIZE_IDENTIFIER - 1);
@@ -379,9 +379,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
                 epr_free_string(tmp);
                 if (dsd->ds_size == -1)
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid OFFSET value");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
             }
@@ -392,9 +392,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
             {
                 if ((uint)strlen(code_block) != 
(uint)(EPR_LENGTH_NUM_DSR_FIELD))
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid dataset record number 
format");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
                 tmp = epr_sub_string(code_block, 
EPR_LENGTH_NUM_DSR_IDENTIFIER, strlen(code_block) - 
EPR_LENGTH_NUM_DSR_IDENTIFIER - 1);
@@ -402,9 +402,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
                 epr_free_string(tmp);
                 if (dsd->num_dsr == -1)
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid dsr number value");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
             }
@@ -415,9 +415,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
             {
                 if (((uint)strlen(code_block) != 
(uint)(EPR_LENGTH_DSR_SIZE_FIELD)) || (strncmp(code_block + strlen(code_block) 
- strlen("<bytes>") - 1, "<bytes>", strlen("<bytes>")) != 0))
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid dataset record size 
format");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
                 tmp = epr_sub_string(code_block, 
EPR_LENGTH_DSR_SIZE_IDENTIFIER, strlen(code_block) - strlen("<bytes>") - 
EPR_LENGTH_DSR_SIZE_IDENTIFIER - 1);
@@ -425,9 +425,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
                 epr_free_string(tmp);
                 if (dsd->dsr_size == -1)
                 {
+                    epr_free_dsd(dsd);
                     epr_set_err(e_err_invalid_data_format,
                         "epr_read_each_dsd: invalid record size value");
-                    epr_free_dsd(dsd);
                     return NULL;
                 }
             }
@@ -436,9 +436,9 @@ EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* 
pos)
             fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);
             if ((strlen(code_block) > 0) && (code_block[0] != ' '))
             {
+                epr_free_dsd(dsd);
                 epr_set_err(e_err_invalid_data_format,
                     "epr_read_each_dsd: invalid code_block, must be empty");
-                epr_free_dsd(dsd);
                 return NULL;
             }
             *pos = *pos + 1;
@@ -521,38 +521,36 @@ EPR_SPtrArray* epr_read_all_dsds(EPR_SProductId* 
product_id)
     /*dsd_begin = epr_api.epr_head_size - dsd_number * EPR_DSD_SIZE;*/
 
     if (fseek(product_id->istream, EPR_MPH_SIZE, SEEK_SET) != 0) {
-        epr_set_err(e_err_file_access_denied,
-            "epr_read_all_dsds: file seek failed");
         if (dsds_array != NULL) {
             epr_free_ptr_array(dsds_array);
         }
+        epr_set_err(e_err_file_access_denied,
+            "epr_read_all_dsds: file seek failed");
         return NULL;
     }
     field = epr_get_field(product_id->mph_record, "SPH_SIZE");
     sph_length = ((uint*) field->elems)[0];
     dsd_begin = EPR_MPH_SIZE + (uint)epr_find_first_dsd(product_id->istream, 
sph_length);
     if (dsd_begin == EPR_MPH_SIZE) {
-        epr_set_err(e_err_file_access_denied,
-            "epr_read_all_dsds: no DS_NAME in SPH");
         if (dsds_array != NULL) {
             epr_free_ptr_array(dsds_array);
         }
+        epr_set_err(e_err_file_access_denied,
+            "epr_read_all_dsds: no DS_NAME in SPH");
         return NULL;
     }
     for(dsd_index = 0; dsd_index < dsd_number; dsd_index ++) {
         if (fseek(product_id->istream, dsd_begin + dsd_index * EPR_DSD_SIZE, 
SEEK_SET) != 0) {
-            epr_set_err(e_err_file_access_denied,
-                "epr_read_all_dsds: file seek failed");
             if (dsds_array != NULL) {
                 epr_free_ptr_array(dsds_array);
             }
+            epr_set_err(e_err_file_access_denied,
+                "epr_read_all_dsds: file seek failed");
             return NULL;
         }
         code_block = epr_create_string(EPR_DSD_SIZE);
         numread = fread(code_block, 1, EPR_DSD_SIZE, product_id->istream);
         if ((uint)numread != EPR_DSD_SIZE) {
-            epr_set_err(e_err_file_read_error,
-                "epr_read_all_dsds: error in reading SPH from product data 
file");
             if (code_block != NULL) {
                 epr_free_string(code_block);
                 code_block = NULL;
@@ -560,6 +558,8 @@ EPR_SPtrArray* epr_read_all_dsds(EPR_SProductId* product_id)
             if (dsds_array != NULL) {
                 epr_free_ptr_array(dsds_array);
             }
+            epr_set_err(e_err_file_read_error,
+                "epr_read_all_dsds: error in reading SPH from product data 
file");
             return NULL;
         }
 
@@ -573,8 +573,6 @@ EPR_SPtrArray* epr_read_all_dsds(EPR_SProductId* product_id)
             dsd = epr_create_dsd(dsd_index);
 
             if (dsd == NULL) {
-                epr_set_err(e_err_out_of_memory,
-                    "epr_read_all_dsds: out of memory");
                 if (code_block != NULL) {
                     epr_free_string(code_block);
                     code_block = NULL;
@@ -588,6 +586,8 @@ EPR_SPtrArray* epr_read_all_dsds(EPR_SProductId* product_id)
                 if (dsds_array != NULL) {
                     epr_free_ptr_array(dsds_array);
                 }
+                epr_set_err(e_err_out_of_memory,
+                    "epr_read_all_dsds: out of memory");
                 return NULL;
             }
 
diff --git a/src/epr_msph.c b/src/epr_msph.c
index c0d64d1..b3df4aa 100644
--- a/src/epr_msph.c
+++ b/src/epr_msph.c
@@ -69,6 +69,7 @@ EPR_SRecord* epr_read_mph(EPR_SProductId* product_id)
         return NULL;
     }
     record = epr_parse_header("mph", code_block);
+    epr_free_string(code_block);
     if (record == NULL)
     {
         epr_set_err(e_err_invalid_record,
@@ -77,7 +78,6 @@ EPR_SRecord* epr_read_mph(EPR_SProductId* product_id)
         epr_add_ptr_array_elem(product_id->record_info_cache, record->info);
     }
 
-    epr_free_string(code_block);
     return record;
 }
 
@@ -143,6 +143,7 @@ EPR_SRecord* epr_read_sph(EPR_SProductId* product_id)
     }
 
     sph_record = epr_parse_header("sph", code_block);
+    epr_free_string(code_block);
     if (sph_record == NULL) {
         epr_set_err(e_err_invalid_record,
             "epr_read_sph: can not recognize the correct SPH from product data 
file");
@@ -150,7 +151,6 @@ EPR_SRecord* epr_read_sph(EPR_SProductId* product_id)
         epr_add_ptr_array_elem(product_id->record_info_cache, 
sph_record->info);
     }
 
-    epr_free_string(code_block);
     return sph_record;
 }
 
@@ -213,23 +213,23 @@ EPR_SRecord* epr_parse_header(const char* header_name, 
const char* ascii_source)
         pos = 0;
         token_name = epr_str_tok(code_block, seps, &pos);
         if (pos == 1) {
-            epr_set_err(e_err_invalid_keyword_name,
-                        "epr_parse_header: invalid ascii header: keyword is 
empty");
             epr_free_string(token_name);
             if (code_block != NULL) {
                 epr_free_string(code_block);
                 code_block = NULL;
             }
+            epr_set_err(e_err_invalid_keyword_name,
+                        "epr_parse_header: invalid ascii header: keyword is 
empty");
             continue;
         }
         if (pos == (int)strlen(code_block) + 1) {
-            epr_set_err(e_err_invalid_keyword_name,
-                        "epr_parse_header: invalid ascii header: keyword not 
found");
             epr_free_string(token_name);
             if (code_block != NULL) {
                 epr_free_string(code_block);
                 code_block = NULL;
             }
+            epr_set_err(e_err_invalid_keyword_name,
+                        "epr_parse_header: invalid ascii header: keyword not 
found");
             continue;
         }
         /*if STRING value*/
diff --git a/src/epr_param.c b/src/epr_param.c
index 4e59a56..5720890 100644
--- a/src/epr_param.c
+++ b/src/epr_param.c
@@ -141,25 +141,25 @@ int epr_set_dyn_dddb_params(EPR_SProductId* product_id)
         if (product_id->sph_record == NULL) {
             product_id->sph_record = epr_read_sph(product_id);
             if (product_id->sph_record == NULL) {
-                epr_set_err(e_err_file_read_error, "epr_set_param: wrong SPH");
                 epr_free_string(tmp);
+                epr_set_err(e_err_file_read_error, "epr_set_param: wrong SPH");
                 return 0;
             }
         }
 
         field = epr_get_field(product_id->sph_record, "LINE_LENGTH");
         if (field == NULL) {
+            epr_free_string(tmp);
             epr_set_err(e_err_invalid_value,
                 "epr_set_param: wrong SPH: unable to read LINE_LENGTH");
-            epr_free_string(tmp);
             return 0;
         }
 
         line_length = ((uint*) field->elems)[0];
         if (line_length == 0) {
+            epr_free_string(tmp);
             epr_set_err(e_err_invalid_value,
                 "epr_set_param: wrong SPH: LINE_LENGTH must be > 0");
-            epr_free_string(tmp);
             return 0;
         }
 
@@ -173,9 +173,9 @@ int epr_set_dyn_dddb_params(EPR_SProductId* product_id)
 
         num_tie_points_across = ((uint*) field->elems)[0];
         if (num_tie_points_across == 0) {
+            epr_free_string(tmp);
             epr_set_err(e_err_invalid_value,
                 "epr_set_param: wrong SPH: LINES_PER_TIE_PT must be > 0");
-            epr_free_string(tmp);
             return 0;
         }
 
@@ -197,17 +197,17 @@ int epr_set_dyn_dddb_params(EPR_SProductId* product_id)
 
         field = epr_get_field(product_id->sph_record, "LINE_LENGTH");
         if (field == NULL) {
+            epr_free_string(tmp);
             epr_set_err(e_err_invalid_value,
                 "epr_set_param: wrong SPH: unable to read LINE_LENGTH");
-            epr_free_string(tmp);
             return 0;
         }
 
         line_length = ((uint*) field->elems)[0];
         if (line_length == 0) {
+            epr_free_string(tmp);
             epr_set_err(e_err_invalid_value,
                 "epr_set_param: wrong SPH: LINE_LENGTH must be > 0");
-            epr_free_string(tmp);
             return 0;
         }
 
diff --git a/src/epr_product.c b/src/epr_product.c
index 9dac6c3..38ee205 100644
--- a/src/epr_product.c
+++ b/src/epr_product.c
@@ -104,9 +104,9 @@ EPR_SProductId* epr_open_product(const char* 
product_file_path) {
 
     /* Set file pointer to start of product identifier */
     if (fseek(product_id->istream, EPR_PRODUCT_ID_OFFSET, SEEK_SET) != 0) {
+        epr_close_product(product_id);
         epr_set_err(e_err_file_access_denied,
                     "epr_open_product: file seek failed");
-        epr_close_product(product_id);
         return NULL;
     }
 
@@ -114,9 +114,9 @@ EPR_SProductId* epr_open_product(const char* 
product_file_path) {
               1,
               EPR_PRODUCT_ID_STRLEN,
               product_id->istream) != (uint) EPR_PRODUCT_ID_STRLEN) {
+        epr_close_product(product_id);
         epr_set_err(e_err_file_access_denied,
                     "epr_open_product: file read failed");
-        epr_close_product(product_id);
         return NULL;
     }
 
@@ -125,9 +125,9 @@ EPR_SProductId* epr_open_product(const char* 
product_file_path) {
             (strncmp(EPR_ENVISAT_PRODUCT_ASAR,  product_id->id_string, 3) != 
0) &&
             (strncmp(EPR_ENVISAT_PRODUCT_SAR,  product_id->id_string, 3) != 0) 
&&
             (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) != 
0)) {
+        epr_close_product(product_id);
         epr_set_err(e_err_invalid_product_id,
                     "epr_open_product: invalid product identifier");
-        epr_close_product(product_id);
         return NULL;
     }
 
@@ -144,18 +144,18 @@ EPR_SProductId* epr_open_product(const char* 
product_file_path) {
 
     /* Set file to end of file in order to determine file size */
     if (fseek(product_id->istream, 0, SEEK_END) != 0) {
+        epr_close_product(product_id);
         epr_set_err(e_err_file_access_denied,
                     "epr_open_product: file seek failed");
-        epr_close_product(product_id);
         return NULL;
     }
 
     /* Get file size */
     product_id->tot_size = (uint) ftell(product_id->istream);
     if (product_id->tot_size == (uint) -1) {
+        epr_close_product(product_id);
         epr_set_err(e_err_file_access_denied,
                     "epr_open_product: failed to determine file size");
-        epr_close_product(product_id);
         return NULL;
     }
     sprintf(message_buffer, "product size: %u", product_id->tot_size);
@@ -163,9 +163,9 @@ EPR_SProductId* epr_open_product(const char* 
product_file_path) {
 
     /* Set file pointer back to start */
     if (fseek(product_id->istream, 0, SEEK_SET) != 0) {
+        epr_close_product(product_id);
         epr_set_err(e_err_file_access_denied,
                     "epr_open_product: file seek failed");
-        epr_close_product(product_id);
         return NULL;
     }
 
@@ -187,9 +187,9 @@ EPR_SProductId* epr_open_product(const char* 
product_file_path) {
     product_id->dsd_array = epr_read_all_dsds(product_id);
     compare_ok = epr_compare_param(product_id);
     if (compare_ok == 0) {
+        epr_close_product(product_id);
         epr_set_err(e_err_invalid_value,
                     "epr_open_product: MPH_SIZE+SPH_SIZE must be equal to 
DSD[0].DS_OFFSET");
-        epr_close_product(product_id);
         return NULL;
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-grass/epr-api.git

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to