coverity Scan the Code Results
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Locate the print(...) function shown in the issue and inspect its failure path around Coverity CID 5543771. Confirm why printed is checked after the allocation and cleanup branches, then run the repository's available tests or static analysis to verify the dead-code finding is resolved without changing normal cleanup behavior.
Written by the indexing model from the issue text.
Description
34static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
1235{
1236 static const size_t default_buffer_size = 256;
1237 printbuffer buffer[1];
assignment: 赋值:printed = NULL。
1238 unsigned char *printed = NULL;
1239
1240 memset(buffer, 0, sizeof(buffer));
1241
1242 /* create buffer */
1243 buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size);
1244 buffer->length = default_buffer_size;
1245 buffer->format = format;
1246 buffer->hooks = *hooks;
1247 if (buffer->buffer == NULL)
1248 {
1249 goto fail;
1250 }
1251
1252 /* print the value */
1253 if (!print_value(item, buffer))
1254 {
1255 goto fail;
1256 }
1257 update_offset(buffer);
1258
1259 /* check if reallocate is available */
1260 if (hooks->reallocate != NULL)
1261 {
1262 printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
1263 if (printed == NULL) {
1264 goto fail;
1265 }
1266 buffer->buffer = NULL;
1267 }
1268 else /* otherwise copy the JSON over to a new buffer */
1269 {
1270 printed = (unsigned char*) hooks->allocate(buffer->offset + 1);
1271 if (printed == NULL)
1272 {
1273 goto fail;
1274 }
1275 memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
1276 printed[buffer->offset] = '\0'; /* just to be sure */
1277
1278 /* free the buffer */
1279 hooks->deallocate(buffer->buffer);
1280 buffer->buffer = NULL;
1281 }
1282
1283 return printed;
1284
1285fail:
1286 if (buffer->buffer != NULL)
1287 {
1288 hooks->deallocate(buffer->buffer);
1289 buffer->buffer = NULL;
1290 }
1291
null: 在条件 printed != NULL 下,printed 的值必须为 NULL。
dead_error_condition: 条件 printed != NULL 不可能为 true。
1292 if (printed != NULL)
1293 {
CID 5543771: (#1 of 1): 逻辑死代码 (DEADCODE)
dead_error_begin: 执行无法到达此语句:hooks->deallocate(printed);。
1294 hooks->deallocate(printed);
1295 printed = NULL;
1296 }
1297
1298 return NULL;
1299}
- Dominant language
- C
- Stars
- 13k
- Forks
- 3.5k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DaveGamble/cJSON
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
DaveGamble/cJSON#1082 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
DaveGamble/cJSON#1081 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
DaveGamble/cJSON#1074 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
DaveGamble/cJSON#1071 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
DaveGamble/cJSON#1050 · 1 comment ·
All issues in DaveGamble/cJSON
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100