Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starboard/types.h: Replace kSbInt32Max with std::numeric_limits equivalents #4187

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions starboard/shared/posix/storage_write_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <fcntl.h>

#include <algorithm>
#include <limits>
#include <vector>

#include "starboard/common/file.h"
Expand Down Expand Up @@ -57,8 +58,8 @@ bool SbStorageWriteRecord(SbStorageRecord record,
const char* source = data;
int64_t to_write = data_size;
while (to_write > 0) {
int to_write_max =
static_cast<int>(std::min(to_write, static_cast<int64_t>(kSbInt32Max)));
int to_write_max = static_cast<int>(std::min(
to_write, static_cast<int64_t>(std::numeric_limits<int32_t>::max())));
int bytes_written = write(temp_file, source, to_write_max);
if (bytes_written < 0) {
close(temp_file);
Expand Down
5 changes: 3 additions & 2 deletions starboard/shared/starboard/file_atomic_replace_write_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <unistd.h>

#include <algorithm>
#include <limits>

#include "starboard/common/file.h"
#include "starboard/common/log.h"
Expand All @@ -42,8 +43,8 @@ bool SbFileAtomicReplaceWriteFile(const char* path,
int64_t to_write = data_size;

while (to_write > 0) {
const int to_write_max =
static_cast<int>(std::min(to_write, static_cast<int64_t>(kSbInt32Max)));
const int to_write_max = static_cast<int>(std::min(
to_write, static_cast<int64_t>(std::numeric_limits<int32_t>::max())));
const int bytes_written = write(temp_file, source, to_write_max);
RecordFileWriteStat(bytes_written);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <unistd.h>

#include <algorithm>
#include <limits>

#include "starboard/common/file.h"
#include "starboard/common/log.h"
Expand Down Expand Up @@ -47,8 +48,8 @@ int64_t SbStorageReadRecord(SbStorageRecord record,
char* destination = out_data;
int64_t to_read = total;
while (to_read > 0) {
int to_read_max =
static_cast<int>(std::min(to_read, static_cast<int64_t>(kSbInt32Max)));
int to_read_max = static_cast<int>(std::min(
to_read, static_cast<int64_t>(std::numeric_limits<int32_t>::max())));
int bytes_read = read(record->file, destination, to_read_max);
if (bytes_read < 0) {
return -1;
Expand Down
4 changes: 3 additions & 1 deletion starboard/shared/starboard/localized_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "starboard/shared/starboard/localized_strings.h"

#include <algorithm>
#include <limits>

#include "starboard/common/file.h"
#include "starboard/common/log.h"
Expand Down Expand Up @@ -71,7 +72,8 @@ bool ReadFile(const std::string& filename, std::string* out_result) {
char* buffer_pos = buffer;
while (bytes_to_read > 0) {
int max_bytes_to_read = static_cast<int>(
std::min(static_cast<int64_t>(kSbInt32Max), bytes_to_read));
std::min(static_cast<int64_t>(std::numeric_limits<int32_t>::max()),
bytes_to_read));
int bytes_read = file.Read(buffer_pos, max_bytes_to_read);
if (bytes_read < 0) {
SB_DLOG(ERROR) << "Read from i18n file failed.";
Expand Down
6 changes: 1 addition & 5 deletions starboard/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ typedef int64_t ssize_t;

// Simulate needed portions of limits.h for platforms that don't provide it.

#define kSbInt32Min ((int32_t)0x80000000)
static const int32_t kSbInt32Max = ((int32_t)0x7FFFFFFF);
static const uint32_t kSbUInt32Max = ((uint32_t)0xFFFFFFFF);

static const int64_t kSbInt64Min = ((int64_t)SB_INT64_C(0x8000000000000000));
static const int64_t kSbInt64Max = ((int64_t)SB_INT64_C(0x7FFFFFFFFFFFFFFF));
static const uint64_t kSbUInt64Max = ((uint64_t)SB_INT64_C(0xFFFFFFFFFFFFFFFF));

// A value that represents an int that is probably invalid.
#define kSbInvalidInt kSbInt32Min
#define kSbInvalidInt INT32_MIN

// --- Standard Include Emulation Audits ---------------------------------------

Expand Down
Loading