From 7b22e48fbf23d20d92a4bae581f39ac3704d8bb2 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 28 Jan 2016 01:14:04 +0000 Subject: [PATCH] Change odhcp6c_insert_state to return a success/failure indicator Some callers will need to free resources on failure. Signed-off-by: Ben Hutchings --- src/odhcp6c.c | 6 ++++-- src/odhcp6c.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 133ade7..1714d62 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -516,11 +516,11 @@ void odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len) memcpy(n, data, len); } -void odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len) +int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len) { ssize_t len_after = state_len[state] - offset; if (len_after < 0) - return; + return -1; uint8_t *n = odhcp6c_resize_state(state, len); if (n) { @@ -529,6 +529,8 @@ void odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *d memmove(sdata + offset + len, sdata + offset, len_after); memcpy(sdata + offset, data, len); } + + return 0; } size_t odhcp6c_remove_state(enum odhcp6c_state state, size_t offset, size_t len) diff --git a/src/odhcp6c.h b/src/odhcp6c.h index d202790..928f82f 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -335,7 +335,7 @@ bool odhcp6c_is_bound(void); void odhcp6c_clear_state(enum odhcp6c_state state); void odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len); void odhcp6c_append_state(enum odhcp6c_state state, const void *data, size_t len); -void odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len); +int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len); size_t odhcp6c_remove_state(enum odhcp6c_state state, size_t offset, size_t len); void* odhcp6c_move_state(enum odhcp6c_state state, size_t *len); void* odhcp6c_get_state(enum odhcp6c_state state, size_t *len); -- 2.39.5