commit b4973869cbb836d5f9c21c6a1645e6346609620f
parent dc1cb16ef8e2e78d9287a9b727133170ef3321bc
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Thu, 6 Feb 2025 16:41:41 +0100
Refactor condition checks for consistency
Updated old condition checks to keep a consistent coding style by using
constant on the left (yoda conditions checking) in comparisons
Diffstat:
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/sphin.c b/src/sphin.c
@@ -35,7 +35,7 @@ static res_T
check_sphin_create_args
(const struct sphin_create_args* args)
{
- if (args == NULL) {
+ if (NULL == args) {
return RES_BAD_ARG;
}
return RES_OK;
@@ -51,7 +51,7 @@ release_sphin
| logger | verbose | allocator | ref |
+--------+---------+-----------+-----+ */
struct sphin* sphin = NULL;
- ASSERT(address != NULL);
+ ASSERT(NULL != address);
sphin = CONTAINER_OF(address, struct sphin, ref);
MEM_RM(sphin->allocator, sphin);
@@ -74,33 +74,33 @@ sphin_create
goto error;
}
res = check_sphin_create_args(args);
- if (res != RES_OK) goto error;
+ if (RES_OK != res) goto error;
- if (args->allocator == NULL) {
+ if (NULL == args->allocator) {
allocator = &mem_default_allocator;
} else {
allocator = args->allocator;
}
sphin = MEM_CALLOC(allocator, 1, sizeof(struct sphin));
- if (sphin == NULL) {
+ if (NULL == sphin) {
res = RES_MEM_ERR;
goto error;
}
ref_init(&sphin->ref);
sphin->verbose = args->verbose;
sphin->allocator = allocator;
- if (args->logger == NULL) {
+ if (NULL == args->logger) {
sphin->logger = LOGGER_DEFAULT;
} else {
sphin->logger = args->logger;
}
exit:
- if (out_sphin != NULL) *out_sphin = sphin;
+ if (NULL != out_sphin) *out_sphin = sphin;
return res;
error:
- if (sphin != NULL) {
+ if (NULL != sphin) {
SPHIN(ref_put(sphin)); /* <=> ASSERT(sphin_ref_put(sphin) == RES_OK) */
sphin = NULL;
}
@@ -111,7 +111,7 @@ res_T
sphin_ref_get
(struct sphin* sphin)
{
- if (sphin == NULL) {
+ if (NULL == sphin) {
return RES_BAD_ARG;
}
ref_get(&sphin->ref);
@@ -122,7 +122,7 @@ res_T
sphin_ref_put
(struct sphin* sphin)
{
- if (sphin == NULL) {
+ if (NULL == sphin) {
return RES_BAD_ARG;
}
ref_put(&sphin->ref, release_sphin);
diff --git a/src/sphin_config.c b/src/sphin_config.c
@@ -108,23 +108,23 @@ load_stream
str_init(sphin->allocator, &line);
res = config_create(sphin, &config);
- if (res != RES_OK) {
+ if (RES_OK != res) {
goto error;
}
res = txtrdr_stream(sphin->allocator, stream, streamname, '#', &txtrdr);
- if (res != RES_OK) {
+ if (RES_OK != res) {
goto error;
}
res = txtrdr_read_line(txtrdr);
- if (res != RES_OK) {
+ if (RES_OK != res) {
goto error;
}
while (NULL != txtrdr_get_line(txtrdr)) {
res = str_set(&line, txtrdr_get_cline(txtrdr));
- if (res != RES_OK) {
+ if (RES_OK != res) {
goto error;
}
@@ -159,7 +159,7 @@ load_stream
else {
res = RES_BAD_ARG;
}
- if (res != RES_OK) {
+ if (RES_OK != res) {
ERROR
(sphin,
"%s: %lu: Bad keyword\n",
@@ -267,7 +267,7 @@ sphin_load
}
stream = fopen(filename, "r");
- if (stream == NULL) {
+ if (NULL == stream) {
ERROR(sphin, "Not possible to open file %s -- %s\n",
filename, strerror(errno));
res = RES_IO_ERR;
@@ -275,12 +275,12 @@ sphin_load
}
res = load_stream(sphin, stream, filename, config);
- if (res != RES_OK) {
+ if (RES_OK != res) {
goto error;
}
exit:
- if (stream != NULL) {
+ if (NULL != stream) {
fclose(stream);
}
return res;