| 196 | } |
| 197 | |
| 198 | static char *print_int(cJSON *item) |
| 199 | { |
| 200 | char *str; |
| 201 | str = (char*) cJSON_malloc(22); /* 2^64+1 can be represented in 21 chars. */ |
| 202 | if (str) |
| 203 | { |
| 204 | if (item->sign == -1) |
| 205 | { |
| 206 | if ((int64)item->valueint <= (int64)INT_MAX && (int64)item->valueint >= (int64)INT_MIN) |
| 207 | { |
| 208 | sprintf(str, "%d", (int32)item->valueint); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | sprintf(str, "%ld", (int64)item->valueint); |
| 213 | } |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | if (item->valueint <= (uint64)UINT_MAX) |
| 218 | { |
| 219 | sprintf(str, "%u", (uint32)item->valueint); |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | sprintf(str, "%lu", item->valueint); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | return str; |
| 228 | } |
| 229 | |
| 230 | /* Parse the input text into an unescaped cstring, and populate item. */ |
| 231 | static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, |