Fix unsigned int overflow reported by UBSan (#761)
[openjpeg.git] / src / lib / openjp2 / openjpeg.h
index c8d806175c28edc677e5aacc36b58529eaa0708b..c07e9c84b347b51ade0db0e880a0d9bed4b2b63e 100644 (file)
@@ -78,29 +78,33 @@ Most compilers implement their own version of this keyword ...
 
 #if defined(OPJ_STATIC) || !defined(_WIN32)
 /* http://gcc.gnu.org/wiki/Visibility */
-#if __GNUC__ >= 4
-#define OPJ_API    __attribute__ ((visibility ("default")))
-#define OPJ_LOCAL  __attribute__ ((visibility ("hidden")))
+#      if __GNUC__ >= 4
+#              if defined(OPJ_STATIC) /* static library uses "hidden" */
+#                      define OPJ_API    __attribute__ ((visibility ("hidden")))
+#              else
+#                      define OPJ_API    __attribute__ ((visibility ("default")))
+#              endif
+#              define OPJ_LOCAL  __attribute__ ((visibility ("hidden")))
+#      else
+#              define OPJ_API
+#              define OPJ_LOCAL
+#      endif
+#      define OPJ_CALLCONV
 #else
-#define OPJ_API
-#define OPJ_LOCAL
-#endif
-#define OPJ_CALLCONV
-#else
-#define OPJ_CALLCONV __stdcall
+#      define OPJ_CALLCONV __stdcall
 /*
 The following ifdef block is the standard way of creating macros which make exporting 
 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
 symbol defined on the command line. this symbol should not be defined on any project
 that uses this DLL. This way any other project whose source files include this file see 
-OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
+OPJ_API functions as being imported from a DLL, whereas this DLL sees symbols
 defined with this macro as being exported.
 */
-#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
-#define OPJ_API __declspec(dllexport)
-#else
-#define OPJ_API __declspec(dllimport)
-#endif /* OPJ_EXPORTS */
+#      if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
+#              define OPJ_API __declspec(dllexport)
+#      else
+#              define OPJ_API __declspec(dllimport)
+#      endif /* OPJ_EXPORTS */
 #endif /* !OPJ_STATIC || !_WIN32 */
 
 typedef int OPJ_BOOL;
@@ -846,7 +850,7 @@ typedef struct opj_codestream_info {
 } opj_codestream_info_t;
 
 /* <----------------------------------------------------------- */
-/* new output managment of the codestream information and index */
+/* new output management of the codestream information and index */
 
 /**
  * Tile-component coding parameters information
@@ -1116,14 +1120,6 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, O
  * @param      p_stream        the stream to destroy.
  */
 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
-
-/**
- * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. 
- * If needed the user must close its own implementation of the stream.
- *
- * @param      p_stream        the stream to destroy.
- */
-OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream);
  
 /**
  * Sets the given function to be used as a read function.
@@ -1153,21 +1149,13 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, o
 */
 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
 
-/**
- * Sets the given data to be used as a user data for the stream.
- * @param              p_stream        the stream to modify
- * @param              p_data          the data to set.
- * @warning depending on your source object p_stream this function may leak, use opj_stream_set_user_data_v3
-*/
-OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data));
-
 /**
  * Sets the given data to be used as a user data for the stream.
  * @param              p_stream        the stream to modify
  * @param              p_data          the data to set.
  * @param              p_function      the function to free p_data when opj_stream_destroy() is called.
 */
-OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_v3 (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function);
+OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function);
 
 /**
  * Sets the length of the user data for the stream.
@@ -1182,14 +1170,14 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream
  * @param fname             the filename of the file to stream
  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
 */
-OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
+OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream);
  
 /** Create a stream from a file identified with its filename with a specific buffer size
  * @param fname             the filename of the file to stream
  * @param p_buffer_size     size of the chunk used to stream
  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
 */
-OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname, 
+OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (const char *fname,
                                                                      OPJ_SIZE_T p_buffer_size,
                                                                      OPJ_BOOL p_is_read_stream);
  
@@ -1359,7 +1347,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile (    opj_codec_t *p_codec,
                                                                                                opj_stream_t *p_stream );
 
 /**
- * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
+ * Reads a tile header. This function is compulsory and allows one to know the size of the tile that will be decoded.
  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
  *
  * @param      p_codec                 the jpeg2000 codec.