Skip to content

api: replace 'long object_size = -1' sentinel with std::optional<uint64_t> #224

@harshavardhana

Description

@harshavardhana

Problem

`PutObjectBaseArgs` uses a signed `long` with `-1` as the "unknown" sentinel:

```cpp
// include/miniocpp/args.h:151
struct PutObjectBaseArgs : public ObjectWriteArgs {
long object_size = -1;
size_t part_size = 0;
long part_count = 0;
...
};
```

And the implementation has signed/unsigned juggling: `utils::CalcPartInfo(long object_size, size_t& part_size, long& part_count)` at `src/args.cc:114`.

Suggested approach

```cpp
std::optional<uint64_t> object_size;
size_t part_size = 0;
size_t part_count = 0;
```

Update validators and `CalcPartInfo` to take `std::optional<uint64_t>` and operate on unsigned consistently.

Impact

Medium — kills a signed/unsigned hazard and an "unknown" sentinel that's silently treated as a real value in any code path that forgets to check.

Roadmap

Tier 3 item from the C++ modernization audit. Pairs with #223 (size_t* sentinels).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions