data_create_empty with size 0 calls malloc(0) — undefined behavior per C standard #74

Closed
opened 2026-07-20 17:14:37 +02:00 by TapTap · 0 comments
Owner

Description

In line 6, calls :

When is 0, has implementation-defined behavior. Per the C11 standard (7.22.3), may return NULL or a unique pointer. If it returns NULL, the caller treats this as an allocation failure, even though requesting 0 bytes is valid.

Several callers pass 0 to :

  • (line 38): — this calls but sets and , so it's fine.
  • (line 60): where is calculated — could be 0 if chunk has 0 files.

Location

Suggested Fix

Use as a safe minimum when is 0:

Severity

Low

Category

Bug

## Description In line 6, calls : When is 0, has implementation-defined behavior. Per the C11 standard (7.22.3), may return NULL or a unique pointer. If it returns NULL, the caller treats this as an allocation failure, even though requesting 0 bytes is valid. Several callers pass 0 to : - (line 38): — this calls but sets and , so it's fine. - (line 60): where is calculated — could be 0 if chunk has 0 files. ## Location ## Suggested Fix Use as a safe minimum when is 0: ## Severity Low ## Category Bug
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#74