Browse Source

Easier 64 bit safety in json_object_to_fd

Avoid any form of conversion issues between data types by using the
data types required by write(2) directly.
pull/661/head
Tobias Stoeckmann 5 years ago
parent
commit
31dcfead33
1 changed files with 4 additions and 5 deletions
  1. +4
    -5
      json_util.c

+ 4
- 5
json_util.c View File

@@ -185,9 +185,9 @@ int json_object_to_fd(int fd, struct json_object *obj, int flags)
}
static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const char *filename)
{
int ret;
ssize_t ret;
const char *json_str;
unsigned int wpos, wsize;
size_t wpos, wsize;

filename = filename ? filename : "(fd)";

@@ -196,8 +196,7 @@ static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const
return -1;
}

/* CAW: probably unnecessary, but the most 64bit safe */
wsize = (unsigned int)(strlen(json_str) & UINT_MAX);
wsize = strlen(json_str);
wpos = 0;
while (wpos < wsize)
{
@@ -209,7 +208,7 @@ static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const
}

/* because of the above check for ret < 0, we can safely cast and add */
wpos += (unsigned int)ret;
wpos += (size_t)ret;
}

return 0;


Loading…
Cancel
Save