Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Build warning - cast from pointer to integer of different size #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions json.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/

#define JSON_PRIVATE_API
#include "json.h"

#ifdef _MSC_VER
Expand Down Expand Up @@ -150,8 +151,10 @@ static int new_value (json_state * state,
if (value->u.array.length == 0)
break;

values_size = sizeof (json_value *) * value->u.array.length;

if (! (value->u.array.values = (json_value **) json_alloc
(state, value->u.array.length * sizeof (json_value *), 0)) )
(state, values_size, 0)) )
{
return 0;
}
Expand All @@ -164,27 +167,23 @@ static int new_value (json_state * state,
if (value->u.object.length == 0)
break;

values_size = sizeof (*value->u.object.values) * value->u.object.length;
values_size = sizeof (json_object_entry *) * value->u.object.length;

if (! (value->u.object.values = (json_object_entry *) json_alloc
#ifdef UINTPTR_MAX
(state, values_size + ((uintptr_t) value->u.object.values), 0)) )
#else
(state, values_size + ((size_t) value->u.object.values), 0)) )
#endif
if (! (value->u.object._u.values = (json_object_entry *) json_alloc
(state, values_size + value->u.object._u._length, 0)) )
{
return 0;
}

value->_reserved.object_mem = (*(char **) &value->u.object.values) + values_size;
value->_reserved.object_mem = (*(char **) &value->u.object._u.values) + values_size;

value->u.object.length = 0;
break;

case json_string:

if (! (value->u.string.ptr = (json_char *) json_alloc
(state, (value->u.string.length + 1) * sizeof (json_char), 0)) )
(state, sizeof (json_char) * (value->u.string.length + 1), 0)) )
{
return 0;
}
Expand Down Expand Up @@ -433,13 +432,13 @@ json_value * json_parse_ex (json_settings * settings,
case json_object:

if (state.first_pass)
(*(json_char **) &top->u.object.values) += string_length + 1;
top->u.object._u._length += string_length + 1;
else
{
top->u.object.values [top->u.object.length].name
top->u.object._u.values [top->u.object.length].name
= (json_char *) top->_reserved.object_mem;

top->u.object.values [top->u.object.length].name_length
top->u.object._u.values [top->u.object.length].name_length
= string_length;

(*(json_char **) &top->_reserved.object_mem) += string_length + 1;
Expand Down Expand Up @@ -919,7 +918,7 @@ json_value * json_parse_ex (json_settings * settings,
{
case json_object:

parent->u.object.values
parent->u.object._u.values
[parent->u.object.length].value = top;

break;
Expand Down Expand Up @@ -1025,11 +1024,11 @@ void json_value_free_ex (json_settings * settings, json_value * value)

if (!value->u.object.length)
{
settings->mem_free (value->u.object.values, settings->user_data);
settings->mem_free (value->u.object._u.values, settings->user_data);
break;
}

value = value->u.object.values [-- value->u.object.length].value;
value = value->u.object._u.values [-- value->u.object.length].value;
continue;

case json_string:
Expand Down
30 changes: 28 additions & 2 deletions json.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,35 @@ typedef struct _json_value
{
unsigned int length;

#ifdef JSON_PRIVATE_API
union
{
json_object_entry * values;
unsigned int _length;

} _u;
#else
json_object_entry * values;
#endif

#if defined(__cplusplus)
json_object_entry * begin () const
{ return values;
{
#ifdef JSON_PRIVATE_API
return _u.values;
#else
return values;
#endif

}
json_object_entry * end () const
{ return values + length;
{
#ifdef JSON_PRIVATE_API
return _u.values + length;
#else
return values + length;
#endif

}
#endif

Expand Down Expand Up @@ -202,8 +223,13 @@ typedef struct _json_value
return json_value_none;

for (unsigned int i = 0; i < u.object.length; ++ i)
#ifdef JSON_PRIVATE_API
if (!strcmp (u.object._u.values [i].name, index))
return *u.object._u.values [i].value;
#else
if (!strcmp (u.object.values [i].name, index))
return *u.object.values [i].value;
#endif

return json_value_none;
}
Expand Down