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