Skip to content

Commit

Permalink
libkvs/treeobj: code cleanup
Browse files Browse the repository at this point in the history
Use treeobj_unpack() where appropriate.
  • Loading branch information
chu11 committed Aug 21, 2017
1 parent 8259d70 commit a3cacf1
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/common/libkvs/treeobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,25 @@ json_t *treeobj_get_data (json_t *obj)

int treeobj_decode_val (json_t *obj, void **dp, int *lp)
{
int version;
const char *type, *xdata;
const char *type, *xdatastr;
json_t *xdata;
int len, xlen;
char *data;

if (json_unpack (obj, "{s:i s:s s:s}", "ver", &version,
"type", &type,
"data", &xdata) < 0
|| version != 1 || strcmp (type, "val") != 0) {
if (treeobj_unpack (obj, &type, &xdata) < 0
|| strcmp (type, "val") != 0) {
errno = EINVAL;
return -1;
}
xlen = strlen (xdata);
xdatastr = json_string_value (xdata);
xlen = strlen (xdatastr);
len = base64_decode_length (xlen);
if (len > 1) {
if (!(data = malloc (len))) {
errno = ENOMEM;
return -1;
}
if (base64_decode_block (data, &len, xdata, xlen) < 0) {
if (base64_decode_block (data, &len, xdatastr, xlen) < 0) {
free (data);
errno = EINVAL;
return -1;
Expand Down

0 comments on commit a3cacf1

Please sign in to comment.