Fix some TODO concerning error handling
This commit is contained in:
parent
1d3cd5fb35
commit
c1c58f087c
@ -670,14 +670,12 @@ static size_t gmio_amf_ostringstream_write_zlib(
|
||||
} while (z_stream->avail_out == 0);
|
||||
/* Check all input was used */
|
||||
if (z_stream->avail_in != 0) {
|
||||
/* TODO: set more precise error */
|
||||
context->error = GMIO_ERROR_UNKNOWN;
|
||||
context->error = GMIO_ERROR_ZLIB_DEFLATE_NOT_ALL_INPUT_USED;
|
||||
return total_written_len;
|
||||
}
|
||||
/* Check stream is complete */
|
||||
if (context->z_flush == Z_FINISH && z_retcode != Z_STREAM_END) {
|
||||
/* TODO: set more precise error */
|
||||
context->error = GMIO_ERROR_UNKNOWN;
|
||||
context->error = GMIO_ERROR_ZLIB_DEFLATE_STREAM_INCOMPLETE;
|
||||
return total_written_len;
|
||||
}
|
||||
context->z_compressed_size += total_written_len;
|
||||
@ -867,7 +865,8 @@ int gmio_amf_write(
|
||||
|
||||
/* Check validity of input parameters */
|
||||
context.error = GMIO_ERROR_OK;
|
||||
/* TODO: check stream function pointers */
|
||||
if (!gmio_check_ostream(&context.error, stream))
|
||||
goto label_end;
|
||||
if (!gmio_check_memblock(&context.error, memblock))
|
||||
goto label_end;
|
||||
if (!gmio_amf_check_document(&context.error, doc))
|
||||
|
@ -64,9 +64,15 @@ enum gmio_error
|
||||
/*! Argument size for the memory block is too small */
|
||||
GMIO_ERROR_INVALID_MEMBLOCK_SIZE,
|
||||
|
||||
/*! Provided gmio_stream is \c NULL */
|
||||
GMIO_ERROR_NULL_STREAM,
|
||||
|
||||
/*! An error occurred with gmio_stream */
|
||||
GMIO_ERROR_STREAM,
|
||||
|
||||
/*! Some required gmio_stream function pointer is NULL */
|
||||
GMIO_ERROR_STREAM_FUNC_REQUIRED,
|
||||
|
||||
/*! Task was stopped by user, that is to say
|
||||
* gmio_task_iface::func_is_stop_requested() returned true */
|
||||
GMIO_ERROR_TASK_STOPPED,
|
||||
@ -105,6 +111,12 @@ enum gmio_error
|
||||
* gmio_zlib_compress_options::memory_usage */
|
||||
GMIO_ERROR_ZLIB_INVALID_COMPRESS_MEMORY_USAGE,
|
||||
|
||||
/*! All input to be deflated(compressed) was not processed */
|
||||
GMIO_ERROR_ZLIB_DEFLATE_NOT_ALL_INPUT_USED,
|
||||
|
||||
/*! Deflate failure to flush pending output */
|
||||
GMIO_ERROR_ZLIB_DEFLATE_STREAM_INCOMPLETE,
|
||||
|
||||
/* ZIP */
|
||||
/*! Zip64 format requires the compiler to provide a 64b integer type */
|
||||
GMIO_ERROR_ZIP_INT64_TYPE_REQUIRED,
|
||||
|
@ -185,7 +185,7 @@ enum gmio_bool_value
|
||||
# define GMIO_RESTRICT __restrict__ /* Compatible with C90 */
|
||||
# elif defined(_MSC_VER)
|
||||
# define GMIO_RESTRICT __restrict
|
||||
# elif defined(GMIO_HAVE_C99_RESTRICT) /* TODO: add cmake detectection */
|
||||
# elif defined(GMIO_HAVE_C99_RESTRICT) /* TODO: add cmake detection */
|
||||
# define GMIO_RESTRICT restrict
|
||||
# else
|
||||
/*! Expands to the C compiler specific restrict keyword (if any) */
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "locale_utils.h"
|
||||
#include "../error.h"
|
||||
#include "../memblock.h"
|
||||
#include "../stream.h"
|
||||
|
||||
bool gmio_check_memblock(int *error, const struct gmio_memblock* mblock)
|
||||
{
|
||||
@ -56,3 +57,43 @@ bool gmio_check_lc_numeric(int *error)
|
||||
*error = GMIO_ERROR_BAD_LC_NUMERIC;
|
||||
return gmio_no_error(*error);
|
||||
}
|
||||
|
||||
bool gmio_check_istream(int *error, const struct gmio_stream *stream)
|
||||
{
|
||||
if (stream == NULL)
|
||||
*error = GMIO_ERROR_NULL_STREAM;
|
||||
else if (stream->func_at_end == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_error == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_read == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_size == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_get_pos == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_set_pos == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
return gmio_no_error(*error);
|
||||
}
|
||||
|
||||
bool gmio_check_ostream(int *error, const struct gmio_stream *stream)
|
||||
{
|
||||
if (stream == NULL)
|
||||
*error = GMIO_ERROR_NULL_STREAM;
|
||||
else if (stream->func_error == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_write == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_get_pos == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
else if (stream->func_set_pos == NULL)
|
||||
*error = GMIO_ERROR_STREAM_FUNC_REQUIRED;
|
||||
return gmio_no_error(*error);
|
||||
}
|
||||
|
||||
bool gmio_check_stream(int *error, const struct gmio_stream *stream)
|
||||
{
|
||||
return gmio_check_istream(error, stream)
|
||||
&& gmio_check_ostream(error, stream);
|
||||
}
|
||||
|
@ -32,12 +32,17 @@
|
||||
#include "../global.h"
|
||||
#include <stddef.h>
|
||||
struct gmio_memblock;
|
||||
struct gmio_stream;
|
||||
|
||||
bool gmio_check_memblock(
|
||||
int* error, const struct gmio_memblock* mblock);
|
||||
bool gmio_check_memblock_size(
|
||||
int* error, const struct gmio_memblock* mblock, size_t minsize);
|
||||
|
||||
/*! Checks gmio_lc_numeric_is_C(), if false sets \p *error to
|
||||
* \c GMIO_ERROR_BAD_LC_NUMERIC*/
|
||||
/* Checks gmio_lc_numeric_is_C()
|
||||
* If false sets *error to GMIO_ERROR_BAD_LC_NUMERIC */
|
||||
bool gmio_check_lc_numeric(int* error);
|
||||
|
||||
bool gmio_check_istream(int* error, const struct gmio_stream* stream);
|
||||
bool gmio_check_ostream(int* error, const struct gmio_stream* stream);
|
||||
bool gmio_check_stream(int* error, const struct gmio_stream* stream);
|
||||
|
@ -270,7 +270,7 @@ static const char* test_stla_write()
|
||||
{
|
||||
const char* model_filepath = filepath_stlb_grabcad_arm11;
|
||||
const char* model_filepath_out = "temp/solid.stla";
|
||||
struct gmio_stl_data data = {0}; /* TODO: fix memory leak on error */
|
||||
struct gmio_stl_data data = {0};
|
||||
char header_str[GMIO_STLB_HEADER_SIZE + 1] = {0};
|
||||
|
||||
/* Read input model file */
|
||||
|
Loading…
Reference in New Issue
Block a user