Skip to content

Commit

Permalink
use std::make_unique() for out-of-bound read test and exception safety (
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-topnotch authored Mar 13, 2024
1 parent 4de2f19 commit 009f2f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,11 @@ minio::s3::PutObjectResponse minio::s3::Client::PutObject(PutObjectArgs args) {
"SSE operation must be performed over a secure connection");
}

char* buf = NULL;
if (args.part_count > 0) {
buf = new char[args.part_size];
} else {
buf = new char[args.part_size + 1];
}

std::string upload_id;
PutObjectResponse resp = PutObject(args, upload_id, buf);
delete[] buf;
auto buf = std::make_unique<char[]>(
(args.part_count > 0) ? args.part_size : args.part_size + 1);
PutObjectResponse resp = PutObject(args, upload_id, buf.get());
buf.reset();

if (!resp && !upload_id.empty()) {
AbortMultipartUploadArgs amu_args;
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class RandomBuf : public std::streambuf {
if (size_ == 0) return EOF;

size_t size = std::min<size_t>(size_, buf_.size());
setg(&buf_[0], &buf_[0], &buf_[size]);
auto* const data = buf_.data();
setg(data, data, data + size);
for (size_t i = 0; i < size; ++i) buf_[i] = charset[pick(rg)];
size_ -= size;
return 0;
Expand Down

0 comments on commit 009f2f5

Please sign in to comment.