1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00

modify rc_open only if it is not a NULL pointer

This commit is contained in:
q-posev 2021-09-24 12:23:59 +02:00
parent 8ef0c1963f
commit 2e2dac3982

View File

@ -714,23 +714,21 @@ trexio_open(const char* file_name, const char mode,
{ {
if (file_name == NULL || file_name[0] == '\0') { if (file_name == NULL || file_name[0] == '\0') {
*rc_open = TREXIO_INVALID_ARG_1; if (rc_open != NULL) *rc_open = TREXIO_INVALID_ARG_1;
return NULL; return NULL;
} }
/* Check overflow in file_name */ /* Check overflow in file_name */
if (back_end < 0 || back_end >= TREXIO_INVALID_BACK_END) { if (back_end < 0 || back_end >= TREXIO_INVALID_BACK_END) {
*rc_open = TREXIO_INVALID_ARG_3; if (rc_open != NULL) *rc_open = TREXIO_INVALID_ARG_3;
return NULL; return NULL;
} }
if (mode != 'r' && mode != 'w') { if (mode != 'r' && mode != 'w') {
*rc_open = TREXIO_INVALID_ARG_2; if (rc_open != NULL) *rc_open = TREXIO_INVALID_ARG_2;
return NULL; return NULL;
} }
if (rc_open == NULL) return NULL;
trexio_t* result = NULL; trexio_t* result = NULL;
void* result_tmp = NULL; void* result_tmp = NULL;
@ -758,14 +756,14 @@ trexio_open(const char* file_name, const char mode,
strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH); strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH);
if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') {
*rc_open = TREXIO_INVALID_ARG_1; if (rc_open != NULL) *rc_open = TREXIO_INVALID_ARG_1;
free(result); free(result);
return NULL; return NULL;
} }
strncpy(result->version, PACKAGE_VERSION, 16); strncpy(result->version, PACKAGE_VERSION, 16);
if (result->version[15] != '\0') { if (result->version[15] != '\0') {
*rc_open = TREXIO_FAILURE; if (rc_open != NULL) *rc_open = TREXIO_FAILURE;
free(result); free(result);
return NULL; return NULL;
} }
@ -803,14 +801,14 @@ trexio_open(const char* file_name, const char mode,
} }
if (rc != TREXIO_SUCCESS) { if (rc != TREXIO_SUCCESS) {
*rc_open = TREXIO_OPEN_ERROR; if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result); free(result);
return NULL; return NULL;
} }
rc = trexio_has_metadata_package_version(result); rc = trexio_has_metadata_package_version(result);
if (rc == TREXIO_FAILURE) { if (rc == TREXIO_FAILURE) {
*rc_open = TREXIO_OPEN_ERROR; if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result); free(result);
return NULL; return NULL;
} }
@ -834,7 +832,7 @@ trexio_open(const char* file_name, const char mode,
} }
if (rc != TREXIO_SUCCESS) { if (rc != TREXIO_SUCCESS) {
*rc_open = TREXIO_OPEN_ERROR; if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result); free(result);
return NULL; return NULL;
} }
@ -861,12 +859,12 @@ trexio_open(const char* file_name, const char mode,
} }
if (rc != TREXIO_SUCCESS) { if (rc != TREXIO_SUCCESS) {
*rc_open = TREXIO_LOCK_ERROR; if (rc_open != NULL) *rc_open = TREXIO_LOCK_ERROR;
free(result); free(result);
return NULL; return NULL;
} }
*rc_open = TREXIO_SUCCESS; if (rc_open != NULL) *rc_open = TREXIO_SUCCESS;
return result; return result;
} }
#+end_src #+end_src