MCPcopy Create free account
hub / github.com/cppla/ServerStatus / new_value

Function new_value

server/src/json.c:103–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103static int new_value
104 (json_state * state, json_value ** top, json_value ** root, json_value ** alloc, json_type type)
105{
106 json_value * value;
107 int values_size;
108
109 if (!state->first_pass)
110 {
111 value = *top = *alloc;
112 *alloc = (*alloc)->_reserved.next_alloc;
113
114 if (!*root)
115 *root = value;
116
117 switch (value->type)
118 {
119 case json_array:
120
121 if (! (value->u.array.values = (json_value **) json_alloc
122 (state, value->u.array.length * sizeof (json_value *), 0)) )
123 {
124 return 0;
125 }
126
127 value->u.array.length = 0;
128 break;
129
130 case json_object:
131
132 values_size = sizeof (*value->u.object.values) * value->u.object.length;
133
134 void *tmp_alloc = json_alloc(state, values_size + ((unsigned long) value->u.object.values), 0);
135 if (!tmp_alloc)
136 {
137 return 0;
138 }
139 /* 避免违反严格别名:通过中间变量复制 */
140 memcpy(&value->u.object.values, &tmp_alloc, sizeof(void*));
141 char *obj_mem = (char*)value->u.object.values + values_size;
142 memcpy(&value->_reserved.object_mem, &obj_mem, sizeof(char*));
143
144 value->u.object.length = 0;
145 break;
146
147 case json_string:
148
149 if (! (value->u.string.ptr = (json_char *) json_alloc
150 (state, (value->u.string.length + 1) * sizeof (json_char), 0)) )
151 {
152 return 0;
153 }
154
155 value->u.string.length = 0;
156 break;
157
158 default:
159 break;
160 };

Callers 1

json_parse_exFunction · 0.85

Calls 1

json_allocFunction · 0.85

Tested by

no test coverage detected