Render an array to text */
| 1241 | |
| 1242 | /* Render an array to text */ |
| 1243 | static unsigned char *print_array(const cJSON *item, size_t depth, cjbool fmt, printbuffer *p) |
| 1244 | { |
| 1245 | unsigned char **entries; |
| 1246 | unsigned char *out = NULL; |
| 1247 | unsigned char *ptr = NULL; |
| 1248 | unsigned char *ret = NULL; |
| 1249 | size_t len = 5; |
| 1250 | cJSON *child = item->child; |
| 1251 | size_t numentries = 0; |
| 1252 | size_t i = 0; |
| 1253 | cjbool fail = false; |
| 1254 | size_t tmplen = 0; |
| 1255 | |
| 1256 | /* How many entries in the array? */ |
| 1257 | while (child) |
| 1258 | { |
| 1259 | numentries++; |
| 1260 | child = child->next; |
| 1261 | } |
| 1262 | |
| 1263 | /* Explicitly handle numentries == 0 */ |
| 1264 | if (!numentries) |
| 1265 | { |
| 1266 | if (p) |
| 1267 | { |
| 1268 | out = ensure(p, 3); |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | out = (unsigned char*)cJSON_malloc(3); |
| 1273 | } |
| 1274 | if (out) |
| 1275 | { |
| 1276 | strcpy((char*)out, "[]"); |
| 1277 | } |
| 1278 | |
| 1279 | return out; |
| 1280 | } |
| 1281 | |
| 1282 | if (p) |
| 1283 | { |
| 1284 | /* Compose the output array. */ |
| 1285 | /* opening square bracket */ |
| 1286 | i = p->offset; |
| 1287 | ptr = ensure(p, 1); |
| 1288 | if (!ptr) |
| 1289 | { |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | *ptr = '['; |
| 1293 | p->offset++; |
| 1294 | |
| 1295 | child = item->child; |
| 1296 | while (child && !fail) |
| 1297 | { |
| 1298 | if (!print_value(child, depth + 1, fmt, p)) |
| 1299 | { |
| 1300 | return NULL; |
no test coverage detected