summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-03-30 13:17:34 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-03-30 13:17:34 +0200
commit9aa7cd1d8d137bdb11f963af3e29ba4f421ab6b3 (patch)
tree2ca4abbddec6866be75fa51c4ed7368fadf020a1
parent2ed8914deed73a558c6fbac7f107f47dc22f22d2 (diff)
downloadouroboros-9aa7cd1d8d137bdb11f963af3e29ba4f421ab6b3.tar.gz
ouroboros-9aa7cd1d8d137bdb11f963af3e29ba4f421ab6b3.zip
lib: fixes for instance_name
fixes wrong check, checks now use lazy evaluation changed the order of instance_name_cpy to (dst, src)
-rw-r--r--include/ouroboros/instance_name.h4
-rw-r--r--src/lib/instance_name.c26
-rw-r--r--src/lib/irm.c27
3 files changed, 18 insertions, 39 deletions
diff --git a/include/ouroboros/instance_name.h b/include/ouroboros/instance_name.h
index b3e528c0..351b222f 100644
--- a/include/ouroboros/instance_name.h
+++ b/include/ouroboros/instance_name.h
@@ -72,8 +72,8 @@ instance_name_t * instance_name_dup(const instance_name_t * src);
* Copies the source object contents into the destination object, both must
* be previously allocated
*/
-int instance_name_cpy(const instance_name_t * src,
- instance_name_t * dst);
+int instance_name_cpy(instance_name_t * dst,
+ const instance_name_t * src);
int instance_name_cmp(const instance_name_t * a,
const instance_name_t * b);
diff --git a/src/lib/instance_name.c b/src/lib/instance_name.c
index 1e61f790..0f666211 100644
--- a/src/lib/instance_name.c
+++ b/src/lib/instance_name.c
@@ -86,7 +86,7 @@ instance_name_t * instance_name_init_from(instance_name_t * dst,
}
instance_name_t * instance_name_init_with(instance_name_t * dst,
- char * name,
+ char * name,
uint16_t id)
{
if (dst == NULL)
@@ -103,13 +103,11 @@ instance_name_t * instance_name_init_with(instance_name_t * dst,
void instance_name_fini(instance_name_t * n)
{
- if (n == NULL)
+ if (n == NULL || n->name == NULL)
return;
- if (n->name != NULL) {
- free(n->name);
- n->name = NULL;
- }
+ free(n->name);
+ n->name = NULL;
}
void instance_name_destroy(instance_name_t * ptr)
@@ -122,17 +120,15 @@ void instance_name_destroy(instance_name_t * ptr)
free(ptr);
}
-int instance_name_cpy(const instance_name_t * src,
- instance_name_t * dst)
+int instance_name_cpy(instance_name_t * dst,
+ const instance_name_t * src)
{
instance_name_t * res;
if (src == NULL || dst == NULL)
return -1;
- res = instance_name_init_from(dst,
- src->name,
- src->id);
+ res = instance_name_init_from(dst, src->name, src->id);
if (res == NULL)
return -1;
@@ -150,7 +146,7 @@ instance_name_t * instance_name_dup(const instance_name_t * src)
if (tmp == NULL)
return NULL;
- if (instance_name_cpy(src, tmp)) {
+ if (instance_name_cpy(tmp, src)) {
instance_name_destroy(tmp);
return NULL;
}
@@ -160,9 +156,7 @@ instance_name_t * instance_name_dup(const instance_name_t * src)
bool instance_name_is_valid(const instance_name_t * n)
{
- return (n != NULL &&
- n->name != NULL &&
- strlen(n->name));
+ return (n != NULL && n->name != NULL && strlen(n->name));
}
int instance_name_cmp(const instance_name_t * a,
@@ -205,7 +199,7 @@ char * instance_name_to_string(const instance_name_t * n)
if (n == NULL)
return NULL;
- size = 0;
+ size = 0;
size += (n->name != NULL ?
strlen(n->name) : none_len);
diff --git a/src/lib/irm.c b/src/lib/irm.c
index af899d0a..644e1113 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -35,10 +35,7 @@ int irm_create_ipcp(instance_name_t * api,
{
irm_msg_t msg = IRM_MSG__INIT;
- if (api == NULL)
- return -EINVAL;
-
- if (ipcp_type == NULL || api == NULL)
+ if (api == NULL || ipcp_type == NULL || api->name == NULL)
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
@@ -59,12 +56,8 @@ int irm_destroy_ipcp(instance_name_t * api)
{
irm_msg_t msg = IRM_MSG__INIT;
- if (api == NULL)
- return -EINVAL;
-
- if (api->name == NULL) {
+ if (api == NULL || api->name == NULL)
return -EINVAL;
- }
msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP;
msg.ap_name = api->name;
@@ -84,10 +77,7 @@ int irm_bootstrap_ipcp(instance_name_t * api,
{
irm_msg_t msg = IRM_MSG__INIT;
- if (api == NULL)
- return -EINVAL;
-
- if (api->name == NULL || conf == NULL)
+ if (api == NULL || api->name == NULL || conf == NULL)
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP;
@@ -108,10 +98,7 @@ int irm_enroll_ipcp(instance_name_t * api,
{
irm_msg_t msg = IRM_MSG__INIT;
- if (api == NULL)
- return -EINVAL;
-
- if (api->name == NULL || dif_name == NULL)
+ if (api == NULL || api->name == NULL || dif_name == NULL)
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP;
@@ -171,10 +158,8 @@ int irm_unreg_ipcp(const instance_name_t * api,
{
irm_msg_t msg = IRM_MSG__INIT;
- if (api == NULL)
- return -EINVAL;
-
- if (api->name == NULL ||
+ if (api == NULL ||
+ api->name == NULL ||
difs == NULL ||
difs_size == 0 ||
difs[0] == NULL) {