[SCM] libmysofa/master: New upstream version 0.6~dfsg0

umlaeute at users.alioth.debian.org umlaeute at users.alioth.debian.org
Thu Jul 20 10:45:10 UTC 2017


The following commit has been merged in the master branch:
commit f0931e8d6f52d127f38e2a2cb823c3dfcbe12192
Author: IOhannes m zmölnig <zmoelnig at umlautQ.umlaeute.mur.at>
Date:   Thu Jul 20 11:38:56 2017 +0200

    New upstream version 0.6~dfsg0

diff --git a/.appveyor.yml b/.appveyor.yml
new file mode 100644
index 0000000..0a5da67
--- /dev/null
+++ b/.appveyor.yml
@@ -0,0 +1,16 @@
+version: 1.0.{build}
+configuration: Release
+platform: x64
+install:
+- cmd: >-
+    cp "%APPVEYOR_BUILD_FOLDER%\src\hrtf\mysofa_export.h.in" "%APPVEYOR_BUILD_FOLDER%\src\hrtf\mysofa_export.h"
+
+    cp "%APPVEYOR_BUILD_FOLDER%\windows/config.h.sln" "%APPVEYOR_BUILD_FOLDER%\src\config.h"
+nuget:
+  account_feed: true
+  project_feed: true
+build:
+  project: windows/libmysofa.sln
+  verbosity: normal
+artifacts:
+- path: windows\bin
diff --git a/.cproject b/.cproject
index 6280118..cfc65e1 100644
--- a/.cproject
+++ b/.cproject
@@ -31,14 +31,6 @@
 							</tool>
 						</toolChain>
 					</folderInfo>
-					<folderInfo id="0.644635990.2049837561" name="/" resourcePath="build">
-						<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.76036489" name="No ToolChain" superClass="org.eclipse.cdt.build.core.prefbase.toolchain" unusedChildren="">
-							<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1725315471" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs.1967846793"/>
-							<tool id="org.eclipse.cdt.build.core.settings.holder.1802266900" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder.1722814120"/>
-							<tool id="org.eclipse.cdt.build.core.settings.holder.880100661" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder.1277431468"/>
-							<tool id="org.eclipse.cdt.build.core.settings.holder.1469475543" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder.1814909526"/>
-						</toolChain>
-					</folderInfo>
 					<sourceEntries>
 						<entry excluding="build" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
 					</sourceEntries>
@@ -48,15 +40,11 @@
 			<storageModule moduleId="de.marw.cdt.cmake.core.settings">
 				<options/>
 				<linux command="cmake" generator="UnixMakefiles" use-default="true">
-					<defs/>
-					<undefs/>
 				</linux>
-				<defs/>
-				<undefs/>
 				<win32 command="cmake" generator="MinGWMakefiles" use-default="true">
-					<defs/>
-					<undefs/>
 				</win32>
+				<defs/>
+				<undefs/>
 			</storageModule>
 		</cconfiguration>
 	</storageModule>
@@ -78,9 +66,16 @@
 	<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
 	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
 		<buildTargets>
+			<target name="all" path="build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
+				<buildCommand>CMAKE_BUILD_TOOL</buildCommand>
+				<buildArguments>CMAKE_BUILD_TOOL_IGN_ERR</buildArguments>
+				<buildTarget>all</buildTarget>
+				<stopOnError>false</stopOnError>
+				<useDefaultCommand>true</useDefaultCommand>
+				<runAllBuilders>true</runAllBuilders>
+			</target>
 			<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
 				<buildCommand>CMAKE_BUILD_TOOL</buildCommand>
-				<buildArguments/>
 				<buildTarget>all</buildTarget>
 				<stopOnError>true</stopOnError>
 				<useDefaultCommand>true</useDefaultCommand>
diff --git a/.gitignore b/.gitignore
index 2c228f9..c7ac9cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -76,13 +76,13 @@ crashlytics-build.properties
 *.pch
 
 # Libraries
-*.lib
+# *.lib
 *.a
 *.la
 *.lo
 
 # Shared objects (inc. Windows DLLs)
-*.dll
+# *.dll
 *.so
 *.so.*
 *.dylib
@@ -113,7 +113,7 @@ crashlytics-build.properties
 # Compiled Dynamic libraries
 *.so
 *.dylib
-*.dll
+# *.dll
 
 # Fortran module files
 *.mod
@@ -122,7 +122,7 @@ crashlytics-build.properties
 *.lai
 *.la
 *.a
-*.lib
+# *.lib
 
 # Executables
 *.exe
@@ -140,3 +140,7 @@ Session.vim
 
 # Build
 build/
+
+src/hrtf/mysofa_export.h
+src/config.h
+
diff --git a/.travis.yml b/.travis.yml
index 14a473d..22ebefa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,19 @@
-dist: trusty
-sudo: require
+matrix:
+  include:
+    - os: linux
+      dist: trusty
+      sudo: required
+    - os: osx
+      osx_image: xcode7.3
+      
 language: c
 
 before_install:
-  - sudo apt-get -qq update
-  - sudo apt-get install -y libcunit1-dev 
-  - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
+  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update  ; fi
+  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y libcunit1-dev  ; fi
+  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca- ; fi
+  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update        ; fi
+  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install cunit ; fi 
   
 before_script:
   - mkdir -p build
@@ -14,7 +22,7 @@ before_script:
 
 script:
   - pwd
-  - make -j 4 all test
+  - make all test
   
 env:
   global:
@@ -26,7 +34,6 @@ addons:
       name: "hoene/libmysofa"
       description: "Build submitted via Travis CI"
     notification_email: christian.hoene at symonics.com
-    build_command_prepend: "mkdir -p build ; cd build ; cmake -DCMAKE_BUILD_TYPE=Debug .."
-    build_command:   "make -j 4 all test"
-    branch_pattern: coverity_scan
+    build_command: make all
+    branch_pattern: coverity
     
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4d641ef..ff83449 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,23 @@
-cmake_minimum_required (VERSION 2.6)
+cmake_minimum_required (VERSION 2.8)
 project (libmysofa)
 
 INCLUDE(CheckCCompilerFlag)
+include(GenerateExportHeader)
 
 option(BUILD_TESTS "Build test programs" ON)
 option(BUILD_SHARED_LIBS "Build shared library" ON)
 
+SET(CPACK_PACKAGE_DESCRIPTION "SOFA file reader for better HRTFs")
+SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This library reads AES SOFA files and normalizes them")
+SET(CPACK_PACKAGE_VENDOR "Symonics GmbH")
+SET(CPACK_PACKAGE_CONTACT "umlaeute at debian.org")
+SET(CPACK_GENERATOR "DEB")
+SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "IOhannes m zmölnig")
+SET(CPACK_PACKAGE_VERSION_MAJOR "0")
+SET(CPACK_PACKAGE_VERSION_MINOR "5")
+SET(CPACK_PACKAGE_VERSION_PATCH "1")
+SET(CPACK_DEBIAN_PACKAGE_DEPENDS "zlib1g")
+
 CHECK_C_COMPILER_FLAG(-Wall C_HAS_WALL)
 IF(C_HAS_WALL)
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
@@ -14,36 +26,28 @@ ENDIF(C_HAS_WALL)
 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
 
 install(FILES share/default.sofa DESTINATION share/libmysofa)
+install(FILES share/MIT_KEMAR_normal_pinna.sofa DESTINATION share/libmysofa)
 
 if(BUILD_TESTS)
 
-    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")  
-    include(FindCUnit)
-    find_package(CUnit REQUIRED cunit)
+  list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+  include(FindCUnit)
+  include_directories(${CUNIT_INCLUDE_DIRS})
+
+  find_package(CUnit REQUIRED cunit)
 
-    enable_testing()
+  enable_testing()
 
-    add_test(CIPIC_subject_003_hrir_final ../tests/compare.sh ../tests/CIPIC_subject_003_hrir_final)
-    add_test(FHK_HRIR_L2354.sofa ../tests/compare.sh ../tests/FHK_HRIR_L2354)
-    add_test(LISTEN_1002_IRC_1002_C_HRIR.sofa ../tests/compare.sh ../tests/LISTEN_1002_IRC_1002_C_HRIR)
-    add_test(MIT_KEMAR_large_pinna.sofa ../tests/compare.sh ../tests/MIT_KEMAR_large_pinna)
-    add_test(Pulse ../tests/compare.sh ../tests/Pulse)
-    add_test(Tester ../tests/compare.sh ../tests/tester)
-    add_test(TU-Berlin_QU_KEMAR_anechoic_radius_0.5_1_2_3_m.sofa ../tests/compare.sh ../tests/TU-Berlin_QU_KEMAR_anechoic_radius_0.5_1_2_3_m)
-    add_test(TU-Berlin_QU_KEMAR_anechoic_radius_0.5m.sofa ../tests/compare.sh ../tests/TU-Berlin_QU_KEMAR_anechoic_radius_0.5m)
+  add_test(CIPIC_subject_003_hrir_final ../tests/compare.sh ../tests/CIPIC_subject_003_hrir_final)
+  add_test(FHK_HRIR_L2354.sofa ../tests/compare.sh ../tests/FHK_HRIR_L2354)
+  add_test(LISTEN_1002_IRC_1002_C_HRIR.sofa ../tests/compare.sh ../tests/LISTEN_1002_IRC_1002_C_HRIR)
+  add_test(MIT_KEMAR_large_pinna.sofa ../tests/compare.sh ../tests/MIT_KEMAR_large_pinna)
+  add_test(Pulse ../tests/compare.sh ../tests/Pulse)
+  add_test(Tester ../tests/compare.sh ../tests/tester)
+  add_test(TU-Berlin_QU_KEMAR_anechoic_radius_0.5_1_2_3_m.sofa ../tests/compare.sh ../tests/TU-Berlin_QU_KEMAR_anechoic_radius_0.5_1_2_3_m)
+  add_test(TU-Berlin_QU_KEMAR_anechoic_radius_0.5m.sofa ../tests/compare.sh ../tests/TU-Berlin_QU_KEMAR_anechoic_radius_0.5m)
 endif(BUILD_TESTS)
 
 add_subdirectory(src)
 
-SET(CPACK_PACKAGE_DESCRIPTION "SOFA file reader for better HRTFs")
-SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This library reads AES SOFA files and normalizes them")
-SET(CPACK_PACKAGE_VENDOR "Symonics GmbH")
-SET(CPACK_PACKAGE_CONTACT "christian.hoene at symonics.com")
-SET(CPACK_GENERATOR "DEB")
-SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Christian Hoene") 
-SET(CPACK_PACKAGE_VERSION_MAJOR "0")
-SET(CPACK_PACKAGE_VERSION_MINOR "5")
-SET(CPACK_PACKAGE_VERSION_PATCH "pre") 
-SET(CPACK_DEBIAN_PACKAGE_DEPENDS "zlib1g")
 INCLUDE(CPack)
-
diff --git a/README.md b/README.md
index 9d792fa..6d97c3d 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,21 @@
 This is a simple set of C functions to read AES SOFA files, if they contain HRTFs
 stored according to the AES69-2015 standard [http://www.aes.org/publications/standards/search.cfm?docID=99].
 
+## Badges
+
+<a href="https://travis-ci.org/hoene/libmysofa">
+	<img alt="Travis CI Status" src="https://travis-ci.org/hoene/libmysofa.svg?branch=master"/>
+</a>
+
+<a href="https://scan.coverity.com/projects/hoene-libmysofa">
+  <img alt="Coverity Scan Build Status"
+       src="https://scan.coverity.com/projects/13030/badge.svg"/>
+</a>
+
+<a href="https://https://ci.appveyor.com/project/hoene/libmysofa-s142k">
+<img alt="AppVeyor Status" src="https://ci.appveyor.com/api/projects/status/mk86lx4ux2jn9tpo/branch/master?svg=true"/>
+</a>
+
 ## Compile
 
 Enter following commands
@@ -89,6 +104,17 @@ Then, all HRTFs having the same filename and sampling rate are stored only once
 
 If your program is using several threads, you must use appropriate synchronisation mechanisms so only a single thread can access the library at a given time.
 
+## OS support
+
+Libmysofa compiles for Linux operating systems, OSX and Windows. By default, each commit is compiled with Travis CI under Ubuntu 14.04 and OSX 7.3 and with AppVeyor for Windows Visual Studio 2015 on a x64 system. In addition, FFmpeg is compiling libmysofa with MinGW under Windows using their own build system. 
+
+
+## References
+
+ * Christian Hoene and Piotr Majdak, "HDF5 under the SOFA – A 3D audio case in HDF5 on embedded and mobile devices", HDF Blog, https://www.hdfgroup.org/2017/04/hdf5-under-the-sofa-hdf5-on-embedded-and-mobile-devices/, April 26, 2017.
+ * Christian Hoene, Isabel C. Patiño Mejía, Alexandru Cacerovschi, "MySofa: Design Your Personal HRTF", Audio Engineering Society
+ Convention Paper 9764, Presented at the 142nd Convention, May 2017, Berlin, Germany, http://www.aes.org/e-lib/browse.cfm?elib=18640
+ 
 ## Disclaimer
 
 The SOFA files are from https://www.sofaconventions.org/, Piotr Majdak <piotr at majdak.com>. The K-D tree algorithm is by John Tsiombikas <nuclear at member.fsf.org>. The resampler is by Jean-Marc Valin. The remaining source code is by Christian Hoene <christian.hoene at symonics.com>, Symonics GmbH, and available under BSD-3-Clause license. This work has been funded by German Federal Ministry of Education and Research, funding code 01IS14027A.
diff --git a/build/project.json b/build/project.json
new file mode 100644
index 0000000..ce0c1c8
--- /dev/null
+++ b/build/project.json
@@ -0,0 +1,9 @@
+{
+    "dependencies": {
+        "zlib": "1.2.8.8",
+    },
+     "frameworks": {
+        ".NETFramework,Version=v4.0": { }
+    },
+    "runtimes": { "win-x64": { } }
+}
diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake
index ada87c1..22b5a70 100644
--- a/cmake/FindCUnit.cmake
+++ b/cmake/FindCUnit.cmake
@@ -9,11 +9,11 @@ pkg_check_modules(PC_CUNIT QUIET cunit)
 
 find_path(CUNIT_INCLUDE_DIR
   NAMES CUnit/CUnit.h
-  HINTS ${PC_CUNIT_INCLUDE_DIRS}
+  HINTS ${PC_CUNIT_INCLUDE_DIRS} C:/projects/cunit/include
 )
 find_library(CUNIT_LIBRARY
   NAMES cunit
-  HINTS ${PC_CUNIT_LIBRARY_DIRS}
+  HINTS ${PC_CUNIT_LIBRARY_DIRS} C:/projects/cunit/lib/Release-x64
 )
 
 if(CUNIT_INCLUDE_DIR)
diff --git a/src/.dir-locals.el b/src/.dir-locals.el
new file mode 100644
index 0000000..7a0bffa
--- /dev/null
+++ b/src/.dir-locals.el
@@ -0,0 +1,3 @@
+((nil . ((indent-tabs-mode . t)
+         (fill-column . 80)))
+ (c-mode . ((c-file-style . "BSD"))))
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c18cf7b..c7b811c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,41 +10,82 @@ endmacro(use_c99)
 
 use_c99()
 
+configure_file (config.h.in ${CMAKE_SOURCE_DIR}/src/config.h)
+
+if(NOT WIN32)
+  find_library(MATH m)
+  include(FindZLIB)
+else()
+  set(MATH "")
+  find_program(NUGET nuget)
+  if (NUGET)
+    execute_process(COMMAND ${NUGET} install zlib)
+  endif()
+  include_directories(${CMAKE_SOURCE_DIR}/windows/third-party/zlib-1.2.11/include/)
+endif()
+
+# include(FindZLIB)
+# include_directories(${ZLIB_INCLUDE_DIRS})
+# MESSAGE(STATUS "ZLIB libs" ${ZLIB_LIBRARIES})
+
+if(NOT WIN32)
+    find_library(MATH m)
+    include(FindZLIB)
+else()
+    set(MATH "")
+    find_program(NUGET nuget)
+    if (NOT NUGET)
+       message(FATAL "Cannot find nuget command line tool.\nInstall it with e.g. choco install nuget.commandline")
+    else()
+         execute_process(COMMAND ${NUGET} install zlib)
+    endif()
+    include_directories(${CMAKE_SOURCE_DIR}/windows/third-party/zlib-1.2.11/include/)
+endif()
+
+
 set(libsrc hrtf/reader.c hdf/superblock.c hdf/dataobject.c hdf/btree.c hdf/fractalhead.c hdf/gunzip.c hdf/gcol.c hrtf/check.c hrtf/spherical.c 
   hrtf/lookup.c hrtf/tools.c hrtf/kdtree.c hrtf/neighbors.c hrtf/interpolate.c hrtf/resample.c hrtf/loudness.c hrtf/minphase.c hrtf/easy.c hrtf/cache.c 
   resampler/speex_resampler.c)
 add_library(mysofa-static STATIC ${libsrc})
-target_link_libraries (mysofa-static m z)
+target_link_libraries (mysofa-static ${MATH} ${ZLIB_LIBRARIES})
 SET_TARGET_PROPERTIES(mysofa-static PROPERTIES OUTPUT_NAME mysofa CLEAN_DIRECT_OUTPUT 1 POSITION_INDEPENDENT_CODE ON)
 install(TARGETS mysofa-static
-    ARCHIVE DESTINATION lib)
+  ARCHIVE DESTINATION lib)
 
 if(BUILD_SHARED_LIBS)
   add_library(mysofa-shared SHARED ${libsrc})
-  target_link_libraries (mysofa-shared m z)
+  target_link_libraries (mysofa-shared ${MATH} ${ZLIB_LIBRARIES})
   SET_TARGET_PROPERTIES(mysofa-shared PROPERTIES OUTPUT_NAME mysofa CLEAN_DIRECT_OUTPUT 1)
-  set_property(TARGET mysofa-shared PROPERTY VERSION "0.5.0")
-  set_property(TARGET mysofa-shared PROPERTY SOVERSION 0 )
-  install(TARGETS mysofa-shared
+  set_property(TARGET mysofa-shared PROPERTY VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+  set_property(TARGET mysofa-shared PROPERTY SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR} )
+  set_property(TARGET mysofa-shared PROPERTY C_VISIBILITY_PRESET hidden)
+  GENERATE_EXPORT_HEADER(mysofa-shared BASE_NAME mysofa EXPORT_FILE_NAME ${CMAKE_SOURCE_DIR}/src/hrtf/mysofa_export.h)
+  install(TARGETS mysofa-shared 
     RUNTIME DESTINATION bin
     LIBRARY DESTINATION lib)
+else()
+  GENERATE_EXPORT_HEADER(mysofa-static BASE_NAME mysofa EXPORT_FILE_NAME ${CMAKE_SOURCE_DIR}/src/hrtf/mysofa_export.h)
 endif()
 
 install(FILES hrtf/mysofa.h DESTINATION include)
 
 if(BUILD_TESTS)
-    add_executable(mysofa2json tests/sofa2json.c tests/json.c )
-    target_link_libraries (mysofa2json mysofa-static m z)
+  add_executable(mysofa2json tests/sofa2json.c tests/json.c)
+  target_link_libraries (mysofa2json mysofa-static)
 
-    add_executable(tests tests/tests.c tests/tools.c tests/check.c tests/lookup.c tests/neighbors.c tests/interpolate.c tests/resample.c tests/loudness.c
-      tests/minphase.c tests/easy.c tests/cache.c tests/json.c)
+  add_executable(external tests/external.c tests/check.c tests/lookup.c tests/neighbors.c tests/interpolate.c tests/resample.c tests/loudness.c
+    tests/minphase.c tests/easy.c tests/cache.c tests/json.c)
+  target_link_libraries (external mysofa-shared ${CUNIT_LIBRARIES})
+  add_test(NAME external WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND external)
 
-    target_link_libraries (tests mysofa-shared cunit)
-    add_test(NAME tests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND tests)
+  add_executable(internal tests/internal.c tests/tools.c hrtf/tools.c)
+  target_link_libraries (internal m ${CUNIT_LIBRARIES})
+  add_test(NAME internal WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND internal)
+  
 
-    install(TARGETS mysofa2json
-        RUNTIME DESTINATION bin
-        ARCHIVE DESTINATION lib
-        LIBRARY DESTINATION lib)
+  install(TARGETS mysofa2json
+    RUNTIME DESTINATION bin
+    ARCHIVE DESTINATION lib
+    LIBRARY DESTINATION lib)
 endif(BUILD_TESTS)
 
diff --git a/src/config.h.in b/src/config.h.in
new file mode 100644
index 0000000..638e112
--- /dev/null
+++ b/src/config.h.in
@@ -0,0 +1,10 @@
+
+#if !defined _CONFIG_H
+#define _CONFIG_H
+
+#define CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
+#define CPACK_PACKAGE_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}
+#define CPACK_PACKAGE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}
+#define CPACK_PACKAGE_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
+
+#endif
diff --git a/src/hdf/btree.c b/src/hdf/btree.c
index 0a6145a..41eb1ea 100644
--- a/src/hdf/btree.c
+++ b/src/hdf/btree.c
@@ -1,6 +1,6 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
  
 */
 
@@ -59,10 +59,10 @@
  00000690  15 00 00 00 d3 c7 19 a0  00 00 00 00 00 00 00 00  |................|
  000006a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 
- */
+*/
 
 static int readBTLF(struct READER *reader, struct BTREE *btree,
-		int number_of_records, union RECORD *records) {
+		    int number_of_records, union RECORD *records) {
 
 	int i;
 
@@ -88,35 +88,35 @@ static int readBTLF(struct READER *reader, struct BTREE *btree,
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	type = fgetc(reader->fhd);
+	type = (uint8_t)fgetc(reader->fhd);
 
 	for (i = 0; i < number_of_records; i++) {
 
 		switch (type) {
 		case 5:
-			records->type5.hash_of_name = readValue(reader, 4);
+			records->type5.hash_of_name = (uint32_t)readValue(reader, 4);
 			records->type5.heap_id = readValue(reader, 7);
 			log(" type5 %08X %14lX\n", records->type5.hash_of_name,
-					records->type5.heap_id);
+			    records->type5.heap_id);
 			records++;
 			break;
 
 		case 6:
-			creation_order = readValue(reader, 8);
-			heap_id = readValue(reader, 7);
+			/*creation_order = */readValue(reader, 8);
+			/*heap_id = */readValue(reader, 7);
 			break;
 
 		case 8:
-			heap_id = readValue(reader, 8);
-			message_flags = fgetc(reader->fhd);
-			creation_order = readValue(reader, 4);
-			hash_of_name = readValue(reader, 4);
+			/*heap_id = */readValue(reader, 8);
+			/*message_flags = */fgetc(reader->fhd);
+			/*creation_order = */readValue(reader, 4);
+			/*hash_of_name = */readValue(reader, 4);
 			break;
 
 		case 9:
-			heap_id = readValue(reader, 8);
-			message_flags = fgetc(reader->fhd);
-			creation_order = readValue(reader, 4);
+			/*heap_id = */readValue(reader, 8);
+			/*message_flags = */fgetc(reader->fhd);
+			/*creation_order = */readValue(reader, 4);
 			break;
 
 		default:
@@ -132,13 +132,13 @@ static int readBTLF(struct READER *reader, struct BTREE *btree,
 
 /*  III.A.2. Disk Format: Level 1A2 - Version 2 B-trees
 
- 000002d0  32 1d 42 54 48 44 00 08  00 02 00 00 11 00 00 00  |2.BTHD..........|
- 000002e0  64 28 70 03 00 00 00 00  00 00 16 00 16 00 00 00  |d(p.............|
- 000002f0  00 00 00 00 30 12 d9 6e  42 54 48 44 00 09 00 02  |....0..nBTHD....|
- 00000300  00 00 0d 00 00 00 64 28  70 05 00 00 00 00 00 00  |......d(p.......|
- 00000310  16 00 16 00 00 00 00 00  00 00 e2 0d 76 5c 46 53  |............v\FS|
+    000002d0  32 1d 42 54 48 44 00 08  00 02 00 00 11 00 00 00  |2.BTHD..........|
+    000002e0  64 28 70 03 00 00 00 00  00 00 16 00 16 00 00 00  |d(p.............|
+    000002f0  00 00 00 00 30 12 d9 6e  42 54 48 44 00 09 00 02  |....0..nBTHD....|
+    00000300  00 00 0d 00 00 00 64 28  70 05 00 00 00 00 00 00  |......d(p.......|
+    00000310  16 00 16 00 00 00 00 00  00 00 e2 0d 76 5c 46 53  |............v\FS|
 
- */
+*/
 
 int btreeRead(struct READER *reader, struct BTREE *btree) {
 	char buf[4];
@@ -154,27 +154,32 @@ int btreeRead(struct READER *reader, struct BTREE *btree) {
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	btree->type = fgetc(reader->fhd);
-	btree->node_size = readValue(reader, 4);
-	btree->record_size = readValue(reader, 2);
-	btree->depth = readValue(reader, 2);
+	btree->type = (uint8_t)fgetc(reader->fhd);
+	btree->node_size = (uint32_t)readValue(reader, 4);
+	btree->record_size = (uint16_t)readValue(reader, 2);
+	btree->depth = (uint16_t)readValue(reader, 2);
 
-	btree->split_percent = fgetc(reader->fhd);
-	btree->merge_percent = fgetc(reader->fhd);
-	btree->root_node_address = readValue(reader,
-			reader->superblock.size_of_offsets);
-	btree->number_of_records = readValue(reader, 2);
-	btree->total_number = readValue(reader, reader->superblock.size_of_lengths);
+	btree->split_percent = (uint8_t)fgetc(reader->fhd);
+	btree->merge_percent = (uint8_t)fgetc(reader->fhd);
+	btree->root_node_address = (uint64_t)readValue(reader,
+					     reader->superblock.size_of_offsets);
+	btree->number_of_records = (uint16_t)readValue(reader, 2);
+	if(btree->number_of_records>0x1000)
+			return MYSOFA_UNSUPPORTED_FORMAT;
+	btree->total_number = (uint64_t)readValue(reader, reader->superblock.size_of_lengths);
 
 	/*	fseek(reader->fhd, 4, SEEK_CUR);  skip checksum */
 
+	if(btree->total_number > 0x10000000)
+		return MYSOFA_NO_MEMORY;
 	btree->records = malloc(sizeof(btree->records[0]) * btree->total_number);
 	if (!btree->records)
 		return MYSOFA_NO_MEMORY;
 	memset(btree->records, 0, sizeof(btree->records[0]) * btree->total_number);
 
 	/* read records */
-	fseek(reader->fhd, btree->root_node_address, SEEK_SET);
+	if(fseek(reader->fhd, btree->root_node_address, SEEK_SET)<0)
+		return errno;
 	return readBTLF(reader, btree, btree->number_of_records, btree->records);
 }
 
@@ -189,7 +194,7 @@ void btreeFree(struct BTREE *btree) {
 int treeRead(struct READER *reader, struct DATAOBJECT *data) {
 
 	int i, j, err, olen, elements, size, x, y, z, b, e, dy, dz, sx, sy, sz, dzy,
-			szy;
+		szy;
 	char *input, *output;
 
 	uint8_t node_type, node_level;
@@ -197,7 +202,7 @@ int treeRead(struct READER *reader, struct DATAOBJECT *data) {
 	uint32_t size_of_chunk;
 	uint32_t filter_mask;
 	uint64_t address_of_left_sibling, address_of_right_sibling, start[4],
-			child_pointer, key, store;
+		child_pointer, key, store;
 
 	char buf[4];
 
@@ -217,13 +222,15 @@ int treeRead(struct READER *reader, struct DATAOBJECT *data) {
 		return MYSOFA_INVALID_FORMAT;
 	} log("%08lX %.4s\n", (uint64_t )ftell(reader->fhd) - 4, buf);
 
-	node_type = fgetc(reader->fhd);
-	node_level = fgetc(reader->fhd);
-	entries_used = readValue(reader, 2);
+	node_type = (uint8_t)fgetc(reader->fhd);
+	node_level = (uint8_t)fgetc(reader->fhd);
+	entries_used = (uint16_t)readValue(reader, 2);
+	if(entries_used>0x1000)
+		return MYSOFA_UNSUPPORTED_FORMAT;
 	address_of_left_sibling = readValue(reader,
-			reader->superblock.size_of_offsets);
+					    reader->superblock.size_of_offsets);
 	address_of_right_sibling = readValue(reader,
-			reader->superblock.size_of_offsets);
+					     reader->superblock.size_of_offsets);
 
 	elements = 1;
 	for (j = 0; j < data->ds.dimensionality; j++)
@@ -247,8 +254,8 @@ int treeRead(struct READER *reader, struct DATAOBJECT *data) {
 		if (node_type == 0) {
 			key = readValue(reader, reader->superblock.size_of_lengths);
 		} else {
-			size_of_chunk = readValue(reader, 4);
-			filter_mask = readValue(reader, 4);
+			size_of_chunk = (uint32_t)readValue(reader, 4);
+			filter_mask = (uint32_t)readValue(reader, 4);
 			if (filter_mask) {
 				log("TREE all filters must be enabled\n");
 				free(output);
@@ -265,18 +272,20 @@ int treeRead(struct READER *reader, struct DATAOBJECT *data) {
 			}
 
 			child_pointer = readValue(reader,
-					reader->superblock.size_of_offsets);
+						  reader->superblock.size_of_offsets);
 			log(" data at %lX len %u\n", child_pointer, size_of_chunk);
 
 			/* read data */
 			store = ftell(reader->fhd);
-			if (fseek(reader->fhd, child_pointer, SEEK_SET)) {
+			if (fseek(reader->fhd, child_pointer, SEEK_SET)<0) {
 				free(output);
 				return errno;
 			}
 
-			if (!(input = malloc(size_of_chunk)))
+			if (!(input = malloc(size_of_chunk))) {
+				free(output);
 				return MYSOFA_NO_MEMORY;
+			}
 			if (fread(input, 1, size_of_chunk, reader->fhd) != size_of_chunk) {
 				free(output);
 				free(input);
@@ -334,12 +343,16 @@ int treeRead(struct READER *reader, struct DATAOBJECT *data) {
 				return MYSOFA_INTERNAL_ERROR;
 			}
 
-			fseek(reader->fhd, store, SEEK_SET);
+			if(fseek(reader->fhd, store, SEEK_SET)<0) {
+				free(output);
+				return errno;
+			}
 		}
 	}
 
 	free(output);
-	fseek(reader->fhd, 4, SEEK_CUR); /* skip checksum */
+	if(fseek(reader->fhd, 4, SEEK_CUR)<0) /* skip checksum */
+		return errno;
 
 	return MYSOFA_OK;
 }
diff --git a/src/hdf/dataobject.c b/src/hdf/dataobject.c
index 064e3e1..7549933 100644
--- a/src/hdf/dataobject.c
+++ b/src/hdf/dataobject.c
@@ -1,16 +1,16 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 /* IV.A.1.b. Version 2 Data Object Header Prefix
 
- 00000030  4f 48 44 52 02 2d d3 18  2b 53 d3 18 2b 53 d3 18  |OHDR.-..+S..+S..|
- 00000040  2b 53 d3 18 2b 53 f4 01  02 22 00 00 00 00        |+S..+S..."......|
- ....
- 00000230  00 00 00 00 00 00 00 00  00 00 00 00 f9 ba 5d c9  |..............].|
- */
+   00000030  4f 48 44 52 02 2d d3 18  2b 53 d3 18 2b 53 d3 18  |OHDR.-..+S..+S..|
+   00000040  2b 53 d3 18 2b 53 f4 01  02 22 00 00 00 00        |+S..+S..."......|
+   ....
+   00000230  00 00 00 00 00 00 00 00  00 00 00 00 f9 ba 5d c9  |..............].|
+*/
 
 #include <stdio.h>
 #include <stddef.h>
@@ -21,10 +21,10 @@
 #include "reader.h"
 
 static int readOCHK(struct READER *reader, struct DATAOBJECT *dataobject,
-		uint64_t end);
+		    uint64_t end);
 
 static struct DATAOBJECT *findDataobject(struct READER *reader,
-		uint64_t address) {
+					 uint64_t address) {
 	struct DATAOBJECT *p = reader->all;
 	while (p && p->address != address)
 		p = p->all;
@@ -40,11 +40,11 @@ static struct DATAOBJECT *findDataobject(struct READER *reader,
  *
  00000230  00 00 00 00 00 00 00 00  00 00 00 00 f9 ba 5d c9  |..............].|
 
- */
+*/
 
 static int readOHDRHeaderMessageNIL(struct READER *reader, int length) {
 
-	if (fseek(reader->fhd, length, SEEK_CUR))
+	if (fseek(reader->fhd, length, SEEK_CUR)<0)
 		return errno;
 
 	return MYSOFA_OK;
@@ -56,7 +56,7 @@ static int readOHDRHeaderMessageNIL(struct READER *reader, int length) {
  */
 
 static int readOHDRHeaderMessageDataspace(struct READER *reader,
-		struct DATASPACE *ds) {
+					  struct DATASPACE *ds) {
 
 	int i;
 
@@ -65,19 +65,19 @@ static int readOHDRHeaderMessageDataspace(struct READER *reader,
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	ds->dimensionality = fgetc(reader->fhd);
+	ds->dimensionality = (uint8_t)fgetc(reader->fhd);
 	if (ds->dimensionality > 4) {
 		log("dimensionality must be low 5\n");
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	ds->flags = fgetc(reader->fhd);
-	ds->type = fgetc(reader->fhd);
+	ds->flags = (uint8_t)fgetc(reader->fhd);
+	ds->type = (uint8_t)fgetc(reader->fhd);
 
 	for (i = 0; i < ds->dimensionality; i++) {
 		if (i < 4) {
 			ds->dimension_size[i] = readValue(reader,
-					reader->superblock.size_of_lengths);
+							  reader->superblock.size_of_lengths);
 			log("   dimension %d %lu\n", i, ds->dimension_size[i]);
 		} else
 			readValue(reader, reader->superblock.size_of_lengths);
@@ -87,7 +87,7 @@ static int readOHDRHeaderMessageDataspace(struct READER *reader,
 		for (i = 0; i < ds->dimensionality; i++) {
 			if (i < 4)
 				ds->dimension_max_size[i] = readValue(reader,
-						reader->superblock.size_of_lengths);
+								      reader->superblock.size_of_lengths);
 			else
 				readValue(reader, reader->superblock.size_of_lengths);
 
@@ -103,29 +103,29 @@ static int readOHDRHeaderMessageDataspace(struct READER *reader,
  00 03  |+S..+S..."......|
  00000050  0f 00 00 00 00 00 00 00  c9 11 00 00 00 00 00 00  |................|
  00000060  5b 12 00 00 00 00 00 00  81 12 00 00 00 00 00 00  |[...............|
- */
+*/
 
 static int readOHDRHeaderMessageLinkInfo(struct READER *reader,
-		struct LINKINFO *li) {
+					 struct LINKINFO *li) {
 
 	if (fgetc(reader->fhd) != 0) {
 		log("object OHDR link info message must have version 0\n");
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	li->flags = fgetc(reader->fhd);
+	li->flags = (uint8_t)fgetc(reader->fhd);
 
 	if (li->flags & 1)
 		li->maximum_creation_index = readValue(reader, 8);
 
 	li->fractal_heap_address = readValue(reader,
-			reader->superblock.size_of_offsets);
+					     reader->superblock.size_of_offsets);
 	li->address_btree_index = readValue(reader,
-			reader->superblock.size_of_offsets);
+					    reader->superblock.size_of_offsets);
 
 	if (li->flags & 2)
 		li->address_btree_order = readValue(reader,
-				reader->superblock.size_of_offsets);
+						    reader->superblock.size_of_offsets);
 
 	return MYSOFA_OK;
 }
@@ -138,25 +138,28 @@ static int readOHDRHeaderMessageLinkInfo(struct READER *reader,
  000007e0  00|05 02 00 01 00 00 03  0a 10 10 00 00 07 00 6d  |...............m|
  000007f0  36 00 00 00 00 00 00 ea  00 00 00 00 00 00 00 15  |6...............|
 
- */
+*/
 
 static int readOHDRHeaderMessageDatatype(struct READER *reader,
-		struct DATATYPE *dt) {
+					 struct DATATYPE *dt) {
 
 	int i, j, c, err;
 	char *buffer, *p;
 	struct DATATYPE dt2;
 
-	dt->class_and_version = fgetc(reader->fhd);
+	dt->class_and_version = (uint8_t)fgetc(reader->fhd);
 	if ((dt->class_and_version & 0xf0) != 0x10
-			&& (dt->class_and_version & 0xf0) != 0x30) {
+	    && (dt->class_and_version & 0xf0) != 0x30) {
 		log("object OHDR datatype message must have version 1 not %d\n",
-				dt->class_and_version >> 4);
+		    dt->class_and_version >> 4);
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	dt->class_bit_field = readValue(reader, 3);
-	dt->size = readValue(reader, 4);
+	dt->class_bit_field = (uint32_t)readValue(reader, 3);
+	dt->size = (uint32_t)readValue(reader, 4);
+	if(dt->size>64)
+		return MYSOFA_UNSUPPORTED_FORMAT;
+
 
 	switch (dt->class_and_version & 0xf) {
 	case 0: /* int */
@@ -166,34 +169,34 @@ static int readOHDRHeaderMessageDatatype(struct READER *reader,
 		break;
 
 	case 1: /* float */
-		dt->u.f.bit_offset = readValue(reader, 2);
-		dt->u.f.bit_precision = readValue(reader, 2);
-		dt->u.f.exponent_location = fgetc(reader->fhd);
-		dt->u.f.exponent_size = fgetc(reader->fhd);
-		dt->u.f.mantissa_location = fgetc(reader->fhd);
-		dt->u.f.mantissa_size = fgetc(reader->fhd);
-		dt->u.f.exponent_bias = readValue(reader, 4);
+		dt->u.f.bit_offset = (uint16_t)readValue(reader, 2);
+		dt->u.f.bit_precision = (uint16_t)readValue(reader, 2);
+		dt->u.f.exponent_location = (uint8_t)fgetc(reader->fhd);
+		dt->u.f.exponent_size = (uint8_t)fgetc(reader->fhd);
+		dt->u.f.mantissa_location = (uint8_t)fgetc(reader->fhd);
+		dt->u.f.mantissa_size = (uint8_t)fgetc(reader->fhd);
+		dt->u.f.exponent_bias = (uint32_t)readValue(reader, 4);
 
 		log("    FLOAT bit %d %d exponent %d %d MANTISSA %d %d OFFSET %d\n",
-				dt->u.f.bit_offset, dt->u.f.bit_precision, dt->u.f.exponent_location,
-				dt->u.f.exponent_size, dt->u.f.mantissa_location,
-				dt->u.f.mantissa_size, dt->u.f.exponent_bias);
+		    dt->u.f.bit_offset, dt->u.f.bit_precision, dt->u.f.exponent_location,
+		    dt->u.f.exponent_size, dt->u.f.mantissa_location,
+		    dt->u.f.mantissa_size, dt->u.f.exponent_bias);
 
 		/* FLOAT bit 0 32 exponent 23 8 MANTISSA 0 23 OFFSET 127    				
-		 FLOAT bit 0 64 exponent 52 11 MANTISSA 0 52 OFFSET 1023 */
+		   FLOAT bit 0 64 exponent 52 11 MANTISSA 0 52 OFFSET 1023 */
 
 		if (dt->u.f.bit_offset != 0 || dt->u.f.mantissa_location != 0
-				|| (dt->u.f.bit_precision != 32 && dt->u.f.bit_precision != 64)
-				|| (dt->u.f.bit_precision == 32
-						&& (dt->u.f.exponent_location != 23
-								|| dt->u.f.exponent_size != 8
-								|| dt->u.f.mantissa_size != 23
-								|| dt->u.f.exponent_bias != 127))
-				|| (dt->u.f.bit_precision == 64
-						&& (dt->u.f.exponent_location != 52
-								|| dt->u.f.exponent_size != 11
-								|| dt->u.f.mantissa_size != 52
-								|| dt->u.f.exponent_bias != 1023)))
+		    || (dt->u.f.bit_precision != 32 && dt->u.f.bit_precision != 64)
+		    || (dt->u.f.bit_precision == 32
+			&& (dt->u.f.exponent_location != 23
+			    || dt->u.f.exponent_size != 8
+			    || dt->u.f.mantissa_size != 23
+			    || dt->u.f.exponent_bias != 127))
+		    || (dt->u.f.bit_precision == 64
+			&& (dt->u.f.exponent_location != 52
+			    || dt->u.f.exponent_size != 11
+			    || dt->u.f.mantissa_size != 52
+			    || dt->u.f.exponent_bias != 1023)))
 			return MYSOFA_UNSUPPORTED_FORMAT;
 		break;
 
@@ -205,25 +208,31 @@ static int readOHDRHeaderMessageDatatype(struct READER *reader,
 		log("    COMPONENT %d %02X\n", dt->size, dt->class_bit_field);
 		if ((dt->class_and_version & 0xf0) != 0x30) {
 			log("object OHDR datatype message must have version 1 not %d\n",
-					dt->class_and_version >> 4);
+			    dt->class_and_version >> 4);
 			return MYSOFA_INVALID_FORMAT;
 		}
 		for (i = 0; i < (dt->class_bit_field & 0xffff); i++) {
-			buffer = malloc(64);
-			j = 0;
-			do {
-				if (j > 64) {
-					p = realloc(buffer, j);
-					if (!p) {
-						free(buffer);
-						return err;
-					}
-					buffer = p;
-				}
+			int maxsize = 0x1000;
+			buffer = malloc(maxsize);
+			if(!buffer)
+				return MYSOFA_NO_MEMORY;
+			for(j=0;j<maxsize-1;j++) {
 				c = fgetc(reader->fhd);
+				if(c<0) {
+					free(buffer);
+					return MYSOFA_READ_ERROR;
+				}
 				buffer[j] = c;
-				j++;
-			} while (c > 0);
+				if(c==0)
+					break;
+			}
+			buffer[j]=0;
+			p = realloc(buffer, j);
+			if (!p) {
+				free(buffer);
+				return errno;
+			}
+			buffer = p;
 
 			for (j = 0, c = 0; (dt->size >> (8 * j)) > 0; j++) {
 				c |= fgetc(reader->fhd) << (8 * j);
@@ -249,7 +258,7 @@ static int readOHDRHeaderMessageDatatype(struct READER *reader,
 
 	default:
 		log("object OHDR datatype message has unknown variable type %d\n",
-				dt->class_and_version & 0xf);
+		    dt->class_and_version & 0xf);
 		return MYSOFA_UNSUPPORTED_FORMAT;
 
 	}
@@ -261,7 +270,7 @@ static int readOHDRHeaderMessageDatatype(struct READER *reader,
 
  000007e0    |05 02 00 01 00 00|03  0a
 
- */
+*/
 
 static int readOHDRHeaderMessageDataFill(struct READER *reader) {
 
@@ -269,19 +278,19 @@ static int readOHDRHeaderMessageDataFill(struct READER *reader) {
 	uint8_t flags;
 	uint32_t size;
 
-	version = fgetc(reader->fhd);
+	version = (uint8_t)fgetc(reader->fhd);
 	if (version != 3) {
 		log(
-				"object OHDR data storage fill value message must have version 3 not %d\n",
-				version);
+			"object OHDR data storage fill value message must have version 3 not %d\n",
+			version);
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	flags = fgetc(reader->fhd);
+	flags = (uint8_t)fgetc(reader->fhd);
 
 	if (flags & (1 << 5)) {
-		size = readValue(reader, 4);
-		if (fseek(reader->fhd, size, SEEK_CUR))
+		size = (uint32_t)readValue(reader, 4);
+		if (fseek(reader->fhd, size, SEEK_CUR)<0)
 			return errno;
 	}
 
@@ -305,10 +314,10 @@ static int readOHDRHeaderMessageDataFill(struct READER *reader) {
  00000f30  00 00 00 00 03 00 05 00  08 00 04 00 00 54 79 70  |.............Typ|
 
 
- */
+*/
 
 static int readOHDRHeaderMessageDataLayout(struct READER *reader,
-		struct DATAOBJECT *data) {
+					   struct DATAOBJECT *data) {
 
 	int i, err;
 	unsigned size;
@@ -325,15 +334,15 @@ static int readOHDRHeaderMessageDataLayout(struct READER *reader,
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	layout_class = fgetc(reader->fhd);
+	layout_class = (uint8_t)fgetc(reader->fhd);
 
 	switch (layout_class) {
 #if 0
 	case 0:
-	data_size = readValue(reader, 2);
-	fseek(reader->fhd, data_size, SEEK_CUR);
-	log("TODO 0 SIZE %u\n", data_size);
-	break;
+		data_size = readValue(reader, 2);
+		fseek(reader->fhd, data_size, SEEK_CUR);
+		log("TODO 0 SIZE %u\n", data_size);
+		break;
 #endif
 	case 1:
 		data_address = readValue(reader, reader->superblock.size_of_offsets);
@@ -342,7 +351,7 @@ static int readOHDRHeaderMessageDataLayout(struct READER *reader,
 		break;
 
 	case 2:
-		dimensionality = fgetc(reader->fhd);
+		dimensionality = (uint8_t)fgetc(reader->fhd);
 		data_address = readValue(reader, reader->superblock.size_of_offsets);
 		log(" CHUNK %lX\n", data_address);
 		for (i = 0; i < dimensionality; i++) {
@@ -357,7 +366,7 @@ static int readOHDRHeaderMessageDataLayout(struct READER *reader,
 
 		if (validAddress(reader, data_address)) {
 			store = ftell(reader->fhd);
-			if (fseek(reader->fhd, data_address, SEEK_SET))
+			if (fseek(reader->fhd, data_address, SEEK_SET)<0)
 				return errno;
 			if (!data->data) {
 				data->data_len = size;
@@ -368,15 +377,15 @@ static int readOHDRHeaderMessageDataLayout(struct READER *reader,
 			err = treeRead(reader, data);
 			if (err)
 				return err;
-			if (fseek(reader->fhd, store, SEEK_SET))
+			if (fseek(reader->fhd, store, SEEK_SET)<0)
 				return errno;
 		}
 		break;
 
 	default:
 		log(
-				"object OHDR message data layout message has unknown layout class %d\n",
-				layout_class);
+			"object OHDR message data layout message has unknown layout class %d\n",
+			layout_class);
 		return MYSOFA_INVALID_FORMAT;
 
 	}
@@ -392,23 +401,23 @@ static int readOHDRHeaderMessageDataLayout(struct READER *reader,
  */
 
 static int readOHDRHeaderMessageGroupInfo(struct READER *reader,
-		struct GROUPINFO *gi) {
+					  struct GROUPINFO *gi) {
 
 	if (fgetc(reader->fhd) != 0) {
 		log("object OHDR group info message must have version 0\n");
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	gi->flags = fgetc(reader->fhd);
+	gi->flags = (uint8_t)fgetc(reader->fhd);
 
 	if (gi->flags & 1) {
-		gi->maximum_compact_value = readValue(reader, 2);
-		gi->minimum_dense_value = readValue(reader, 2);
+		gi->maximum_compact_value = (uint16_t)readValue(reader, 2);
+		gi->minimum_dense_value = (uint16_t)readValue(reader, 2);
 	}
 
 	if (gi->flags & 2) {
-		gi->number_of_entries = readValue(reader, 2);
-		gi->length_of_entries = readValue(reader, 2);
+		gi->number_of_entries = (uint16_t)readValue(reader, 2);
+		gi->length_of_entries = (uint16_t)readValue(reader, 2);
 	}
 	return MYSOFA_OK;
 }
@@ -426,7 +435,7 @@ static int readOHDRHeaderMessageFilterPipeline(struct READER *reader) {
 	uint16_t filter_identification_value, flags, number_client_data_values;
 	uint32_t client_data;
 	uint64_t maximum_compact_value, minimum_dense_value, number_of_entries,
-			length_of_entries;
+		length_of_entries;
 
 	UNUSED(flags);
 	UNUSED(client_data);
@@ -440,27 +449,29 @@ static int readOHDRHeaderMessageFilterPipeline(struct READER *reader) {
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	filters = fgetc(reader->fhd);
+	filters = (uint8_t)fgetc(reader->fhd);
 	if (filters > 32) {
 		log("object OHDR filter pipeline message has too many filters: %d\n",
-				filters);
+		    filters);
 		return MYSOFA_INVALID_FORMAT;
 	}
 
 	for (i = 0; i < filters; i++) {
-		filter_identification_value = readValue(reader, 2);
+		filter_identification_value = (uint16_t)readValue(reader, 2);
 		switch (filter_identification_value) {
 		case 1:
 		case 2:
 			break;
 		default:
 			log(
-					"object OHDR filter pipeline message contains unsupported filter: %d\n",
-					filter_identification_value);
+				"object OHDR filter pipeline message contains unsupported filter: %d\n",
+				filter_identification_value);
 			return MYSOFA_INVALID_FORMAT;
 		} log("  filter %d\n", filter_identification_value);
-		flags = readValue(reader, 2);
-		number_client_data_values = readValue(reader, 2);
+		flags = (uint16_t)readValue(reader, 2);
+		number_client_data_values = (uint16_t)readValue(reader, 2);
+		if(number_client_data_values > 0x1000)
+			return MYSOFA_UNSUPPORTED_FORMAT;
 		/* no name here */
 		for (j = 0; j < number_client_data_values; j++) {
 			client_data = readValue(reader, 4);
@@ -475,7 +486,7 @@ int readDataVar(struct READER *reader, struct DATAOBJECT *data,
 		struct DATATYPE *dt, struct DATASPACE *ds) {
 
 	char *buffer, number[16];
-	uint64_t reference, gcol, dataobject;
+	uint64_t reference, gcol=0, dataobject;
 	int err;
 	struct DATAOBJECT *referenceData;
 
@@ -485,7 +496,8 @@ int readDataVar(struct READER *reader, struct DATAOBJECT *data,
 			gcol = readValue(reader, 4);
 		} else {
 			gcol = readValue(reader, dt->list - dt->size);
-		} log("    GCOL %d %8lX %8lX\n",dt->list - dt->size,gcol,ftell(reader->fhd));
+		}
+		log("    GCOL %d %8lX %8lX\n",dt->list - dt->size,gcol,ftell(reader->fhd));
 /*		fseek(reader->fhd, dt->list - dt->size, SEEK_CUR); TODO: missing part in specification */
 	}
 
@@ -509,7 +521,7 @@ int readDataVar(struct READER *reader, struct DATAOBJECT *data,
 		/*
 		 * 000036e3   67 0e 00 00 00  00 00 00 00 00 00 00 00  |...g............|
 		 000036f0  00 00 00
-		 */
+		*/
 	case 6:
 		/* TODO unclear spec */
 		log("COMPONENT todo %lX %d\n", ftell(reader->fhd),dt->size);
@@ -523,22 +535,22 @@ int readDataVar(struct READER *reader, struct DATAOBJECT *data,
 		log(" REFERENCE size %d %lX\n",dt->size, reference);
 		if (!!(err = gcolRead(reader, gcol, reference, &dataobject))) {
 			return MYSOFA_OK;       /* ignore error
-            return err; */
+						   return err; */
 		}
 		referenceData = findDataobject(reader, dataobject);
 		if (referenceData)
 			buffer = referenceData->name;
 		else {
-			sprintf(number, "REF%08lX", reference);
+			sprintf(number, "REF%08lX", (long unsigned int)reference);
 			buffer = number;
 		}
 		log("    REFERENCE %lu %lX %s\n", reference, dataobject, buffer);
 /*		if(!referenceData) {
-		    return MYSOFA_UNSUPPORTED_FORMAT;
+		return MYSOFA_UNSUPPORTED_FORMAT;
 		} */
 		if (data->string) {
 			data->string = realloc(data->string,
-					strlen(data->string) + strlen(buffer) + 2);
+					       strlen(data->string) + strlen(buffer) + 2);
 			strcat(data->string, ",");
 			strcat(data->string, buffer);
 		} else {
@@ -572,7 +584,7 @@ int readDataDim(struct READER *reader, struct DATAOBJECT *da,
 }
 
 int readData(struct READER *reader, struct DATAOBJECT *da, struct DATATYPE *dt,
-		struct DATASPACE *ds) {
+	     struct DATASPACE *ds) {
 	if (ds->dimensionality == 0) {
 		ds->dimension_size[0] = 1;
 	}
@@ -580,41 +592,51 @@ int readData(struct READER *reader, struct DATAOBJECT *da, struct DATATYPE *dt,
 }
 
 /*
- IV.A.2.q. The Object Header Continuation Message
+  IV.A.2.q. The Object Header Continuation Message
 
- 10 10 00 00 07 00 6d  |...............m|
- 000007f0  36 00 00 00 00 00 00 ea  00 00 00 00 00 00 00 15  |6...............|
- */
+  10 10 00 00 07 00 6d  |...............m|
+  000007f0  36 00 00 00 00 00 00 ea  00 00 00 00 00 00 00 15  |6...............|
+*/
 
 static int readOHDRHeaderMessageContinue(struct READER *reader,
-		struct DATAOBJECT *dataobject) {
+					 struct DATAOBJECT *dataobject) {
 
 	int err;
-	uint64_t offset, length, store;
+	uint64_t offset, length;
+	long store;
 
 	offset = readValue(reader, reader->superblock.size_of_offsets);
 	length = readValue(reader, reader->superblock.size_of_lengths);
+	if(offset > 0x1000000 || length > 0x10000000)
+		return MYSOFA_UNSUPPORTED_FORMAT;
+
 	log(" continue %08lX %08lX\n", offset, length);
 
 	store = ftell(reader->fhd);
-	fseek(reader->fhd, offset, SEEK_SET);
+
+	if(fseek(reader->fhd, offset, SEEK_SET)<0)
+		return errno;
 
 	err = readOCHK(reader, dataobject, offset + length);
 	if (err)
 		return err;
 
-	fseek(reader->fhd, store, SEEK_SET);
+	if(store<0)
+		return MYSOFA_READ_ERROR;
+	if(fseek(reader->fhd, store, SEEK_SET)<0)
+		return errno;
+
 	log(" continue back\n");
 	return MYSOFA_OK;
 }
 
 /*
- IV.A.2.m. The Attribute Message
+  IV.A.2.m. The Attribute Message
 
- */
+*/
 
 static int readOHDRHeaderMessageAttribute(struct READER *reader,
-		struct DATAOBJECT *dataobject) {
+					  struct DATAOBJECT *dataobject) {
 	int err;
 
 	uint8_t flags, encoding;
@@ -634,15 +656,22 @@ static int readOHDRHeaderMessageAttribute(struct READER *reader,
 		return MYSOFA_INVALID_FORMAT;
 	}
 
-	flags = fgetc(reader->fhd);
+	flags = (uint8_t)fgetc(reader->fhd);
 
-	name_size = readValue(reader, 2);
-	datatype_size = readValue(reader, 2);
-	dataspace_size = readValue(reader, 2);
-	encoding = fgetc(reader->fhd);
+	name_size = (uint16_t)readValue(reader, 2);
+	datatype_size = (uint16_t)readValue(reader, 2);
+	dataspace_size = (uint16_t)readValue(reader, 2);
+	encoding = (uint8_t)fgetc(reader->fhd);
 
+	if(name_size>0x1000)
+		return MYSOFA_NO_MEMORY;
 	name = malloc(name_size);
-	fread(name, 1, name_size, reader->fhd);
+	if(!name)
+		return MYSOFA_NO_MEMORY;
+	if(fread(name, 1, name_size, reader->fhd)!=name_size) {
+		free(name);
+		return errno;
+	}
 	log("  attribute name %s\n", name);
 
 	if (flags & 3) {
@@ -687,29 +716,29 @@ static int readOHDRHeaderMessageAttribute(struct READER *reader,
  00000080  16 00 40 02 00 00 00 00  00 00 d2 02 00 00 00 00  |.. at .............|
  00000090  00 00 f8 02 00 00 00 00  00 00
 
- */
+*/
 
 static int readOHDRHeaderMessageAttributeInfo(struct READER *reader,
-		struct ATTRIBUTEINFO *ai) {
+					      struct ATTRIBUTEINFO *ai) {
 
 	if (fgetc(reader->fhd) != 0) {
 		log("object OHDR attribute info message must have version 0\n");
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	ai->flags = fgetc(reader->fhd);
+	ai->flags = (uint8_t)fgetc(reader->fhd);
 
 	if (ai->flags & 1)
 		ai->maximum_creation_index = readValue(reader, 2);
 
 	ai->fractal_heap_address = readValue(reader,
-			reader->superblock.size_of_offsets);
+					     reader->superblock.size_of_offsets);
 	ai->attribute_name_btree = readValue(reader,
-			reader->superblock.size_of_offsets);
+					     reader->superblock.size_of_offsets);
 
 	if (ai->flags & 2)
 		ai->attribute_creation_order_btree = readValue(reader,
-				reader->superblock.size_of_offsets);
+							       reader->superblock.size_of_offsets);
 
 	return MYSOFA_OK;
 }
@@ -718,28 +747,29 @@ static int readOHDRHeaderMessageAttributeInfo(struct READER *reader,
  * read all OHDR messages
  */
 static int readOHDRmessages(struct READER *reader,
-		struct DATAOBJECT *dataobject, uint64_t end_of_messages) {
+			    struct DATAOBJECT *dataobject, uint64_t end_of_messages) {
 
 	FILE *fhd = reader->fhd;
 	int err;
 	long end;
 
 	while (ftell(fhd) < end_of_messages - 4) { /* final gap may has a size of up to 3 */
-		uint8_t header_message_type = fgetc(fhd);
-		uint16_t header_message_size = readValue(reader, 2);
-		uint8_t header_message_flags = fgetc(fhd);
+		uint8_t header_message_type = (uint8_t)fgetc(fhd);
+		uint16_t header_message_size = (uint16_t)readValue(reader, 2);
+		uint8_t header_message_flags = (uint8_t)fgetc(fhd);
 		if ((header_message_flags & ~5) != 0) {
 			log("OHDR unsupported OHDR message flag %02X\n",
-					header_message_flags);
+			    header_message_flags);
 			return MYSOFA_UNSUPPORTED_FORMAT;
 		}
 
 		if ((dataobject->flags & (1 << 2)) != 0)
 			/* ignore header_creation_order */
-			fseek(reader->fhd, 2, SEEK_CUR);
+			if(fseek(reader->fhd, 2, SEEK_CUR)<0)
+				return errno;
 
 		log(" OHDR message type %2d offset %6lX len %4X\n", header_message_type,
-				ftell(fhd), header_message_size);
+		    ftell(fhd), header_message_size);
 
 		end = ftell(fhd) + header_message_size;
 
@@ -786,12 +816,12 @@ static int readOHDRmessages(struct READER *reader,
 			break;
 		case 21: /* Attribute Info Message */
 			if (!!(err = readOHDRHeaderMessageAttributeInfo(reader,
-					&dataobject->ai)))
+									&dataobject->ai)))
 				return err;
 			break;
 		default:
 			log("OHDR unknown header message of type %d\n",
-					header_message_type);
+			    header_message_type);
 
 			return MYSOFA_UNSUPPORTED_FORMAT;
 		}
@@ -802,13 +832,14 @@ static int readOHDRmessages(struct READER *reader,
 		}
 	}
 
-	fseek(fhd, end_of_messages + 4, SEEK_SET); /* skip checksum */
+	if(fseek(fhd, end_of_messages + 4, SEEK_SET)<0) /* skip checksum */
+		return errno;
 
 	return MYSOFA_OK;
 }
 
 static int readOCHK(struct READER *reader, struct DATAOBJECT *dataobject,
-		uint64_t end) {
+		    uint64_t end) {
 	int err;
 	char buf[4];
 
@@ -827,7 +858,7 @@ static int readOCHK(struct READER *reader, struct DATAOBJECT *dataobject,
 }
 
 int dataobjectRead(struct READER *reader, struct DATAOBJECT *dataobject,
-		char *name) {
+		   char *name) {
 	uint64_t size_of_chunk, end_of_messages;
 	int err;
 	char buf[4];
@@ -847,10 +878,11 @@ int dataobjectRead(struct READER *reader, struct DATAOBJECT *dataobject,
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	dataobject->flags = fgetc(reader->fhd);
+	dataobject->flags = (uint8_t)fgetc(reader->fhd);
 
 	if (dataobject->flags & (1 << 5)) { /* bit 5 indicated time stamps */
-		fseek(reader->fhd, 16, SEEK_CUR); /* skip them */
+		if(fseek(reader->fhd, 16, SEEK_CUR)<0) /* skip them */
+			return errno;
 	}
 
 	if (dataobject->flags & (1 << 4)) { /* bit 4 ? */
@@ -868,15 +900,16 @@ int dataobjectRead(struct READER *reader, struct DATAOBJECT *dataobject,
 	}
 
 	/* not needed
-	 if (validAddress(reader, dataobject->ai.attribute_name_btree)) {
-	 fseek(reader->fhd, dataobject->ai.attribute_name_btree, SEEK_SET);
-	 btreeRead(reader, &dataobject->attributes);
-	 }
-	 */
+	   if (validAddress(reader, dataobject->ai.attribute_name_btree)) {
+	   fseek(reader->fhd, dataobject->ai.attribute_name_btree, SEEK_SET);
+	   btreeRead(reader, &dataobject->attributes);
+	   }
+	*/
 
 	/* parse message attribute info */
 	if (validAddress(reader, dataobject->ai.fractal_heap_address)) {
-		fseek(reader->fhd, dataobject->ai.fractal_heap_address, SEEK_SET);
+		if(fseek(reader->fhd, dataobject->ai.fractal_heap_address, SEEK_SET)<0)
+			return errno;
 		fractalheapRead(reader, dataobject, &dataobject->attributes_heap);
 	}
 
@@ -889,11 +922,11 @@ int dataobjectRead(struct READER *reader, struct DATAOBJECT *dataobject,
 	}
 
 	/* no needed 
-	 if (validAddress(reader, dataobject->li.address_btree_index)) {
-	 fseek(reader->fhd, dataobject->li.address_btree_index, SEEK_SET);
-	 btreeRead(reader, &dataobject->objects);
-	 }
-	 */
+	   if (validAddress(reader, dataobject->li.address_btree_index)) {
+	   fseek(reader->fhd, dataobject->li.address_btree_index, SEEK_SET);
+	   btreeRead(reader, &dataobject->objects);
+	   }
+	*/
 
 	dataobject->all = reader->all;
 	reader->all = dataobject;
@@ -902,7 +935,7 @@ int dataobjectRead(struct READER *reader, struct DATAOBJECT *dataobject,
 }
 
 void dataobjectFree(struct READER *reader, struct DATAOBJECT *dataobject) {
-    struct DATAOBJECT **p;
+	struct DATAOBJECT **p;
     
 	btreeFree(&dataobject->attributes_btree);
 	fractalheapFree(&dataobject->attributes_heap);
diff --git a/src/hdf/fractalhead.c b/src/hdf/fractalhead.c
index 26eb4a0..5104363 100644
--- a/src/hdf/fractalhead.c
+++ b/src/hdf/fractalhead.c
@@ -1,28 +1,30 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 #include <errno.h>
+#include <assert.h>
 #include "reader.h"
 
 static int log2i(int a) {
-	return roundf(log2f(a));
+	return round(log2(a));
 }
 
 static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
-		struct FRACTALHEAP *fractalheap) {
+			   struct FRACTALHEAP *fractalheap) {
 
 	char buf[4], *name, *value;
-	int size, offset_size, length_size, err;
+	int size, offset_size, length_size, err, len;
 	uint8_t typeandversion;
 	uint64_t unknown, heap_header_address, block_offset, block_size, offset,
-			length, store;
+		length;
+	long store;
 	struct DIR *dir;
 	struct MYSOFA_ATTRIBUTE *attr;
 
@@ -42,7 +44,8 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 	}
 
 	/* ignore heap_header_address */
-	fseek(reader->fhd, reader->superblock.size_of_offsets, SEEK_CUR);
+	if(fseek(reader->fhd, reader->superblock.size_of_offsets, SEEK_CUR)<0)
+		return errno;
 
 	size = (fractalheap->maximum_heap_size + 7) / 8;
 	block_offset = readValue(reader, size);
@@ -75,9 +78,11 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 	 *
 	 */
 	do {
-		typeandversion = fgetc(reader->fhd);
+		typeandversion = (uint8_t)fgetc(reader->fhd);
 		offset = readValue(reader, offset_size);
 		length = readValue(reader, length_size);
+		if(offset>0x10000000 || length>0x10000000)
+			return MYSOFA_UNSUPPORTED_FORMAT;
 
 		log(" %d %4lX %ld %8lX\n",typeandversion,offset,length,ftell(reader->fhd));
 
@@ -94,7 +99,10 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 
 			if (!(name = malloc(length)))
 				return MYSOFA_NO_MEMORY;
-			fread(name, 1, length, reader->fhd);
+			if(fread(name, 1, length, reader->fhd)!=length) {
+				free(name);
+				return MYSOFA_READ_ERROR;
+			}
 
 			if (readValue(reader, 4) != 0x00000013) {
 				log("FHDB type 3 unsupported values");
@@ -102,19 +110,27 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 				return MYSOFA_UNSUPPORTED_FORMAT;
 			}
 
-			length = readValue(reader, 2);
+			len = (int)readValue(reader, 2);
+			if(len > 0x1000 || len<0) {
+				free(name);
+				return MYSOFA_UNSUPPORTED_FORMAT;
+			}
 
 			/* TODO: Get definition of this field */
 			unknown = readValue(reader, 6);
 			if (unknown == 0x000000020200)
 				value = NULL;
 			else if (unknown == 0x000000020000) {
-				if (!(value = malloc(length + 1))) {
+				if (!(value = malloc(len + 1))) {
 					free(name);
 					return MYSOFA_NO_MEMORY;
 				}
-				fread(value, 1, length, reader->fhd);
-				value[length] = 0;
+				if(fread(value, 1, len, reader->fhd)!=len) {
+					free(value);
+					free(name);
+					return MYSOFA_READ_ERROR;
+				}
+				value[len] = 0;
 			} else if (unknown == 0x20000020000) {
 				if (!(value = malloc(5))) {
 					free(name);
@@ -124,9 +140,10 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 			} else {
 				log("FHDB type 3 unsupported values: %12lX\n",unknown);
 				free(name);
-/*				return MYSOFA_UNSUPPORTED_FORMAT; */
+/* TODO:			return MYSOFA_UNSUPPORTED_FORMAT; */
 				return MYSOFA_OK;
-			} log(" %s = %s\n", name, value);
+			}
+			log(" %s = %s\n", name, value);
 
 			attr = malloc(sizeof(struct MYSOFA_ATTRIBUTE));
 			attr->name = name;
@@ -144,14 +161,21 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 				return MYSOFA_UNSUPPORTED_FORMAT;
 			}
 
-			length = fgetc(reader->fhd);
-			if (!(name = malloc(length + 1)))
+			len = fgetc(reader->fhd);
+			if(len < 0)
+				return MYSOFA_READ_ERROR;
+			assert(len < 0x100);
+
+			if (!(name = malloc(len + 1)))
 				return MYSOFA_NO_MEMORY;
-			fread(name, 1, length, reader->fhd);
-			name[length] = 0;
+			if(fread(name, 1, len, reader->fhd) != len) {
+				free(name);
+				return MYSOFA_READ_ERROR;
+			}
+			name[len] = 0;
 
 			heap_header_address = readValue(reader,
-					reader->superblock.size_of_offsets);
+							reader->superblock.size_of_offsets);
 
 			log("\nfractal head type 1 length %4lX name %s address %lX\n", length, name, heap_header_address);
 
@@ -166,10 +190,15 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
 			}
 
 			err = dataobjectRead(reader, &dir->dataobject, name);
-			if (err)
+			if (err) {
 				return err;
+			}
 
-			fseek(reader->fhd, store, SEEK_SET);
+			if(store < 0) {
+				return errno;
+			}
+			if(fseek(reader->fhd, store, SEEK_SET)<0)
+				return errno;
 
 		} else if (typeandversion != 0) {
 			/* TODO is must be avoided somehow */
@@ -188,12 +217,13 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
  */
 
 static int indirectblockRead(struct READER *reader,
-		struct DATAOBJECT *dataobject, struct FRACTALHEAP *fractalheap,
-		uint64_t iblock_size) {
+			     struct DATAOBJECT *dataobject, struct FRACTALHEAP *fractalheap,
+			     uint64_t iblock_size) {
 	int size, nrows, max_dblock_rows, k, n, err;
 	uint32_t filter_mask;
-	uint64_t store, heap_header_address, block_offset, child_direct_block,
-			size_filtered, child_indirect_block;
+	uint64_t heap_header_address, block_offset, child_direct_block=0,
+		size_filtered, child_indirect_block;
+	long store;
 
 	char buf[4];
 
@@ -228,7 +258,7 @@ static int indirectblockRead(struct READER *reader,
 
 	/* The maximum number of rows of direct blocks, max_dblock_rows, in any indirect block of a fractal heap is given by the following expression: */
 	max_dblock_rows = (log2i(fractalheap->maximum_direct_block_size)
-			- log2i(fractalheap->starting_block_size)) + 2;
+			   - log2i(fractalheap->starting_block_size)) + 2;
 
 	/* Using the computed values for nrows and max_dblock_rows, along with the Width of the doubling table, the number of direct and indirect block entries (K and N in the indirect block description, below) in an indirect block can be computed: */
 	if (nrows < max_dblock_rows)
@@ -241,19 +271,23 @@ static int indirectblockRead(struct READER *reader,
 
 	while (k > 0) {
 		child_direct_block = readValue(reader,
-				reader->superblock.size_of_offsets);
+					       reader->superblock.size_of_offsets);
 		if (fractalheap->encoded_length > 0) {
 			size_filtered = readValue(reader,
-					reader->superblock.size_of_lengths);
+						  reader->superblock.size_of_lengths);
 			filter_mask = readValue(reader, 4);
 		} log(">> %d %lX %d\n",k,child_direct_block,size);
 		if (validAddress(reader, child_direct_block)) {
 			store = ftell(reader->fhd);
-			fseek(reader->fhd, child_direct_block, SEEK_SET);
+			if(fseek(reader->fhd, child_direct_block, SEEK_SET)<0)
+				return errno;
 			err = directblockRead(reader, dataobject, fractalheap);
 			if (err)
 				return err;
-			fseek(reader->fhd, store, SEEK_SET);
+			if(store<0)
+				return MYSOFA_READ_ERROR;
+			if(fseek(reader->fhd, store, SEEK_SET)<0)
+				return errno;
 		}
 
 		k--;
@@ -261,16 +295,20 @@ static int indirectblockRead(struct READER *reader,
 
 	while (n > 0) {
 		child_indirect_block = readValue(reader,
-				reader->superblock.size_of_offsets);
+						 reader->superblock.size_of_offsets);
 
 		if (validAddress(reader, child_direct_block)) {
 			store = ftell(reader->fhd);
-			fseek(reader->fhd, child_indirect_block, SEEK_SET);
+			if(fseek(reader->fhd, child_indirect_block, SEEK_SET)<0)
+				return errno;
 			err = indirectblockRead(reader, dataobject, fractalheap,
-					iblock_size * 2);
+						iblock_size * 2);
 			if (err)
 				return err;
-			fseek(reader->fhd, store, SEEK_SET);
+			if(store < 0)
+				return MYSOFA_READ_ERROR;
+			if(fseek(reader->fhd, store, SEEK_SET)<0)
+				return errno;
 		}
 
 		n--;
@@ -281,21 +319,21 @@ static int indirectblockRead(struct READER *reader,
 
 /*  III.G. Disk Format: Level 1G - Fractal Heap
 
- 00000240  46 52 48 50 00 08 00 00  00 02 00 10 00 00 00 00  |FRHP............|
- 00000250  00 00 00 00 00 00 ff ff  ff ff ff ff ff ff a3 0b  |................|
- 00000260  00 00 00 00 00 00 1e 03  00 00 00 00 00 00 00 10  |................|
- 00000270  00 00 00 00 00 00 00 08  00 00 00 00 00 00 00 08  |................|
- 00000280  00 00 00 00 00 00 16 00  00 00 00 00 00 00 00 00  |................|
- 00000290  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
- 000002a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 04 00  |................|
- 000002b0  00 04 00 00 00 00 00 00  00 00 01 00 00 00 00 00  |................|
- 000002c0  28 00 01 00 29 32 00 00  00 00 00 00 01 00 60 49  |(...)2........`I|
- 000002d0  32 1d 42 54 48 44 00 08  00 02 00 00 11 00 00 00  |2.BTHD..........|
+    00000240  46 52 48 50 00 08 00 00  00 02 00 10 00 00 00 00  |FRHP............|
+    00000250  00 00 00 00 00 00 ff ff  ff ff ff ff ff ff a3 0b  |................|
+    00000260  00 00 00 00 00 00 1e 03  00 00 00 00 00 00 00 10  |................|
+    00000270  00 00 00 00 00 00 00 08  00 00 00 00 00 00 00 08  |................|
+    00000280  00 00 00 00 00 00 16 00  00 00 00 00 00 00 00 00  |................|
+    00000290  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
+    000002a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 04 00  |................|
+    000002b0  00 04 00 00 00 00 00 00  00 00 01 00 00 00 00 00  |................|
+    000002c0  28 00 01 00 29 32 00 00  00 00 00 00 01 00 60 49  |(...)2........`I|
+    000002d0  32 1d 42 54 48 44 00 08  00 02 00 00 11 00 00 00  |2.BTHD..........|
 
- */
+*/
 
 int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
-		struct FRACTALHEAP *fractalheap) {
+		    struct FRACTALHEAP *fractalheap) {
 	int err;
 	char buf[4];
 
@@ -310,66 +348,73 @@ int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	fractalheap->heap_id_length = readValue(reader, 2);
-	fractalheap->encoded_length = readValue(reader, 2);
-	fractalheap->flags = fgetc(reader->fhd);
-	fractalheap->maximum_size = readValue(reader, 4);
+	fractalheap->heap_id_length = (uint16_t)readValue(reader, 2);
+	fractalheap->encoded_length = (uint16_t)readValue(reader, 2);
+	if(fractalheap->encoded_length>0x8000)
+		return MYSOFA_UNSUPPORTED_FORMAT;
+	fractalheap->flags = (uint8_t)fgetc(reader->fhd);
+	fractalheap->maximum_size = (uint32_t)readValue(reader, 4);
 
 	fractalheap->next_huge_object_id = readValue(reader,
-			reader->superblock.size_of_lengths);
+						     reader->superblock.size_of_lengths);
 	fractalheap->btree_address_of_huge_objects = readValue(reader,
-			reader->superblock.size_of_offsets);
+							       reader->superblock.size_of_offsets);
 	fractalheap->free_space = readValue(reader,
-			reader->superblock.size_of_lengths);
+					    reader->superblock.size_of_lengths);
 	fractalheap->address_free_space = readValue(reader,
-			reader->superblock.size_of_offsets);
+						    reader->superblock.size_of_offsets);
 	fractalheap->amount_managed_space = readValue(reader,
-			reader->superblock.size_of_lengths);
+						      reader->superblock.size_of_lengths);
 	fractalheap->amount_allocated_space = readValue(reader,
-			reader->superblock.size_of_lengths);
+							reader->superblock.size_of_lengths);
 	fractalheap->offset_managed_space = readValue(reader,
-			reader->superblock.size_of_lengths);
+						      reader->superblock.size_of_lengths);
 	fractalheap->number_managed_objects = readValue(reader,
-			reader->superblock.size_of_lengths);
+							reader->superblock.size_of_lengths);
 	fractalheap->size_huge_objects = readValue(reader,
-			reader->superblock.size_of_lengths);
+						   reader->superblock.size_of_lengths);
 	fractalheap->number_huge_objects = readValue(reader,
-			reader->superblock.size_of_lengths);
+						     reader->superblock.size_of_lengths);
 	fractalheap->size_tiny_objects = readValue(reader,
-			reader->superblock.size_of_lengths);
+						   reader->superblock.size_of_lengths);
 	fractalheap->number_tiny_objects = readValue(reader,
-			reader->superblock.size_of_lengths);
+						     reader->superblock.size_of_lengths);
 
-	fractalheap->table_width = readValue(reader, 2);
+	fractalheap->table_width = (uint16_t)readValue(reader, 2);
 
 	fractalheap->starting_block_size = readValue(reader,
-			reader->superblock.size_of_lengths);
+						     reader->superblock.size_of_lengths);
 	fractalheap->maximum_direct_block_size = readValue(reader,
-			reader->superblock.size_of_lengths);
+							   reader->superblock.size_of_lengths);
 
-	fractalheap->maximum_heap_size = readValue(reader, 2);
-	fractalheap->starting_row = readValue(reader, 2);
+	fractalheap->maximum_heap_size = (uint16_t)readValue(reader, 2);
+	fractalheap->starting_row = (uint16_t)readValue(reader, 2);
 
 	fractalheap->address_of_root_block = readValue(reader,
-			reader->superblock.size_of_offsets);
+						       reader->superblock.size_of_offsets);
 
-	fractalheap->current_row = readValue(reader, 2);
+	fractalheap->current_row = (uint16_t)readValue(reader, 2);
 
 	if (fractalheap->encoded_length > 0) {
 
 		fractalheap->size_of_filtered_block = readValue(reader,
-				reader->superblock.size_of_lengths);
-		fractalheap->fitler_mask = readValue(reader, 4);
+								reader->superblock.size_of_lengths);
+		fractalheap->fitler_mask = (uint32_t)readValue(reader, 4);
 
 		fractalheap->filter_information = malloc(fractalheap->encoded_length);
 		if (!fractalheap->filter_information)
 			return MYSOFA_NO_MEMORY;
 
-		fread(fractalheap->filter_information, 1, fractalheap->encoded_length,
-				reader->fhd);
+		if(fread(fractalheap->filter_information, 1, fractalheap->encoded_length,
+		      reader->fhd) != fractalheap->encoded_length) {
+			free(fractalheap->filter_information);
+			return MYSOFA_READ_ERROR;
+		}
 	}
 
-	fseek(reader->fhd, 4, SEEK_CUR); /* skip checksum */
+	if(fseek(reader->fhd, 4, SEEK_CUR)<0) { /* skip checksum */
+		return MYSOFA_READ_ERROR;
+	}
 
 	if (fractalheap->number_huge_objects) {
 		log("cannot handle huge objects\n");
@@ -383,10 +428,11 @@ int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
 
 	if (validAddress(reader, fractalheap->address_of_root_block)) {
 
-		fseek(reader->fhd, fractalheap->address_of_root_block, SEEK_SET);
+		if(fseek(reader->fhd, fractalheap->address_of_root_block, SEEK_SET)<0)
+			return errno;
 		if (fractalheap->current_row)
 			err = indirectblockRead(reader, dataobject, fractalheap,
-					fractalheap->starting_block_size);
+						fractalheap->starting_block_size);
 		else {
 			err = directblockRead(reader, dataobject, fractalheap);
 
diff --git a/src/hdf/gcol.c b/src/hdf/gcol.c
index cb0b143..981245c 100644
--- a/src/hdf/gcol.c
+++ b/src/hdf/gcol.c
@@ -1,11 +1,12 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include "reader.h"
 
 /*  III.E. Disk Format: Level 1E - Global Heap
@@ -30,9 +31,8 @@ static int readGCOL(struct READER *reader) {
 		log("object GCOL must have version 1\n");
 		return MYSOFA_INVALID_FORMAT;
 	}
-	fgetc(reader->fhd);
-	fgetc(reader->fhd);
-	fgetc(reader->fhd);
+	if(fgetc(reader->fhd)<0 ||  fgetc(reader->fhd)<0 || fgetc(reader->fhd)<0)
+		return MYSOFA_READ_ERROR;
 
 	address = ftell(reader->fhd);
 	end = address;
@@ -48,13 +48,20 @@ static int readGCOL(struct READER *reader) {
 			break;
 		}
 		reference_count = readValue(reader, 2);
-		fseek(reader->fhd, 4, SEEK_CUR);
+		if(fseek(reader->fhd, 4, SEEK_CUR)<0) {
+			free(gcol);
+			return errno;
+		}
 		gcol->object_size = readValue(reader,
-				reader->superblock.size_of_lengths);
+					      reader->superblock.size_of_lengths);
+		if(gcol->object_size>8) {
+			free(gcol);
+			return MYSOFA_UNSUPPORTED_FORMAT;
+		}
 		gcol->value = readValue(reader, gcol->object_size);
 		gcol->address = address;
 		log(" GCOL object %d size %ld value %08lX\n", gcol->heap_object_index,
-				gcol->object_size, gcol->value);
+		    gcol->object_size, gcol->value);
 
 		gcol->next = reader->gcol;
 		reader->gcol = gcol;
@@ -66,8 +73,8 @@ static int readGCOL(struct READER *reader) {
 }
 
 int gcolRead(struct READER *reader, uint64_t gcol, int reference,
-		uint64_t *dataobject) {
-	uint64_t pos;
+	     uint64_t *dataobject) {
+	long pos;
 	struct GCOL *p = reader->gcol;
 
 	while (p && p->address != gcol && p->heap_object_index != reference) {
@@ -75,9 +82,13 @@ int gcolRead(struct READER *reader, uint64_t gcol, int reference,
 	}
 	if (!p) {
 		pos = ftell(reader->fhd);
-		fseek(reader->fhd, gcol, SEEK_SET);
+		if(fseek(reader->fhd, gcol, SEEK_SET)<0)
+			return MYSOFA_READ_ERROR;
 		readGCOL(reader);
-		fseek(reader->fhd, pos, SEEK_SET);
+		if(pos<0)
+			return MYSOFA_READ_ERROR;
+		if(fseek(reader->fhd, pos, SEEK_SET)<0)
+			return MYSOFA_READ_ERROR;
 
 		p = reader->gcol;
 		while (p && p->address != gcol && p->heap_object_index != reference) {
@@ -115,10 +126,10 @@ for (;;) {
 	gcol = gcol->next;
 #endif
 
-void gcolFree(struct GCOL *gcol) {
-	if (gcol) {
-		gcolFree(gcol->next);
-		free(gcol);
+	void gcolFree(struct GCOL *gcol) {
+		if (gcol) {
+			gcolFree(gcol->next);
+			free(gcol);
+		}
 	}
-}
 
diff --git a/src/hdf/gunzip.c b/src/hdf/gunzip.c
index 9afdf71..7ea7ce5 100644
--- a/src/hdf/gunzip.c
+++ b/src/hdf/gunzip.c
@@ -1,8 +1,8 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #include <stdlib.h>
 #include <string.h>
diff --git a/src/hdf/reader.h b/src/hdf/reader.h
index fe1b56d..94eae20 100644
--- a/src/hdf/reader.h
+++ b/src/hdf/reader.h
@@ -1,8 +1,8 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+	*/
 
 #ifndef READER_H_
 #define READER_H_
@@ -56,37 +56,37 @@ struct GCOL {
 struct FRACTALHEAP {
 	uint8_t flags;
 	uint16_t heap_id_length, encoded_length, table_width, maximum_heap_size,
-			starting_row, current_row;
+		starting_row, current_row;
 	uint32_t maximum_size, fitler_mask;
 	uint64_t next_huge_object_id, btree_address_of_huge_objects, free_space,
-			address_free_space, amount_managed_space, amount_allocated_space,
-			offset_managed_space, number_managed_objects, size_huge_objects,
-			number_huge_objects, size_tiny_objects, number_tiny_objects,
-			starting_block_size, maximum_direct_block_size,
-			address_of_root_block, size_of_filtered_block;
+		address_free_space, amount_managed_space, amount_allocated_space,
+		offset_managed_space, number_managed_objects, size_huge_objects,
+		number_huge_objects, size_tiny_objects, number_tiny_objects,
+		starting_block_size, maximum_direct_block_size,
+		address_of_root_block, size_of_filtered_block;
 	uint8_t *filter_information;
 };
 
 int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
-		struct FRACTALHEAP *fractalheap);
+		    struct FRACTALHEAP *fractalheap);
 void fractalheapFree(struct FRACTALHEAP *fractalheap);
 
 struct LINKINFO {
 	uint8_t flags;
 	uint64_t maximum_creation_index, fractal_heap_address, address_btree_index,
-			address_btree_order;
+		address_btree_order;
 };
 
 struct GROUPINFO {
 	uint8_t flags;
 	uint64_t maximum_compact_value, minimum_dense_value, number_of_entries,
-			length_of_entries;
+		length_of_entries;
 };
 
 struct ATTRIBUTEINFO {
 	uint8_t flags;
 	uint64_t maximum_creation_index, fractal_heap_address, attribute_name_btree,
-			attribute_creation_order_btree;
+		attribute_creation_order_btree;
 };
 
 struct DATASPACE {
@@ -105,7 +105,7 @@ struct DATATYPE {
 		struct {
 			uint16_t bit_offset, bit_precision;
 			uint8_t exponent_location, exponent_size, mantissa_location,
-					mantissa_size;
+				mantissa_size;
 			uint32_t exponent_bias;
 		} f;
 	} u;
@@ -146,7 +146,7 @@ struct DATAOBJECT {
 };
 
 int dataobjectRead(struct READER *reader, struct DATAOBJECT *dataobject,
-		char *name);
+		   char *name);
 void dataobjectFree(struct READER *reader, struct DATAOBJECT *dataobject);
 
 struct DIR {
@@ -160,7 +160,7 @@ struct SUPERBLOCK {
 	uint8_t size_of_lengths;
 
 	uint64_t base_address, superblock_extension_address, end_of_file_address,
-			root_group_object_header_address;
+		root_group_object_header_address;
 
 	struct DATAOBJECT dataobject;
 };
@@ -169,7 +169,7 @@ int superblockRead(struct READER *reader, struct SUPERBLOCK *superblock);
 void superblockFree(struct READER *reader, struct SUPERBLOCK *superblock);
 
 int gcolRead(struct READER *reader, uint64_t gcol, int reference,
-		uint64_t *dataobject);
+	     uint64_t *dataobject);
 void gcolFree(struct GCOL *gcol);
 
 int treeRead(struct READER *reader, struct DATAOBJECT *data);
diff --git a/src/hdf/superblock.c b/src/hdf/superblock.c
index 86b995e..0c11df3 100644
--- a/src/hdf/superblock.c
+++ b/src/hdf/superblock.c
@@ -1,8 +1,8 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #include <string.h>
 #include <stdlib.h>
@@ -11,10 +11,10 @@
 #include "reader.h"
 
 /* read superblock
- 00000000  89 48 44 46 0d 0a 1a 0a  02 08 08 00 00 00 00 00  |.HDF............|
- 00000010  00 00 00 00 ff ff ff ff  ff ff ff ff bc 62 12 00  |.............b..|
- 00000020  00 00 00 00 30 00 00 00  00 00 00 00 27 33 a3 16  |....0.......'3..|
- */
+   00000000  89 48 44 46 0d 0a 1a 0a  02 08 08 00 00 00 00 00  |.HDF............|
+   00000010  00 00 00 00 ff ff ff ff  ff ff ff ff bc 62 12 00  |.............b..|
+   00000020  00 00 00 00 30 00 00 00  00 00 00 00 27 33 a3 16  |....0.......'3..|
+*/
 
 int superblockRead(struct READER *reader, struct SUPERBLOCK *superblock) {
 	char buf[8];
@@ -22,7 +22,7 @@ int superblockRead(struct READER *reader, struct SUPERBLOCK *superblock) {
 
 	/* signature */
 	if (fread(buf, 1, 8, reader->fhd) != 8
-			|| strncmp("\211HDF\r\n\032\n", buf, 8)) {
+	    || strncmp("\211HDF\r\n\032\n", buf, 8)) {
 		log("file does not have correct signature");
 		return MYSOFA_INVALID_FORMAT;
 	}
@@ -33,25 +33,26 @@ int superblockRead(struct READER *reader, struct SUPERBLOCK *superblock) {
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
-	superblock->size_of_offsets = fgetc(reader->fhd);
-	superblock->size_of_lengths = fgetc(reader->fhd);
-	fgetc(reader->fhd); /* File Consistency Flags */
+	superblock->size_of_offsets = (uint8_t)fgetc(reader->fhd);
+	superblock->size_of_lengths = (uint8_t)fgetc(reader->fhd);
+	if(fgetc(reader->fhd)<0) /* File Consistency Flags */
+		return MYSOFA_READ_ERROR;
 
 	if (superblock->size_of_offsets < 2 || superblock->size_of_offsets > 8
-			|| superblock->size_of_lengths < 2
-			|| superblock->size_of_lengths > 8) {
+	    || superblock->size_of_lengths < 2
+	    || superblock->size_of_lengths > 8) {
 		log("size of offsets and length is invalid: %d %d\n",
-				superblock->size_of_offsets, superblock->size_of_lengths);
+		    superblock->size_of_offsets, superblock->size_of_lengths);
 		return MYSOFA_UNSUPPORTED_FORMAT;
 	}
 
 	superblock->base_address = readValue(reader, superblock->size_of_offsets);
 	superblock->superblock_extension_address = readValue(reader,
-			superblock->size_of_offsets);
+							     superblock->size_of_offsets);
 	superblock->end_of_file_address = readValue(reader,
-			superblock->size_of_offsets);
+						    superblock->size_of_offsets);
 	superblock->root_group_object_header_address = readValue(reader,
-			superblock->size_of_offsets);
+								 superblock->size_of_offsets);
 
 	if (superblock->base_address != 0) {
 		log("base address is not null\n");
@@ -72,9 +73,9 @@ int superblockRead(struct READER *reader, struct SUPERBLOCK *superblock) {
 
 	/* seek to first object */
 	if (fseek(reader->fhd, superblock->root_group_object_header_address,
-	SEEK_SET)) {
+		  SEEK_SET)) {
 		log("cannot seek to first object at %ld\n",
-				superblock->root_group_object_header_address);
+		    superblock->root_group_object_header_address);
 		return errno;
 	}
 
diff --git a/src/hrtf/cache.c b/src/hrtf/cache.c
index 522535b..e8454cb 100644
--- a/src/hrtf/cache.c
+++ b/src/hrtf/cache.c
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "../hdf/reader.h"
 
@@ -20,17 +21,26 @@ static struct MYSOFA_CACHE_ENTRY {
 	int count;
 } *cache;
 
-struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate)
+static int compare_filenames(const char *a, const char *b)
+{
+	if(a == NULL && b == NULL)
+		return 0;
+	if(a == NULL)
+		return -1;
+	else if(b == NULL)
+		return 1;
+	return strcmp(a,b);
+}
+
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate)
 {
 	struct MYSOFA_CACHE_ENTRY *p;
 	struct MYSOFA_EASY *res = NULL;
 
-	assert(filename);
-
 	p = cache;
 
 	while(p) {
-		if(samplerate == p->samplerate && !strcmp(filename, p->filename)) {
+		if(samplerate == p->samplerate && !compare_filenames(filename, p->filename)) {
 			res = p->easy;
 			p->count++;
 			break;
@@ -41,17 +51,16 @@ struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate)
 	return res;
 }
 
-struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *easy, const char *filename, float samplerate)
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *easy, const char *filename, float samplerate)
 {
 	struct MYSOFA_CACHE_ENTRY *p;
 
 	assert(easy);
-	assert(filename);
 
 	p = cache;
 
 	while(p) {
-		if(samplerate == p->samplerate && !strcmp(filename, p->filename)) {
+		if(samplerate == p->samplerate && !compare_filenames(filename, p->filename)) {
 			mysofa_close(easy);
 			return p->easy;
 		}
@@ -64,10 +73,13 @@ struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *easy, const char *fil
 	}
 	p->next = cache;
 	p->samplerate = samplerate;
-	p->filename = mysofa_strdup(filename);
-	if(p->filename == NULL) {
-		free(p);
-		return NULL;
+	p->filename = NULL;
+	if(filename != NULL) {
+		p->filename = mysofa_strdup(filename);
+		if(p->filename == NULL) {
+			free(p);
+			return NULL;
+		}
 	}
 	p->easy = easy;
 	p->count = 1;
@@ -75,7 +87,7 @@ struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *easy, const char *fil
 	return easy;
 }
 
-void mysofa_cache_release(struct MYSOFA_EASY *easy)
+MYSOFA_EXPORT void mysofa_cache_release(struct MYSOFA_EASY *easy)
 {
 	struct MYSOFA_CACHE_ENTRY **p;
 	int count;
@@ -104,19 +116,18 @@ void mysofa_cache_release(struct MYSOFA_EASY *easy)
 	}
 }
 
-void mysofa_cache_release_all()
+MYSOFA_EXPORT void mysofa_cache_release_all()
 {
 	struct MYSOFA_CACHE_ENTRY *p;
 
 	p = cache;
 	while(p) {
 		struct MYSOFA_CACHE_ENTRY *gone = p;
-/*		fprintf(stderr,"ra %p %s %p\n",(void*)p,gone->filename,(void*)p->easy); */
 		p=p->next;
 		free(gone->filename);
 		free(gone->easy);
-/*		mysofa_close2(gone->easy); */
 		free(gone);
 	}
 	cache = NULL;
 }
+
diff --git a/src/hrtf/check.c b/src/hrtf/check.c
index e572a0e..5402bec 100644
--- a/src/hrtf/check.c
+++ b/src/hrtf/check.c
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <math.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
@@ -18,7 +19,7 @@ static float array000[] = { 0, 0, 0 };
 static float array001[] = { 0, 0, 1 };
 static float array100[] = { 1, 0, 0 };
 
-int mysofa_check(struct MYSOFA_HRTF *hrtf) {
+MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf) {
 
 	/* check for valid parameter ranges */
 	/*
diff --git a/src/hrtf/easy.c b/src/hrtf/easy.c
index 57aac75..2884349 100644
--- a/src/hrtf/easy.c
+++ b/src/hrtf/easy.c
@@ -7,16 +7,15 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <pthread.h>
+#include <assert.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 
-pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
 /**
  *
  */
 
-struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err)
+MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err)
 {
 	struct MYSOFA_EASY *easy = malloc(sizeof(struct MYSOFA_EASY));
 	if(!easy) {
@@ -48,7 +47,7 @@ struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *fil
 	mysofa_loudness(easy->hrtf);
 
 /* does not sound well:
-	mysofa_minphase(easy->hrtf,0.01);
+   mysofa_minphase(easy->hrtf,0.01);
 */
 
 	mysofa_tocartesian(easy->hrtf);
@@ -61,14 +60,14 @@ struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *fil
 	}
 
 	easy->neighborhood = mysofa_neighborhood_init(easy->hrtf,
-			easy->lookup);
+						      easy->lookup);
 
-    *filterlength = easy->hrtf->N;
+	*filterlength = easy->hrtf->N;
 
 	return easy;
 }
 
-struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err)
+MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err)
 {
 	struct MYSOFA_EASY* res = mysofa_cache_lookup(filename, samplerate);
 	if(res) {
@@ -82,28 +81,29 @@ struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, i
 	return res;
 }
 
-void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
-		short *IRleft, short *IRright,
-		int *delayLeft, int *delayRight)
+MYSOFA_EXPORT void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
+					  short *IRleft, short *IRright,
+					  int *delayLeft, int *delayRight)
 {
 	float c[3];
 	float *fir = malloc(easy->hrtf->N * easy->hrtf->R * sizeof(float));
 	float delays[2];
-    float *fl;
+	float *fl;
 	float *fr;
 	int nearest;
 	int *neighbors;
 	int i;
 
-    c[0] = x;
-    c[1] = y;
-    c[2] = z;
-    nearest = mysofa_lookup(easy->lookup, c);
-    neighbors = mysofa_neighborhood(easy->neighborhood, nearest);
+	c[0] = x;
+	c[1] = y;
+	c[2] = z;
+	nearest = mysofa_lookup(easy->lookup, c);
+	assert(nearest>=0);
+	neighbors = mysofa_neighborhood(easy->neighborhood, nearest);
     
 	mysofa_interpolate(easy->hrtf, c,
-			nearest, neighbors,
-			fir, delays);
+			   nearest, neighbors,
+			   fir, delays);
 
 	*delayLeft  = delays[0] * easy->hrtf->DataSamplingRate.values[0];
 	*delayRight = delays[1] * easy->hrtf->DataSamplingRate.values[0];
@@ -117,28 +117,29 @@ void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
 	free(fir);
 }
 
-void mysofa_getfilter_float(struct MYSOFA_EASY* easy, float x, float y, float z,
-		float *IRleft, float *IRright,
-		float *delayLeft, float *delayRight)
+MYSOFA_EXPORT void mysofa_getfilter_float(struct MYSOFA_EASY* easy, float x, float y, float z,
+					  float *IRleft, float *IRright,
+					  float *delayLeft, float *delayRight)
 {
 	float c[3];
 	float *fir = malloc(easy->hrtf->N * easy->hrtf->R * sizeof(float));
 	float delays[2];
-    float *fl;
+	float *fl;
 	float *fr;
 	int nearest;
 	int *neighbors;
 	int i;
 
-    c[0] = x;
-    c[1] = y;
-    c[2] = z;
-    nearest = mysofa_lookup(easy->lookup, c);
-    neighbors = mysofa_neighborhood(easy->neighborhood, nearest);
+	c[0] = x;
+	c[1] = y;
+	c[2] = z;
+	nearest = mysofa_lookup(easy->lookup, c);
+	assert(nearest>=0);
+	neighbors = mysofa_neighborhood(easy->neighborhood, nearest);
     
 	mysofa_interpolate(easy->hrtf, c,
-			nearest, neighbors,
-			fir, delays);
+			   nearest, neighbors,
+			   fir, delays);
 
 	*delayLeft  = delays[0];
 	*delayRight = delays[1];
@@ -152,7 +153,7 @@ void mysofa_getfilter_float(struct MYSOFA_EASY* easy, float x, float y, float z,
 	free(fir);
 }
 
-void mysofa_close(struct MYSOFA_EASY* easy)
+MYSOFA_EXPORT void mysofa_close(struct MYSOFA_EASY* easy)
 {
 	if(easy) {
 		if(easy->neighborhood)
@@ -165,7 +166,7 @@ void mysofa_close(struct MYSOFA_EASY* easy)
 	}
 }
 
-void mysofa_close_cached(struct MYSOFA_EASY* easy)
+MYSOFA_EXPORT void mysofa_close_cached(struct MYSOFA_EASY* easy)
 {
 	mysofa_cache_release(easy);
 }
diff --git a/src/hrtf/interpolate.c b/src/hrtf/interpolate.c
index c21d1fd..5643c3f 100644
--- a/src/hrtf/interpolate.c
+++ b/src/hrtf/interpolate.c
@@ -8,13 +8,14 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
 /* #define VDEBUG */
 
-float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
-		int nearest, int *neighborhood, float *fir, float *delays) {
+MYSOFA_EXPORT float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
+					int nearest, int *neighborhood, float *fir, float *delays) {
 	int i, use[6];
 	float d, d6[6];
 	float weight;
@@ -27,69 +28,71 @@ float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
 			delays[1] = hrtf->DataDelay.values[nearest * hrtf->R + 1];
 		}
 		else {
-    		delays[0] = hrtf->DataDelay.values[0];
-    		delays[1] = hrtf->DataDelay.values[1];
-    	}
+			delays[0] = hrtf->DataDelay.values[0];
+			delays[1] = hrtf->DataDelay.values[1];
+		}
 		return hrtf->DataIR.values + nearest * size;
 	}
 
-	for (i = 0; i < 6; i++)
+	for (i = 0; i < 6; i++) {
 		use[i] = 0;
+		d6[i] = 1;
+	}
 
 	if (neighborhood[0] >= 0 && neighborhood[1] >= 0) {
 		d6[0] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[0] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[0] * hrtf->C);
 		d6[1] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[1] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[1] * hrtf->C);
 		if (d6[0] < d6[1])
 			use[0] = 1;
 		else
 			use[1] = 1;
 	} else if (neighborhood[0] >= 0) {
 		d6[0] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[0] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[0] * hrtf->C);
 		use[0] = 1;
 	} else if (neighborhood[1] >= 0) {
 		d6[1] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[1] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[1] * hrtf->C);
 		use[1] = 1;
 	}
 
 	if (neighborhood[2] >= 0 && neighborhood[3] >= 0) {
 		d6[2] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[2] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[2] * hrtf->C);
 		d6[3] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[3] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[3] * hrtf->C);
 		if (d6[2] < d6[3])
 			use[2] = 1;
 		else
 			use[3] = 1;
 	} else if (neighborhood[2] >= 0) {
 		d6[2] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[2] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[2] * hrtf->C);
 		use[2] = 1;
 	} else if (neighborhood[3] >= 0) {
 		d6[3] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[3] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[3] * hrtf->C);
 		use[3] = 1;
 	}
 
 	if (neighborhood[4] >= 0 && neighborhood[5] >= 0) {
 		d6[4] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[4] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[4] * hrtf->C);
 		d6[5] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[5] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[5] * hrtf->C);
 		if (d6[4] < d6[5])
 			use[4] = 1;
 		else
 			use[5] = 1;
 	} else if (neighborhood[4] >= 0) {
 		d6[4] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[4] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[4] * hrtf->C);
 		use[4] = 1;
 	} else if (neighborhood[5] >= 0) {
 		d6[5] = distance(cordinate,
-				hrtf->SourcePosition.values + neighborhood[5] * hrtf->C);
+				 hrtf->SourcePosition.values + neighborhood[5] * hrtf->C);
 		use[5] = 1;
 	}
 
@@ -110,11 +113,11 @@ float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
 		if (use[i]) {
 			float w = 1 / d6[i];
 #ifdef VDEBUG			
-        	printf("%d - %f ",neighborhood[i], d6[i]);
+			printf("%d - %f ",neighborhood[i], d6[i]);
 #endif        	
 			addArrayWeighted(fir,
-					hrtf->DataIR.values + neighborhood[i] * size, size,
-					w);
+					 hrtf->DataIR.values + neighborhood[i] * size, size,
+					 w);
 			weight += w;
 			if (hrtf->DataDelay.elements > hrtf->R) {
 				delays[0] += hrtf->DataDelay.values[neighborhood[i] * hrtf->R] * w;
@@ -123,7 +126,7 @@ float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
 		}
 	}
 #ifdef VDEBUG			
-    printf("\n");
+	printf("\n");
 #endif
 	weight = 1 / weight;
 	scaleArray(fir, size, weight);
diff --git a/src/hrtf/lookup.c b/src/hrtf/lookup.c
index 8233e10..91b2b22 100644
--- a/src/hrtf/lookup.c
+++ b/src/hrtf/lookup.c
@@ -11,10 +11,11 @@
 #include <string.h>
 
 #include "kdtree.h"
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
-struct MYSOFA_LOOKUP* mysofa_lookup_init(struct MYSOFA_HRTF *hrtf) {
+MYSOFA_EXPORT struct MYSOFA_LOOKUP* mysofa_lookup_init(struct MYSOFA_HRTF *hrtf) {
 	int i;
 	struct MYSOFA_LOOKUP *lookup;
 
@@ -65,10 +66,10 @@ struct MYSOFA_LOOKUP* mysofa_lookup_init(struct MYSOFA_HRTF *hrtf) {
  * looks for a filter that is similar to the given Cartesian coordinate
  * BE AWARE: The coordinate vector will be normalized if required
  */
-int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate) {
+MYSOFA_EXPORT int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate) {
 
-    int index;
-    struct kdres *res;
+	int index;
+	struct kdres *res;
 	float r = radius(coordinate);
 	if(r>lookup->radius_max) {
 		r = lookup->radius_max / r;
@@ -84,7 +85,7 @@ int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate) {
 	}
 
 	res = kd_nearest((struct kdtree *) lookup->kdtree,
-			coordinate);
+			 coordinate);
 	if (kd_res_size(res) != 1) {
 		kd_res_free(res);
 		return -1;
@@ -94,7 +95,7 @@ int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate) {
 	return index;
 }
 
-void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup) {
+MYSOFA_EXPORT void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup) {
 	if(lookup) {
 		kd_free((struct kdtree *) lookup->kdtree);
 		free(lookup);
diff --git a/src/hrtf/loudness.c b/src/hrtf/loudness.c
index a5710bc..a21e164 100644
--- a/src/hrtf/loudness.c
+++ b/src/hrtf/loudness.c
@@ -12,16 +12,17 @@
 #include <float.h>
 #include <math.h>
 #include <assert.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
-float mysofa_loudness(struct MYSOFA_HRTF *hrtf) {
+MYSOFA_EXPORT float mysofa_loudness(struct MYSOFA_HRTF *hrtf) {
 	float c[3], factor;
 	float min = FLT_MAX;
 	int radius = 0;
-	int i, index;
+	int i, index=0;
 	int cartesian = verifyAttribute(hrtf->SourcePosition.attributes, "Type",
-			"cartesian");
+					"cartesian");
 
 	/*
 	 * find frontal source position
@@ -46,7 +47,7 @@ float mysofa_loudness(struct MYSOFA_HRTF *hrtf) {
 
 	/* get loudness of frontal fir filter, for both channels*/
 	factor = loudness(hrtf->DataIR.values + (index / 3) * hrtf->N * hrtf->R,
-			hrtf->N * hrtf->R);
+			  hrtf->N * hrtf->R);
 	factor = sqrt(2 / factor);
 	if (fequals(factor, 1.))
 		return 1.;
diff --git a/src/hrtf/minphase.c b/src/hrtf/minphase.c
index 59453b0..af69d48 100644
--- a/src/hrtf/minphase.c
+++ b/src/hrtf/minphase.c
@@ -11,6 +11,7 @@
 #include <float.h>
 #include <math.h>
 #include <assert.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
@@ -44,7 +45,7 @@ static void trunk(float *in, int size, int *start, int *end, float threshold) {
 	*end = e + 1;
 }
 
-int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold) {
+MYSOFA_EXPORT int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold) {
 	int i;
 	int max = 0;
 	int filters;
@@ -65,14 +66,14 @@ int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold) {
 	 */
 	for (i = 0; i < filters; i++) {
 		trunk(hrtf->DataIR.values + i * hrtf->N, hrtf->N, start + i, end + i,
-				threshold);
+		      threshold);
 		if (end[i] - start[i] > max)
 			max = end[i] - start[i];
 	}
 
 	if (max == hrtf->N) {
-	    free(start);
-	    free(end);
+		free(start);
+		free(end);
 		return max;
 	}
 
@@ -84,14 +85,14 @@ int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold) {
 	d[1] = hrtf->DataDelay.values[1];
 	hrtf->DataDelay.elements = filters;
 	hrtf->DataDelay.values = realloc(hrtf->DataDelay.values,
-			sizeof(float) * filters);
+					 sizeof(float) * filters);
 	for (i = 0; i < filters; i++) {
 		if (start[i] + max > hrtf->N)
 			start[i] = hrtf->N - max;
 		hrtf->DataDelay.values[i] = d[i % 1] + (start[i] / samplerate);
 		memmove(hrtf->DataIR.values + i * max,
-				hrtf->DataIR.values + i * hrtf->N + start[i],
-				max * sizeof(float));
+			hrtf->DataIR.values + i * hrtf->N + start[i],
+			max * sizeof(float));
 	}
 
 	/*
@@ -100,10 +101,10 @@ int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold) {
 	hrtf->N = max;
 	hrtf->DataIR.elements = max * filters;
 	hrtf->DataIR.values = realloc(hrtf->DataIR.values,
-			sizeof(float) * hrtf->DataIR.elements);
+				      sizeof(float) * hrtf->DataIR.elements);
 
-    free(start);
-    free(end);
+	free(start);
+	free(end);
 	return max;
 }
 
diff --git a/src/hrtf/mysofa.h b/src/hrtf/mysofa.h
index 17ead3e..c8ff5df 100644
--- a/src/hrtf/mysofa.h
+++ b/src/hrtf/mysofa.h
@@ -1,8 +1,8 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #ifndef MYSOFA_H_INCLUDED
 #define MYSOFA_H_INCLUDED
@@ -13,128 +13,129 @@ extern "C" {
 #include <stdint.h>
 
 /** attributes */
-struct MYSOFA_ATTRIBUTE {
-	struct MYSOFA_ATTRIBUTE *next;
-	char *name;
-	char *value;
-};
-
-struct MYSOFA_ARRAY {
-	float *values;
-	unsigned int elements;
-	struct MYSOFA_ATTRIBUTE *attributes;
-};
+	struct MYSOFA_ATTRIBUTE {
+		struct MYSOFA_ATTRIBUTE *next;
+		char *name;
+		char *value;
+	};
+
+	struct MYSOFA_ARRAY {
+		float *values;
+		unsigned int elements;
+		struct MYSOFA_ATTRIBUTE *attributes;
+	};
 
 /*
  * The HRTF structure data types
  */
-struct MYSOFA_HRTF {
+	struct MYSOFA_HRTF {
 
-	/* Dimensions defined in AES69 
-	 M Number of measurements; must be integer greater than zero.
-	 R Number of receivers; must be integer greater than zero.
-	 E Number of emitters; must be integer greater than zero.
-	 N Number of data samples describing one measurement; must be integer greater than zero.
-	 S Number of characters in a string; must be integer greater than zero.
-	 I 1 Singleton dimension, defines a scalar value.
-	 C 3 Coordinate triplet, always three; the coordinate type defines the meaning of this dimension.
-	 */
-	unsigned I, C, R, E, N, M;
+		/* Dimensions defined in AES69 
+		   M Number of measurements; must be integer greater than zero.
+		   R Number of receivers; must be integer greater than zero.
+		   E Number of emitters; must be integer greater than zero.
+		   N Number of data samples describing one measurement; must be integer greater than zero.
+		   S Number of characters in a string; must be integer greater than zero.
+		   I 1 Singleton dimension, defines a scalar value.
+		   C 3 Coordinate triplet, always three; the coordinate type defines the meaning of this dimension.
+		*/
+		unsigned I, C, R, E, N, M;
 
-	struct MYSOFA_ARRAY ListenerPosition;
+		struct MYSOFA_ARRAY ListenerPosition;
 
-	struct MYSOFA_ARRAY ReceiverPosition;
+		struct MYSOFA_ARRAY ReceiverPosition;
 
-	struct MYSOFA_ARRAY SourcePosition;
+		struct MYSOFA_ARRAY SourcePosition;
 
-	struct MYSOFA_ARRAY EmitterPosition;
+		struct MYSOFA_ARRAY EmitterPosition;
 
-	struct MYSOFA_ARRAY ListenerUp;
+		struct MYSOFA_ARRAY ListenerUp;
 
-	struct MYSOFA_ARRAY ListenerView;
+		struct MYSOFA_ARRAY ListenerView;
 
-	/** array of filter coefficients. Sizes are filters*filter_length. */
-	struct MYSOFA_ARRAY DataIR;
+		/** array of filter coefficients. Sizes are filters*filter_length. */
+		struct MYSOFA_ARRAY DataIR;
 
-	/** the sampling rate used in this structure */
-	struct MYSOFA_ARRAY DataSamplingRate;
+		/** the sampling rate used in this structure */
+		struct MYSOFA_ARRAY DataSamplingRate;
 
-	/** array of min-phase delays. Sizes are filters */
-	struct MYSOFA_ARRAY DataDelay;
+		/** array of min-phase delays. Sizes are filters */
+		struct MYSOFA_ARRAY DataDelay;
 
-	/** general file attributes */
-	struct MYSOFA_ATTRIBUTE *attributes;
-};
+		/** general file attributes */
+		struct MYSOFA_ATTRIBUTE *attributes;
+	};
 
 /* structure for lookup HRTF filters */
-struct MYSOFA_LOOKUP {
-	void *kdtree;
-	float radius_min, radius_max;
-};
-
-struct MYSOFA_NEIGHBORHOOD {
-	int elements;
-	int *index;
-};
-
-enum {
-	MYSOFA_OK = 0,
-	MYSOFA_INVALID_FORMAT = 10000,
-	MYSOFA_UNSUPPORTED_FORMAT,
-	MYSOFA_INTERNAL_ERROR,
-	MYSOFA_NO_MEMORY,
-	MYSOFA_READ_ERROR
-};
-
-struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err);
-
-int mysofa_check(struct MYSOFA_HRTF *hrtf);
-char* mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
-void mysofa_tospherical(struct MYSOFA_HRTF *hrtf);
-void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf);
-void mysofa_free(struct MYSOFA_HRTF *hrtf);
-
-struct MYSOFA_LOOKUP* mysofa_lookup_init(struct MYSOFA_HRTF *hrtf);
-int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate);
-void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup);
-
-struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
-		struct MYSOFA_LOOKUP *lookup);
-int* mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
-void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);
-
-float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
-		int nearest, int *neighborhood, float *fir, float *delays);
-
-int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate);
-float mysofa_loudness(struct MYSOFA_HRTF *hrtf);
-int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold);
-
-struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate);
-struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *, const char *filename, float samplerate);
-void mysofa_cache_release(struct MYSOFA_EASY *);
-void mysofa_cache_release_all(void);
-
-void mysofa_c2s(float values[3]);
-void mysofa_s2c(float values[3]);
-
-struct MYSOFA_EASY {
-	struct MYSOFA_HRTF *hrtf;
-	struct MYSOFA_LOOKUP *lookup;
-	struct MYSOFA_NEIGHBORHOOD *neighborhood;
-};
-
-struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err);
-struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err);
-void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
-		short *IRleft, short *IRright,
-		int *delayLeft, int *delayRight);
-void mysofa_getfilter_float(struct MYSOFA_EASY* easy, float x, float y, float z,
-		float *IRleft, float *IRright,
-		float *delayLeft, float *delayRight);
-void mysofa_close(struct MYSOFA_EASY* easy);
-void mysofa_close_cached(struct MYSOFA_EASY* easy);
-
+	struct MYSOFA_LOOKUP {
+		void *kdtree;
+		float radius_min, radius_max;
+	};
+
+	struct MYSOFA_NEIGHBORHOOD {
+		int elements;
+		int *index;
+	};
+
+	enum {
+		MYSOFA_OK = 0,
+		MYSOFA_INVALID_FORMAT = 10000,
+		MYSOFA_UNSUPPORTED_FORMAT,
+		MYSOFA_INTERNAL_ERROR,
+		MYSOFA_NO_MEMORY,
+		MYSOFA_READ_ERROR
+	};
+
+	struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err);
+
+	int mysofa_check(struct MYSOFA_HRTF *hrtf);
+	char* mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
+	void mysofa_tospherical(struct MYSOFA_HRTF *hrtf);
+	void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf);
+	void mysofa_free(struct MYSOFA_HRTF *hrtf);
+
+	struct MYSOFA_LOOKUP* mysofa_lookup_init(struct MYSOFA_HRTF *hrtf);
+	int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate);
+	void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup);
+
+	struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
+							     struct MYSOFA_LOOKUP *lookup);
+	int* mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
+	void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);
+
+	float* mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
+				  int nearest, int *neighborhood, float *fir, float *delays);
+
+	int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate);
+	float mysofa_loudness(struct MYSOFA_HRTF *hrtf);
+	int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold);
+
+	struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate);
+	struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *, const char *filename, float samplerate);
+	void mysofa_cache_release(struct MYSOFA_EASY *);
+	void mysofa_cache_release_all(void);
+
+	void mysofa_c2s(float *values);
+	void mysofa_s2c(float *values);
+
+	struct MYSOFA_EASY {
+		struct MYSOFA_HRTF *hrtf;
+		struct MYSOFA_LOOKUP *lookup;
+		struct MYSOFA_NEIGHBORHOOD *neighborhood;
+	};
+
+	struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err);
+	struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err);
+	void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
+				    short *IRleft, short *IRright,
+				    int *delayLeft, int *delayRight);
+	void mysofa_getfilter_float(struct MYSOFA_EASY* easy, float x, float y, float z,
+				    float *IRleft, float *IRright,
+				    float *delayLeft, float *delayRight);
+	void mysofa_close(struct MYSOFA_EASY* easy);
+	void mysofa_close_cached(struct MYSOFA_EASY* easy);
+
+	void mysofa_getversion(int *major, int *minor, int *patch);
 
 #ifdef __cplusplus
 }
diff --git a/src/hrtf/mysofa_export.h.in b/src/hrtf/mysofa_export.h.in
new file mode 100644
index 0000000..d9455c1
--- /dev/null
+++ b/src/hrtf/mysofa_export.h.in
@@ -0,0 +1,7 @@
+
+/**
+ * use this file if you do not use CMAKE to generate you an own file
+ */ 
+ 
+#define MYSOFA_EXPORT 
+
diff --git a/src/hrtf/neighbors.c b/src/hrtf/neighbors.c
index 1a6160b..22857ad 100644
--- a/src/hrtf/neighbors.c
+++ b/src/hrtf/neighbors.c
@@ -8,11 +8,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
-struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
-		struct MYSOFA_LOOKUP *lookup) {
+MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
+								   struct MYSOFA_LOOKUP *lookup) {
 	int i, index;
 	float *origin, *test;
 	float radius, radius2;
@@ -20,7 +21,7 @@ struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
 	float phi;
 
 	struct MYSOFA_NEIGHBORHOOD *neighbor = malloc(
-			sizeof(struct MYSOFA_NEIGHBORHOOD));
+		sizeof(struct MYSOFA_NEIGHBORHOOD));
 	if (!neighbor)
 		return NULL;
 
@@ -33,8 +34,8 @@ struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
 	for (i = 0; i < neighbor->elements * 6; i++)
 		neighbor->index[i] = -1;
 
-    origin = malloc(sizeof(float)*hrtf->C);
-    test = malloc(sizeof(float)*hrtf->C);
+	origin = malloc(sizeof(float)*hrtf->C);
+	test = malloc(sizeof(float)*hrtf->C);
 
 	for (i = 0; i < hrtf->M; i ++) {
 		memcpy(origin, hrtf->SourcePosition.values + i * hrtf->C, sizeof(float) * hrtf->C);
@@ -59,7 +60,7 @@ struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
 			test[0] = origin[0] + phi;
 			test[1] = origin[1];
 			test[2] = origin[2];
-			mysofa_s2c(test);
+			convertSphericalToCartesian(test,3);
 			index = mysofa_lookup(lookup, test);
 			if (index != i) {
 				neighbor->index[i * 6 + 1] = index;
@@ -129,13 +130,13 @@ struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
 	return neighbor;
 }
 
-int* mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int index) {
+MYSOFA_EXPORT int* mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int index) {
 	if (index < 0 || index >= neighborhood->elements)
 		return NULL ;
 	return neighborhood->index + index * 6;
 }
 
-void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood) {
+MYSOFA_EXPORT void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood) {
 	if(neighborhood) {
 		free(neighborhood->index);
 		free(neighborhood);
diff --git a/src/hrtf/reader.c b/src/hrtf/reader.c
index 63e4735..d491254 100644
--- a/src/hrtf/reader.c
+++ b/src/hrtf/reader.c
@@ -1,8 +1,8 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #include <errno.h>
 #include <stddef.h>
@@ -11,8 +11,10 @@
 #include <string.h>
 #include <ctype.h>
 
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "../hdf/reader.h"
+#include "../config.h"
 
 /* checks file address.
  * NULL is an invalid address indicating a invalid field
@@ -23,10 +25,18 @@ int validAddress(struct READER *reader, uint64_t address) {
 
 /* little endian */
 uint64_t readValue(struct READER *reader, int size) {
-	int i;
-	uint64_t value = fgetc(reader->fhd);
-	for (i = 1; i < size; i++)
-		value |= ((uint64_t) fgetc(reader->fhd)) << (i * 8);
+	int i,c;
+	uint64_t value;
+	c = fgetc(reader->fhd);
+	if(c<0)
+		return 0xffffffffffffffffLL;
+	value = (uint8_t)c;
+	for (i = 1; i < size; i++) {
+		c = fgetc(reader->fhd);
+		if(c<0)
+			return 0xffffffffffffffffLL;
+		value |= ((uint64_t)c) << (i * 8);
+	}
 	return value;
 }
 
@@ -41,10 +51,10 @@ static int mystrcmp(char *s1, char *s2) {
 }
 
 static int checkAttribute(struct MYSOFA_ATTRIBUTE *attribute, char *name,
-		char *value) {
+			  char *value) {
 	while (attribute) {
 		if (!mystrcmp(attribute->name, name)
-				&& !mystrcmp(attribute->value, value))
+		    && !mystrcmp(attribute->value, value))
 			return MYSOFA_OK;
 		attribute = attribute->next;
 	}
@@ -57,16 +67,16 @@ static int getDimension(unsigned *dim, struct DATAOBJECT *dataobject) {
 	struct MYSOFA_ATTRIBUTE *attr = dataobject->attributes;
 
 	if (!!(err = checkAttribute(dataobject->attributes, "CLASS",
-			"DIMENSION_SCALE")))
+				    "DIMENSION_SCALE")))
 		return err;
 
 	while (attr) {
 		log(" %s=%s\n",attr->name,attr->value);
 
 		if (!strcmp(attr->name, "NAME")
-				&& !strncmp(attr->value,
-						"This is a netCDF dimension but not a netCDF variable.",
-						53)) {
+		    && !strncmp(attr->value,
+				"This is a netCDF dimension but not a netCDF variable.",
+				53)) {
 			char *p = attr->value + strlen(attr->value) - 1;
 			while (isdigit(*p)) {
 				p--;
@@ -133,7 +143,7 @@ static struct MYSOFA_HRTF *getHrtf(struct READER *reader, int *err) {
 	/* read dimensions */
 	while (dir) {
 		if (dir->dataobject.name && dir->dataobject.name[0]
-				&& dir->dataobject.name[1] == 0) {
+		    && dir->dataobject.name[1] == 0) {
 			switch (dir->dataobject.name[0]) {
 			case 'I':
 				*err = getDimension(&hrtf->I, &dir->dataobject);
@@ -206,20 +216,23 @@ static struct MYSOFA_HRTF *getHrtf(struct READER *reader, int *err) {
 
 	return hrtf;
 
-	error: free(hrtf);
+ error: free(hrtf);
 	if (!*err)
 		*err = MYSOFA_INVALID_FORMAT;
 	return NULL;
 }
 
-struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err) {
+MYSOFA_EXPORT struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err) {
 	struct READER reader;
 	struct MYSOFA_HRTF *hrtf = NULL;
 
+	if(filename == NULL)
+		filename = CMAKE_INSTALL_PREFIX "/share/libmysofa/default.sofa";
+
 	if(strcmp(filename,"-"))
-    	reader.fhd = fopen(filename, "rb");
-    else
-        reader.fhd = stdin;
+		reader.fhd = fopen(filename, "rb");
+	else
+		reader.fhd = stdin;
 
 	if (!reader.fhd) {
 		log("cannot open file %s\n", filename);
@@ -238,7 +251,7 @@ struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err) {
 	superblockFree(&reader, &reader.superblock);
 	gcolFree(reader.gcol);
 	if(strcmp(filename,"-"))
-    	fclose(reader.fhd);
+		fclose(reader.fhd);
 
 	return hrtf;
 }
@@ -254,7 +267,7 @@ static void arrayFree(struct MYSOFA_ARRAY *array) {
 	free(array->values);
 }
 
-void mysofa_free(struct MYSOFA_HRTF *hrtf) {
+MYSOFA_EXPORT void mysofa_free(struct MYSOFA_HRTF *hrtf) {
 	if (!hrtf)
 		return;
 
@@ -277,3 +290,11 @@ void mysofa_free(struct MYSOFA_HRTF *hrtf) {
 	arrayFree(&hrtf->DataDelay);
 	free(hrtf);
 }
+
+MYSOFA_EXPORT void mysofa_getversion(int *major, int *minor, int *patch)
+{
+	*major = CPACK_PACKAGE_VERSION_MAJOR;
+	*minor = CPACK_PACKAGE_VERSION_MINOR;
+	*patch = CPACK_PACKAGE_VERSION_PATCH;
+}
+
diff --git a/src/hrtf/resample.c b/src/hrtf/resample.c
index bef3ac9..1ce9705 100644
--- a/src/hrtf/resample.c
+++ b/src/hrtf/resample.c
@@ -10,16 +10,17 @@
 #include <stdio.h>
 #include <math.h>
 #include <assert.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 #include "../resampler/speex_resampler.h"
 
-int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate) {
+MYSOFA_EXPORT int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate) {
 	int i, err;
 	float factor;
 	unsigned newN;
-    float *values;
-    SpeexResamplerState *resampler;
+	float *values;
+	SpeexResamplerState *resampler;
 	float *out;
 	float zero[10] = { 0,0,0,0,0,0,0,0,0,0 };
     
@@ -39,24 +40,26 @@ int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate) {
 	if (values == NULL)
 		return MYSOFA_NO_MEMORY;
 
-    resampler = speex_resampler_init(1, hrtf->DataSamplingRate.values[0], samplerate, 10, &err);
-    if(resampler == NULL)
-        return err;
+	resampler = speex_resampler_init(1, hrtf->DataSamplingRate.values[0], samplerate, 10, &err);
+	if(resampler == NULL) {
+		free(values);
+		return err;
+	}
 
-    out = malloc(sizeof(float)*(newN+ speex_resampler_get_output_latency(resampler)));
+	out = malloc(sizeof(float)*(newN+ speex_resampler_get_output_latency(resampler)));
 	for (i = 0; i < hrtf->R * hrtf->M; i++) {
-	    unsigned inlen = hrtf->N;
-	    unsigned outlen = newN;
+		unsigned inlen = hrtf->N;
+		unsigned outlen = newN;
 		speex_resampler_reset_mem(resampler);
 		speex_resampler_skip_zeros(resampler);
-        speex_resampler_process_float(resampler, 0, hrtf->DataIR.values + i * hrtf->N, &inlen,
-                                    values + i * newN, &outlen);
+		speex_resampler_process_float(resampler, 0, hrtf->DataIR.values + i * hrtf->N, &inlen,
+					      values + i * newN, &outlen);
 		assert(inlen == hrtf->N);
 		while (outlen < newN) {
-		    unsigned difflen = newN - outlen;
-		    inlen = 10;
-            speex_resampler_process_float(resampler, 0, zero, &inlen,
-                                    values + i * newN + outlen, &difflen);
+			unsigned difflen = newN - outlen;
+			inlen = 10;
+			speex_resampler_process_float(resampler, 0, zero, &inlen,
+						      values + i * newN + outlen, &difflen);
 			outlen+=difflen;
 		}
 	}
diff --git a/src/hrtf/spherical.c b/src/hrtf/spherical.c
index 85cf13d..b4dbba4 100644
--- a/src/hrtf/spherical.c
+++ b/src/hrtf/spherical.c
@@ -1,6 +1,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <math.h>
+#include "mysofa_export.h"
 #include "mysofa.h"
 #include "tools.h"
 
@@ -13,7 +14,7 @@ static void convertArray(struct MYSOFA_ARRAY *array) {
 	convertCartesianToSpherical(array->values, array->elements);
 }
 
-void mysofa_tospherical(struct MYSOFA_HRTF *hrtf) {
+MYSOFA_EXPORT void mysofa_tospherical(struct MYSOFA_HRTF *hrtf) {
 	convertArray(&hrtf->ListenerView);
 	convertArray(&hrtf->ListenerUp);
 	convertArray(&hrtf->ListenerPosition);
@@ -31,7 +32,7 @@ static void convertArray2(struct MYSOFA_ARRAY *array) {
 	convertSphericalToCartesian(array->values, array->elements);
 }
 
-void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf) {
+MYSOFA_EXPORT void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf) {
 	convertArray2(&hrtf->ListenerView);
 	convertArray2(&hrtf->ListenerUp);
 	convertArray2(&hrtf->ListenerPosition);
diff --git a/src/hrtf/tools.c b/src/hrtf/tools.c
index d9d359e..f2578a7 100644
--- a/src/hrtf/tools.c
+++ b/src/hrtf/tools.c
@@ -10,14 +10,16 @@
 #include <stdio.h>
 #include <string.h>
 #include "tools.h"
+#include "mysofa_export.h"
+#include "mysofa.h"
 
 char *mysofa_strdup(const char *str)
 {
-    size_t size = strlen(str) + 1;
-    char *copy = malloc(size);
-    if(copy)
-        memcpy(copy, str, size);
-    return copy;
+	size_t size = strlen(str) + 1;
+	char *copy = malloc(size);
+	if(copy)
+		memcpy(copy, str, size);
+	return copy;
 }
 
 int verifyAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name, char *value) {
@@ -30,10 +32,10 @@ int verifyAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name, char *value) {
 }
 
 int changeAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name, char *value,
-		char *newvalue) {
+		    char *newvalue) {
 	while (attr) {
 		if (!strcmp(name, attr->name)
-				&& (value == NULL || !strcmp(value, attr->value))) {
+		    && (value == NULL || !strcmp(value, attr->value))) {
 			free(attr->value);
 			attr->value = mysofa_strdup(newvalue);
 			return 1;
@@ -53,8 +55,7 @@ char* mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name) {
 	return NULL;
 }
 
-
-void mysofa_c2s(float values[3])
+MYSOFA_EXPORT void mysofa_c2s(float values[3])
 {
 	float x,y,z,r,theta,phi;
 	x = values[0];
@@ -70,7 +71,7 @@ void mysofa_c2s(float values[3])
 	values[2] = r;
 }
 
-void mysofa_s2c(float values[3])
+MYSOFA_EXPORT void mysofa_s2c(float values[3])
 {
 	float x, r, theta, phi;
 	phi = values[0] * (M_PI / 180);
@@ -101,26 +102,8 @@ void convertSphericalToCartesian(float *values, int elements) {
 
 float radius(float *cartesian) {
 	return sqrtf(
-			powf(cartesian[0], 2.f) + powf(cartesian[1], 2.f)
-					+ powf(cartesian[2], 2.f));
-}
-
-float distance(float *cartesian1, float *cartesian2) {
-	return sqrtf(
-			powf(cartesian1[0] - cartesian2[0], 2.f)
-					+ powf(cartesian1[1] - cartesian2[1], 2.f)
-					+ powf(cartesian1[2] - cartesian2[2], 2.f));
-}
-
-/*
- static int fequalsf(float a, float b)
- {
- return fabsf(a-b)<0.000001;
- }
- */
-
-int fequals(float a, float b) {
-	return fabsf(a - b) < 0.00001;
+		powf(cartesian[0], 2.f) + powf(cartesian[1], 2.f)
+		+ powf(cartesian[2], 2.f));
 }
 
 /*
@@ -128,7 +111,7 @@ int fequals(float a, float b) {
  */
 
 void nsearch(const void *key, const char *base, size_t num, size_t size,
-		int (*cmp)(const void *key, const void *elt), int *lower, int *higher) {
+	     int (*cmp)(const void *key, const void *elt), int *lower, int *higher) {
 	size_t start = 0, end = num;
 	int result;
 
diff --git a/src/hrtf/tools.h b/src/hrtf/tools.h
index 9cb4a0f..2d24a21 100644
--- a/src/hrtf/tools.h
+++ b/src/hrtf/tools.h
@@ -9,19 +9,22 @@
 #define SRC_TOOLS_H_
 
 #include <stdlib.h>
+#include <math.h>
 #include "mysofa.h"
 
 int changeAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name, char *value,
-		char *newvalue);
+		    char *newvalue);
 int verifyAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name, char *value);
 char* getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
 
 void convertCartesianToSpherical(float *values, int elements);
 void convertSphericalToCartesian(float *values, int elements);
-int fequalsf(float a, float b);
-int fequals(float a, float b);
+
+#define fequals(a,b) (fabsf(a - b) < 0.00001)
+
 float radius(float *cartesian);
-float distance(float *cartesian1, float *cartesian2);
+
+#define distance(cartesian1, cartesian2) (sqrtf(powf((cartesian1)[0] - (cartesian2)[0], 2.f) + powf((cartesian1)[1] - (cartesian2)[1], 2.f) + powf((cartesian1)[2] - (cartesian2)[2], 2.f)))
 
 void copyToFloat(float *out, float *in, int size);  
 void copyFromFloat(float *out, float *in, int size);
@@ -32,6 +35,6 @@ void scaleArray(float *dst, int size, float w);
 float loudness(float *in, int size);
 
 void nsearch(const void *key, const char *base, size_t num, size_t size,
-		int (*cmp)(const void *key, const void *elt), int *lower, int *higher);
+	     int (*cmp)(const void *key, const void *elt), int *lower, int *higher);
 
 #endif /* SRC_TOOLS_H_ */
diff --git a/src/resampler/speex_resampler.c b/src/resampler/speex_resampler.c
index 3958528..7029de1 100644
--- a/src/resampler/speex_resampler.c
+++ b/src/resampler/speex_resampler.c
@@ -465,9 +465,9 @@ static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_in
 
 static int _muldiv(spx_uint32_t *result, spx_uint32_t value, spx_uint32_t mul, spx_uint32_t div)
 {
-   speex_assert(result);
    spx_uint32_t major = value / div;
    spx_uint32_t remainder = value % div;
+   speex_assert(result);
    /* TODO: Could use 64 bits operation to check for overflow. But only guaranteed in C99+ */
    if (remainder > UINT32_MAX / mul || major > UINT32_MAX / mul
        || major * mul > UINT32_MAX - remainder * mul / div)
@@ -837,7 +837,7 @@ EXPORT void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_r
    *out_rate = st->out_rate;
 }
 
-static inline spx_uint32_t _gcd(spx_uint32_t a, spx_uint32_t b)
+static spx_uint32_t _gcd(spx_uint32_t a, spx_uint32_t b)
 {
    while (b != 0)
    {
diff --git a/src/tests/cache.c b/src/tests/cache.c
index 74d1ba4..84d2f36 100644
--- a/src/tests/cache.c
+++ b/src/tests/cache.c
@@ -3,7 +3,6 @@
 #include <float.h>
 #include <stdio.h>
 #include <math.h>
-#include <strings.h>
 #include "../hrtf/mysofa.h"
 #include "../hrtf/tools.h"
 #include "tests.h"
@@ -29,12 +28,11 @@ void test_cache() {
 	mysofa_cache_release_all();							/* remove all */
 	CU_ASSERT(!mysofa_cache_lookup(filename1,sr1));		/* cache must be empty now */
 
-
 /*
-	 mysofa_cache_release(easy1);		
-	free(easy1) 
+  mysofa_cache_release(easy1);		
+  free(easy1) 
 	
-	must segfail
+  must segfail
 */
 
 	easy1 = malloc(sizeof(struct MYSOFA_EASY));
diff --git a/src/tests/check.c b/src/tests/check.c
index f1bcb98..0b01b59 100644
--- a/src/tests/check.c
+++ b/src/tests/check.c
@@ -13,8 +13,10 @@ static void check(char *filename)
 
 	hrtf = mysofa_load(filename, &err);
 
-	if (!hrtf)
+	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
+	}
 
 	err = mysofa_check(hrtf);
 	CU_ASSERT(err == MYSOFA_OK);
diff --git a/src/tests/easy.c b/src/tests/easy.c
index 76c4baf..00a7cba 100644
--- a/src/tests/easy.c
+++ b/src/tests/easy.c
@@ -8,6 +8,10 @@
 #include "tests.h"
 #include "json.h"
 
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#endif
+
 /* #define VDEBUG */
 
 void test_easy() {
@@ -28,6 +32,7 @@ void test_easy() {
 	easy = mysofa_open("share/MIT_KEMAR_normal_pinna.sofa", 8000., &filterlength, &err);
 	if (!easy) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 
 	mysofa_close(easy);
@@ -35,31 +40,32 @@ void test_easy() {
 	easy = mysofa_open("tests/tester.sofa", 48000, &filterlength, &err);
 	if (!easy) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 	mysofa_minphase(easy->hrtf, 0.01);
 	
-    for(filters=0;filters<easy->hrtf->M;filters++) {
-        c[0]=easy->hrtf->SourcePosition.values[filters*3];
-        c[1]=easy->hrtf->SourcePosition.values[filters*3+1];
-        c[2]=easy->hrtf->SourcePosition.values[filters*3+2];
-        convertCartesianToSpherical(c,3);
+	for(filters=0;filters<easy->hrtf->M;filters++) {
+		c[0]=easy->hrtf->SourcePosition.values[filters*3];
+		c[1]=easy->hrtf->SourcePosition.values[filters*3+1];
+		c[2]=easy->hrtf->SourcePosition.values[filters*3+2];
+		mysofa_c2s(c);
         
 #ifdef VDEBUG        
    		printf("in %d %f %f %f # %f %f %f\n",filters,c[0],c[1],c[2],easy->hrtf->SourcePosition.values[filters*3],easy->hrtf->SourcePosition.values[filters*3+1],easy->hrtf->SourcePosition.values[filters*3+2]);
 #endif   		
-        c[0] = fmod(round(c[0]+360),360);
-        c[1] = fmod(round(c[1]+361),360);        
-        l1 = round(easy->hrtf->DataDelay.values[filters*2]*48000*2);
-        l2 = round(easy->hrtf->DataDelay.values[filters*2+1]*48000*2);
+		c[0] = fmod(round(c[0]+360),360);
+		c[1] = fmod(round(c[1]+361),360);        
+		l1 = round(easy->hrtf->DataDelay.values[filters*2]*48000*2);
+		l2 = round(easy->hrtf->DataDelay.values[filters*2+1]*48000*2);
 
 #ifdef VDEBUG        
 /*   		printf("compare %d %f %f %f %f %f\n",filters,c[0],c[1],c[2],l1,l2); */
 #endif   		
-        CU_ASSERT(!((fabs(c[0]-l1)>2 || fabs(c[1]-l2)>2) && !fequals(l2,90)));
-    }
+		CU_ASSERT(!((fabs(c[0]-l1)>2 || fabs(c[1]-l2)>2) && !fequals(l2,90)));
+	}
     
     
-    filters=0; 
+	filters=0; 
 	for(theta=-90.;theta<=90.;theta+=5.) {
 		r = round(cos(theta*M_PI/180.) * 120.);
 		if(r==0.) r=1;
@@ -73,8 +79,8 @@ void test_easy() {
 	ir = malloc(filters*easy->hrtf->N*sizeof(float)*2);
 	delays = malloc(filters*2*sizeof(float));
 
-    sdiff1 = sdiff2 = 0;
-    err = 0;
+	sdiff1 = sdiff2 = 0;
+	err = 0;
 	for(theta=-90.;theta<=90.;theta+=5.) {
 		int r = round(cos(theta*M_PI/180.) * 120.);
 		int phi;
@@ -83,25 +89,25 @@ void test_easy() {
 			coordinates[count*3+0] = phi * (360. / r);
 			coordinates[count*3+1] = theta;
 			coordinates[count*3+2] = 1;
-			convertSphericalToCartesian(coordinates+count*3,3);
+			mysofa_s2c(coordinates+count*3);
 #ifdef VDEBUG
 			printf("req %f %f %d %f %f %f\n",phi* (360. / r),theta,count,coordinates[count*3+0],coordinates[count*3+1],coordinates[count*3+2]);
 #endif
 			mysofa_getfilter_float(easy,
-					coordinates[count*3+0],
-					coordinates[count*3+1],
-					coordinates[count*3+2],
-					ir + 2*count * easy->hrtf->N,
-					ir + (2*count+1) * easy->hrtf->N,
-					&delays[2*count], &delays[2*count+1]);
-            diff1 = fabs(phi * (360. / r) - delays[2*count] * 48000 * 2);
-            diff2 = fabs(fmod(theta + 360,360) - delays[2*count+1] * 48000 * 2);
-            if(diff1 > 5 || diff2 > 5)
-                err++;
-            else {
-                sdiff1 += diff1;
-                sdiff2 += diff2;
-            }
+					       coordinates[count*3+0],
+					       coordinates[count*3+1],
+					       coordinates[count*3+2],
+					       ir + 2*count * easy->hrtf->N,
+					       ir + (2*count+1) * easy->hrtf->N,
+					       &delays[2*count], &delays[2*count+1]);
+			diff1 = fabs(phi * (360. / r) - delays[2*count] * 48000 * 2);
+			diff2 = fabs(fmod(theta + 360,360) - delays[2*count+1] * 48000 * 2);
+			if(diff1 > 5 || diff2 > 5)
+				err++;
+			else {
+				sdiff1 += diff1;
+				sdiff2 += diff2;
+			}
                 
 #ifdef VDEBUG
 			printf("diff %f %f\t", diff1, diff2);
@@ -118,9 +124,9 @@ void test_easy() {
 #ifdef VDEBUG
 	printf("errors %f%% diffs %f %f\n", err*100./count, sdiff1 / (count-err), sdiff2 / (count-err));
 #endif
-    CU_ASSERT(err < 31.7);
-    CU_ASSERT(sdiff1 < 1.67);
-    CU_ASSERT(sdiff2 < 1.43);
+	CU_ASSERT(err < 31.7);
+	CU_ASSERT(sdiff1 < 1.67);
+	CU_ASSERT(sdiff2 < 1.43);
 
 	free(easy->hrtf->DataDelay.values);
 	free(easy->hrtf->DataIR.values);
@@ -133,7 +139,7 @@ void test_easy() {
 	easy->hrtf->SourcePosition.values=coordinates;
 	easy->hrtf->M = filters;
 
-	file = fopen("easy.tmp.json","w");
+	file = fopen("/tmp/easy.tmp.json","w");
 	CU_ASSERT(file!=NULL);
 	printJson(file,easy->hrtf);
 	fclose(file);
diff --git a/src/tests/external.c b/src/tests/external.c
new file mode 100644
index 0000000..9b7292c
--- /dev/null
+++ b/src/tests/external.c
@@ -0,0 +1,46 @@
+#include <CUnit/Basic.h>
+#include <CUnit/CUnit.h>
+#include <string.h>
+#include <stdio.h>
+#include "tests.h"
+
+int main() {
+
+	int err;
+    
+	CU_pSuite pSuite = NULL;
+
+	/* initialize the CUnit test registry */
+	if (CUE_SUCCESS != CU_initialize_registry())
+		return CU_get_error();
+
+	/* add a suite to the registry */
+	pSuite = CU_add_suite("Suite Tools", NULL, NULL);
+	if (NULL == pSuite) {
+		CU_cleanup_registry();
+		return CU_get_error();
+	}
+
+	/* add the tests to the suite */
+	/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
+	if ((NULL == CU_add_test(pSuite, "test of mysofa_check", test_check))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_lookup", test_lookup))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_neighbors", test_neighbors))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_interpolate", test_interpolate))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_resample", test_resample))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_loudness", test_loudness))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_minphase", test_minphase))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_cache", test_cache))
+	    || (NULL == CU_add_test(pSuite, "test of mysofa_easy", test_easy))
+		) {
+		CU_cleanup_registry();
+		return CU_get_error();
+	}
+
+	/* Run all tests using the CUnit Basic interface */
+	CU_basic_set_mode(CU_BRM_VERBOSE);
+	CU_basic_run_tests();
+	err = CU_get_number_of_failures();
+	CU_cleanup_registry();
+	return err;
+}
diff --git a/src/tests/tests.c b/src/tests/internal.c
similarity index 52%
rename from src/tests/tests.c
rename to src/tests/internal.c
index 4d504f7..d115b4d 100644
--- a/src/tests/tests.c
+++ b/src/tests/internal.c
@@ -6,7 +6,7 @@
 
 int main() {
 
-    int err;
+	int err;
     
 	CU_pSuite pSuite = NULL;
 
@@ -24,17 +24,8 @@ int main() {
 	/* add the tests to the suite */
 	/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
 	if ((NULL == CU_add_test(pSuite, "test of coordinates", test_coordinates))
-		|| (NULL == CU_add_test(pSuite, "test of nsearch", test_nsearch))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_check", test_check))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_lookup", test_lookup))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_neighbors", test_neighbors))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_interpolate", test_interpolate))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_resample", test_resample))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_loudness", test_loudness))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_minphase", test_minphase))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_cache", test_cache))
-		|| (NULL == CU_add_test(pSuite, "test of mysofa_easy", test_easy))
-			) {
+	    || (NULL == CU_add_test(pSuite, "test of nsearch", test_nsearch))
+		) {
 		CU_cleanup_registry();
 		return CU_get_error();
 	}
diff --git a/src/tests/interpolate.c b/src/tests/interpolate.c
index 41b4375..41d0ccb 100644
--- a/src/tests/interpolate.c
+++ b/src/tests/interpolate.c
@@ -1,4 +1,3 @@
-#include <string.h>
 #include <float.h>
 #include <stdio.h>
 #include <math.h>
@@ -17,10 +16,11 @@ void test_interpolate() {
 	float c[3];
 
 	hrtf = mysofa_load("share/MIT_KEMAR_normal_pinna.sofa",
-				&err);
+			   &err);
 
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 
 	mysofa_tocartesian(hrtf);
@@ -28,17 +28,17 @@ void test_interpolate() {
 	fir = malloc(hrtf->N * hrtf->R * sizeof(float));
 
 	res = mysofa_interpolate(hrtf, hrtf->SourcePosition.values, 0, neighborhood,
-			fir, delays);
+				 fir, delays);
 	CU_ASSERT(res == hrtf->DataIR.values);
 	CU_ASSERT(delays[0] == 0);
 	CU_ASSERT(delays[1] == 0);
 
 	c[0] = (hrtf->SourcePosition.values[0] + hrtf->SourcePosition.values[3])
-			/ 2;
+		/ 2;
 	c[1] = (hrtf->SourcePosition.values[1] + hrtf->SourcePosition.values[4])
-			/ 2;
+		/ 2;
 	c[2] = (hrtf->SourcePosition.values[2] + hrtf->SourcePosition.values[5])
-			/ 2;
+		/ 2;
 	neighborhood[0] = 1;
 
 	res = mysofa_interpolate(hrtf, c, 0, neighborhood, fir, delays);
@@ -49,7 +49,7 @@ void test_interpolate() {
 	for (i = 0; i < hrtf->N * hrtf->R; i++) {
 #ifdef VDEBUG
 		printf("%f %f %f\n", res[i], hrtf->DataIR.values[i],
-				hrtf->DataIR.values[i + hrtf->N * hrtf->R]);
+		       hrtf->DataIR.values[i + hrtf->N * hrtf->R]);
 #endif
 		CU_ASSERT(fequals(res[i],(hrtf->DataIR.values[i]+hrtf->DataIR.values[i+hrtf->N*hrtf->R])/2));
 	}
@@ -57,4 +57,5 @@ void test_interpolate() {
 	/* TODO add some tests... */
 
 	mysofa_free(hrtf);
+	free(fir);
 }
diff --git a/src/tests/json.c b/src/tests/json.c
index 026a44d..dc4f583 100644
--- a/src/tests/json.c
+++ b/src/tests/json.c
@@ -50,7 +50,7 @@ static void printString(FILE *out, char *string) {
 }
 
 static void printAttributes(FILE *out, int spaces,
-		struct MYSOFA_ATTRIBUTE *attr) {
+			    struct MYSOFA_ATTRIBUTE *attr) {
 	int i;
 
 	for (i = 0; i < spaces; i++)
@@ -71,19 +71,19 @@ static void printAttributes(FILE *out, int spaces,
 }
 
 /*
- "Dimensions":[
- 1,
- 2
- ],
- "DimensionNames":[
- "I",
- "R"
- ],
- */
+  "Dimensions":[
+  1,
+  2
+  ],
+  "DimensionNames":[
+  "I",
+  "R"
+  ],
+*/
 
 static void printDimensions(FILE *out, struct MYSOFA_HRTF *hrtf,
-		struct MYSOFA_ATTRIBUTE **p) {
-	struct MYSOFA_ATTRIBUTE *found;
+			    struct MYSOFA_ATTRIBUTE **p) {
+	struct MYSOFA_ATTRIBUTE *found = NULL;
 	char *s;
 	int dimensions[4];
 	int dims = 0, i;
@@ -147,7 +147,7 @@ static void printDimensions(FILE *out, struct MYSOFA_HRTF *hrtf,
 }
 
 static int printArray(FILE *out, struct MYSOFA_HRTF *hrtf,
-		struct MYSOFA_ARRAY *array, char *name) {
+		      struct MYSOFA_ARRAY *array, char *name) {
 	int i = 0;
 
 	if (!array->elements)
@@ -169,7 +169,7 @@ static int printArray(FILE *out, struct MYSOFA_HRTF *hrtf,
 	fprintf(out, "   \"Values\": [");
 	for (i = 0; i < array->elements; i++) {
 		fprintf(out, "%c%s%.6f", i == 0 ? ' ' : ',',
-				i % 20 == 19 ? "\n    " : "", array->values[i]);
+			i % 20 == 19 ? "\n    " : "", array->values[i]);
 	}
 
 	fprintf(out, " ]\n  }");
diff --git a/src/tests/lookup.c b/src/tests/lookup.c
index 3ebade6..76764f5 100644
--- a/src/tests/lookup.c
+++ b/src/tests/lookup.c
@@ -27,8 +27,10 @@ void test_lookup() {
 
 	hrtf = mysofa_load("tests/Pulse.sofa", &err);
 
-	if (!hrtf)
+	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
+	}
 
 	mysofa_tocartesian(hrtf);
 
@@ -55,11 +57,11 @@ void test_lookup() {
 #ifdef HAVE_GETTIMEOFDAY
 		gettimeofday(&r1, NULL);
 #endif		
-	    lk = mysofa_lookup(lookup, find);
+		lk = mysofa_lookup(lookup, find);
 #ifdef HAVE_GETTIMEOFDAY
 		gettimeofday(&r2, NULL);
 		duration1 = (r2.tv_sec - r1.tv_sec) * 1000000.
-				+ (r2.tv_usec - r1.tv_usec);
+			+ (r2.tv_usec - r1.tv_usec);
 
 		gettimeofday(&r1, NULL);
 #endif		
@@ -73,15 +75,15 @@ void test_lookup() {
 #ifdef HAVE_GETTIMEOFDAY		
 		gettimeofday(&r2, NULL);
 		duration2 = (r2.tv_sec - r1.tv_sec) * 1000000.
-				+ (r2.tv_usec - r1.tv_usec);
+			+ (r2.tv_usec - r1.tv_usec);
 #endif
 
 		CU_ASSERT(lk==index);
 		if(lk!=index) {
 			printf("O(log n) %f %f %f -> %d %f \t\t", find[0], find[1], find[2], lk,
-				distance(find, hrtf->SourcePosition.values + lk  * hrtf->C));
+			       distance(find, hrtf->SourcePosition.values + lk  * hrtf->C));
 			printf("O(n): %f %f %f -> %d %f\t%f%%\n", find[0], find[1], find[2],
-				index, dmin, duration1 / duration2 * 100);
+			       index, dmin, duration1 / duration2 * 100);
 		}
 	}
 
diff --git a/src/tests/loudness.c b/src/tests/loudness.c
index f9e0737..76842fc 100644
--- a/src/tests/loudness.c
+++ b/src/tests/loudness.c
@@ -15,6 +15,7 @@ void test_loudness() {
 	hrtf = mysofa_load("tests/Pulse.sofa", &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 
 	factor = mysofa_loudness(hrtf);
@@ -27,7 +28,7 @@ void test_loudness() {
 
 
 	hrtf = mysofa_load("share/MIT_KEMAR_normal_pinna.sofa",
-			&err);
+			   &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
 	}
@@ -41,8 +42,8 @@ void test_loudness() {
 	factor = mysofa_loudness(hrtf);
 #ifdef VDEBUG
 	printf(
-			"loudness of MIT_KEMAR_normal_pinna.sofa after normalization %f\n",
-			factor);
+		"loudness of MIT_KEMAR_normal_pinna.sofa after normalization %f\n",
+		factor);
 #endif
 	CU_ASSERT(fequals(factor,1.));
 
diff --git a/src/tests/minphase.c b/src/tests/minphase.c
index c4a19b8..05da2cd 100644
--- a/src/tests/minphase.c
+++ b/src/tests/minphase.c
@@ -15,6 +15,7 @@ void test_minphase() {
 	hrtf = mysofa_load("tests/Pulse.sofa", &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 
 	len = mysofa_minphase(hrtf, 0.01);
@@ -29,7 +30,7 @@ void test_minphase() {
 
 
 	hrtf = mysofa_load("share/MIT_KEMAR_normal_pinna.sofa",
-			&err);
+			   &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
 	}
@@ -42,7 +43,7 @@ void test_minphase() {
 	mysofa_free(hrtf);
 
 	hrtf = mysofa_load("share/MIT_KEMAR_normal_pinna.sofa",
-				&err);
+			   &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
 	}
@@ -57,7 +58,7 @@ void test_minphase() {
 
 
 	hrtf = mysofa_load("share/MIT_KEMAR_normal_pinna.sofa",
-			&err);
+			   &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
 	}
diff --git a/src/tests/neighbors.c b/src/tests/neighbors.c
index e6e8857..18a6e91 100644
--- a/src/tests/neighbors.c
+++ b/src/tests/neighbors.c
@@ -18,9 +18,10 @@ void test_neighbors() {
 #endif
 
 	hrtf = mysofa_load("share/MIT_KEMAR_normal_pinna.sofa",
-			&err);
+			   &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 
 	mysofa_tocartesian(hrtf);
@@ -33,7 +34,7 @@ void test_neighbors() {
 	}
 
 	neighborhood = mysofa_neighborhood_init(hrtf,
-			lookup);
+						lookup);
 
 	if (neighborhood == NULL) {
 		CU_FAIL("Error getting neighborhood.");
@@ -42,7 +43,6 @@ void test_neighbors() {
 		return;
 	}
 
-
 	for (i = 0; i < hrtf->M; i ++) {
 		memcpy(c, hrtf->SourcePosition.values + i * hrtf->C, sizeof(float) * hrtf->C);
 		mysofa_c2s(c);
@@ -54,7 +54,7 @@ void test_neighbors() {
 		for (j = 0; j < 6; j++) {
 			if (res[j] >= 0) {
 				memcpy(C, hrtf->SourcePosition.values + res[j] * hrtf->C,
-						sizeof(float) * hrtf->C);
+				       sizeof(float) * hrtf->C);
 				mysofa_c2s(C);
 #ifdef VDEBUG
 				printf("\t%c %4.0f %4.0f %5.2f", dir[j], C[0], C[1], C[2]);
diff --git a/src/tests/resample.c b/src/tests/resample.c
index 83839e8..7519f44 100644
--- a/src/tests/resample.c
+++ b/src/tests/resample.c
@@ -15,9 +15,15 @@ void test_resample() {
 	hrtf = mysofa_load("tests/Pulse.sofa", &err);
 	if (!hrtf) {
 		CU_FAIL_FATAL("Error reading file.");
+		return;
 	}
 
 	backup = malloc(sizeof(float)*hrtf->N * 3);
+	if(!backup) {
+		CU_FAIL_FATAL("No memory, N is too large.");
+		mysofa_free(hrtf);
+		return;
+	}
 
 	for (i = 0; i < hrtf->N * 3; i++) {
 		backup[i]=hrtf->DataIR.values[i];
@@ -32,11 +38,11 @@ void test_resample() {
 		if ((i % hrtf->N) == (hrtf->N - 1))
 			printf("\n");
 #endif
-			CU_ASSERT( !((hrtf->DataIR.values[i]>0.4 && backup[i/2]==0.) ||
-				(hrtf->DataIR.values[i]<=0.3 && backup[i/2]==1.) ) );
+		CU_ASSERT( !((hrtf->DataIR.values[i]>0.4 && backup[i/2]==0.) ||
+			     (hrtf->DataIR.values[i]<=0.3 && backup[i/2]==1.) ) );
 	}
 
-    free(backup);
+	free(backup);
 	mysofa_free(hrtf);
 }
 
diff --git a/src/tests/sofa2json.c b/src/tests/sofa2json.c
index eab2a1e..7fd62a4 100644
--- a/src/tests/sofa2json.c
+++ b/src/tests/sofa2json.c
@@ -1,8 +1,8 @@
 /*
 
- Copyright 2016 Christian Hoene, Symonics GmbH
+  Copyright 2016 Christian Hoene, Symonics GmbH
 
- */
+*/
 
 #include <stddef.h>
 #include <stdlib.h>
@@ -25,7 +25,7 @@ int main(int argc, char **argv) {
 
 	if (!hrtf) {
 		fprintf(stderr, "Error reading file %s. Error code: %d\n", argv[1],
-				err);
+			err);
 		return err;
 	}
 

-- 
libmysofa packaging



More information about the pkg-multimedia-commits mailing list