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

[native] 32bit conversion warning fix for gRPC C-Core #109

Merged
merged 1 commit into from
Jun 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ void XdsClusterResolverLb::OnEndpointChanged(size_t index,
mechanism.pending_priority_list->begin(),
mechanism.pending_priority_list->end());
priority_index += mechanism.num_priorities;
mechanism.num_priorities = mechanism.pending_priority_list->size();
mechanism.num_priorities = (uint32_t)(mechanism.pending_priority_list->size());
mechanism.pending_priority_list.reset();
} else {
priority_list.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void ChannelData::Destroy(grpc_channel_element* elem) {

ChannelData::ChannelData(grpc_channel_element* elem,
grpc_channel_element_args* args)
: index_(grpc_channel_stack_filter_instance_number(args->channel_stack,
: index_((int)grpc_channel_stack_filter_instance_number(args->channel_stack,
elem)) {}

// CallData::ResumeBatchCanceller
Expand Down
2 changes: 1 addition & 1 deletion native_src/src/core/ext/filters/rbac/rbac_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void RbacFilter::CallData::RecvInitialMetadataReady(void* user_data,
} else {
RbacFilter* chand = static_cast<RbacFilter*>(elem->channel_data);
auto* authorization_engine =
method_params->authorization_engine(chand->index_);
method_params->authorization_engine((int)(chand->index_));
if (authorization_engine
->Evaluate(EvaluateArgs(calld->recv_initial_metadata_,
&chand->per_channel_evaluate_args_))
Expand Down
4 changes: 2 additions & 2 deletions native_src/src/core/ext/transport/binder/wire_format/binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class WritableParcel {
virtual absl::Status WriteByteArray(const int8_t* buffer, int32_t length) = 0;

absl::Status WriteByteArrayWithLength(absl::string_view buffer) {
absl::Status status = WriteInt32(buffer.length());
absl::Status status = WriteInt32((int32_t)(buffer.length()));
if (!status.ok()) return status;
if (buffer.empty()) return absl::OkStatus();
return WriteByteArray(reinterpret_cast<const int8_t*>(buffer.data()),
buffer.length());
(int32_t)(buffer.length()));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ absl::Status WireWriterImpl::WriteInitialMetadata(const Transaction& tx,
// Only client sends method ref.
RETURN_IF_ERROR(parcel->WriteString(tx.GetMethodRef()));
}
RETURN_IF_ERROR(parcel->WriteInt32(tx.GetPrefixMetadata().size()));
RETURN_IF_ERROR(parcel->WriteInt32((int32_t)(tx.GetPrefixMetadata().size())));
for (const auto& md : tx.GetPrefixMetadata()) {
RETURN_IF_ERROR(parcel->WriteByteArrayWithLength(md.first));
RETURN_IF_ERROR(parcel->WriteByteArrayWithLength(md.second));
Expand All @@ -52,7 +52,7 @@ absl::Status WireWriterImpl::WriteTrailingMetadata(const Transaction& tx,
if (tx.GetFlags() & kFlagStatusDescription) {
RETURN_IF_ERROR(parcel->WriteString(tx.GetStatusDesc()));
}
RETURN_IF_ERROR(parcel->WriteInt32(tx.GetSuffixMetadata().size()));
RETURN_IF_ERROR(parcel->WriteInt32((int32_t)(tx.GetSuffixMetadata().size())));
for (const auto& md : tx.GetSuffixMetadata()) {
RETURN_IF_ERROR(parcel->WriteByteArrayWithLength(md.first));
RETURN_IF_ERROR(parcel->WriteByteArrayWithLength(md.second));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s,

size_t msg_len = message.length();
GPR_ASSERT(msg_len <= UINT32_MAX);
grpc_core::VarintWriter<1> msg_len_writer(msg_len);
grpc_core::VarintWriter<1> msg_len_writer((uint32_t)msg_len);
message_pfx = GRPC_SLICE_MALLOC(14 + msg_len_writer.length());
p = GRPC_SLICE_START_PTR(message_pfx);
*p++ = 0x00; /* literal header, not indexed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class BinaryStringValue {
explicit BinaryStringValue(Slice value, bool use_true_binary_metadata)
: wire_value_(
GetWireValue(std::move(value), use_true_binary_metadata, true)),
len_val_(wire_value_.length) {}
len_val_((uint32_t)(wire_value_.length)) {}

size_t prefix_length() const {
return len_val_.length() +
Expand All @@ -239,7 +239,7 @@ class BinaryStringValue {
class NonBinaryStringValue {
public:
explicit NonBinaryStringValue(Slice value)
: value_(std::move(value)), len_val_(value_.length()) {}
: value_(std::move(value)), len_val_((uint32_t)(value_.length())) {}

size_t prefix_length() const { return len_val_.length(); }

Expand All @@ -255,7 +255,7 @@ class NonBinaryStringValue {
class StringKey {
public:
explicit StringKey(Slice key)
: key_(std::move(key)), len_key_(key_.length()) {}
: key_(std::move(key)), len_key_((uint32_t)(key_.length())) {}

size_t prefix_length() const { return 1 + len_key_.length(); }

Expand Down Expand Up @@ -342,7 +342,7 @@ void HPackCompressor::SliceIndex::EmitTo(absl::string_view key,
using It = std::vector<ValueIndex>::iterator;
It prev = values_.end();
uint32_t transport_length =
key.length() + value.length() + hpack_constants::kEntryOverhead;
(uint32_t)(key.length() + value.length() + hpack_constants::kEntryOverhead);
if (transport_length > HPackEncoderTable::MaxEntrySize()) {
framer->EmitLitHdrWithNonBinaryStringKeyNotIdx(Slice::FromStaticString(key),
value.Ref());
Expand Down Expand Up @@ -567,7 +567,7 @@ void HPackCompressor::Framer::Encode(UserAgentMetadata, const Slice& slice) {
}
EncodeAlwaysIndexed(
&compressor_->user_agent_index_, "user-agent", slice.Ref(),
10 /* user-agent */ + slice.size() + hpack_constants::kEntryOverhead);
(uint32_t)(10 /* user-agent */ + slice.size() + hpack_constants::kEntryOverhead));
}

void HPackCompressor::Framer::Encode(GrpcStatusMetadata,
Expand All @@ -584,7 +584,7 @@ void HPackCompressor::Framer::Encode(GrpcStatusMetadata,
Slice key = Slice::FromStaticString(GrpcStatusMetadata::key());
Slice value = Slice::FromInt64(code);
const uint32_t transport_length =
key.length() + value.length() + hpack_constants::kEntryOverhead;
(uint32_t)(key.length() + value.length() + hpack_constants::kEntryOverhead);
if (index != nullptr) {
*index = compressor_->table_.AllocateIndex(transport_length);
EmitLitHdrWithNonBinaryStringKeyIncIdx(std::move(key), std::move(value));
Expand All @@ -606,7 +606,7 @@ void HPackCompressor::Framer::Encode(GrpcEncodingMetadata,
auto key = Slice::FromStaticString(GrpcEncodingMetadata::key());
auto encoded_value = GrpcEncodingMetadata::Encode(value);
uint32_t transport_length =
key.length() + encoded_value.length() + hpack_constants::kEntryOverhead;
(uint32_t)(key.length() + encoded_value.length() + hpack_constants::kEntryOverhead);
if (index != nullptr) {
*index = compressor_->table_.AllocateIndex(transport_length);
EmitLitHdrWithNonBinaryStringKeyIncIdx(std::move(key),
Expand All @@ -630,7 +630,7 @@ void HPackCompressor::Framer::Encode(GrpcAcceptEncodingMetadata,
auto key = Slice::FromStaticString(GrpcAcceptEncodingMetadata::key());
auto encoded_value = GrpcAcceptEncodingMetadata::Encode(value);
uint32_t transport_length =
key.length() + encoded_value.length() + hpack_constants::kEntryOverhead;
(uint32_t)(key.length() + encoded_value.length() + hpack_constants::kEntryOverhead);
compressor_->grpc_accept_encoding_index_ =
compressor_->table_.AllocateIndex(transport_length);
compressor_->grpc_accept_encoding_ = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool HPackEncoderTable::SetMaxSize(uint32_t max_table_size) {
hpack_constants::EntriesForBytes(max_table_size);
// TODO(ctiller): integrate with ResourceQuota to rebuild smaller when we can.
if (max_table_elems > elem_size_.size()) {
Rebuild(std::max(max_table_elems, 2 * elem_size_.size()));
Rebuild((uint32_t)(std::max(max_table_elems, 2 * elem_size_.size())));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ class HPackParser::Parser {
const auto transport_size = key_string.size() + value_slice.size() +
hpack_constants::kEntryOverhead;
return grpc_metadata_batch::Parse(
key->string_view(), std::move(value_slice), transport_size,
key->string_view(), std::move(value_slice), (uint32_t)transport_size,
[key_string](absl::string_view error, const Slice& value) {
ReportMetadataParseError(key_string, error, value.as_string_view());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ GPR_ATTRIBUTE_NOINLINE HPackTable::Memento MakeMemento(size_t i) {
auto sm = kStaticTable[i];
return grpc_metadata_batch::Parse(
sm.key, Slice::FromStaticString(sm.value),
strlen(sm.key) + strlen(sm.value) + hpack_constants::kEntryOverhead,
(uint32_t)(strlen(sm.key) + strlen(sm.value) + hpack_constants::kEntryOverhead),
[](absl::string_view, const Slice&) {
abort(); // not expecting to see this
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ FileWatcherCertificateProviderFactory::CreateCertificateProvider(
file_watcher_config->private_key_file(),
file_watcher_config->identity_cert_file(),
file_watcher_config->root_cert_file(),
file_watcher_config->refresh_interval_ms() / GPR_MS_PER_SEC);
(unsigned int)(file_watcher_config->refresh_interval_ms() / GPR_MS_PER_SEC));
}

void FileWatcherCertificateProviderInit() {
Expand Down
10 changes: 5 additions & 5 deletions native_src/src/core/lib/compression/compression_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CompressionAlgorithmSet CompressionAlgorithmSet::FromUint32(uint32_t value) {
CompressionAlgorithmSet set;
for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (value & (1u << i)) {
set.set_.set(i);
set.set_.set((int)i);
}
}
return set;
Expand Down Expand Up @@ -152,7 +152,7 @@ bool CompressionAlgorithmSet::IsSet(
grpc_compression_algorithm algorithm) const {
size_t i = static_cast<size_t>(algorithm);
if (i < GRPC_COMPRESS_ALGORITHMS_COUNT) {
return set_.is_set(i);
return set_.is_set((int)i);
} else {
return false;
}
Expand All @@ -161,14 +161,14 @@ bool CompressionAlgorithmSet::IsSet(
void CompressionAlgorithmSet::Set(grpc_compression_algorithm algorithm) {
size_t i = static_cast<size_t>(algorithm);
if (i < GRPC_COMPRESS_ALGORITHMS_COUNT) {
set_.set(i);
set_.set((int)i);
}
}

std::string CompressionAlgorithmSet::ToString() const {
absl::InlinedVector<const char*, GRPC_COMPRESS_ALGORITHMS_COUNT> segments;
for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (set_.is_set(i)) {
if (set_.is_set((int)i)) {
segments.push_back(CompressionAlgorithmAsString(
static_cast<grpc_compression_algorithm>(i)));
}
Expand Down Expand Up @@ -196,7 +196,7 @@ CompressionAlgorithmSet CompressionAlgorithmSet::FromString(
uint32_t CompressionAlgorithmSet::ToLegacyBitmask() const {
uint32_t x = 0;
for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (set_.is_set(i)) {
if (set_.is_set((int)i)) {
x |= (1u << i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion native_src/src/core/lib/gpr/time_precise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ gpr_cycle_counter gpr_get_cycle_counter() {
gpr_timespec gpr_cycle_counter_to_time(gpr_cycle_counter cycles) {
gpr_timespec ts;
ts.tv_sec = static_cast<int64_t>(cycles / GPR_US_PER_SEC);
ts.tv_nsec = static_cast<int64_t>((cycles - ts.tv_sec * GPR_US_PER_SEC) *
ts.tv_nsec = static_cast<int32_t>((cycles - ts.tv_sec * GPR_US_PER_SEC) *
GPR_NS_PER_US);
ts.clock_type = GPR_CLOCK_PRECISE;
return ts;
Expand Down
2 changes: 1 addition & 1 deletion native_src/src/core/lib/gprpp/status_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void StatusAddChild(absl::Status* status, absl::Status child) {
children = *old_children;
}
char head_buf[sizeof(uint32_t)];
EncodeUInt32ToBytes(buf_len, head_buf);
EncodeUInt32ToBytes((uint32_t)buf_len, head_buf);
children.Append(absl::string_view(head_buf, sizeof(uint32_t)));
children.Append(absl::string_view(buf, buf_len));
status->SetPayload(kChildrenPropertyUrl, std::move(children));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void ExternalAccountCredentials::OnImpersenateServiceAccountInternal(
"Invalid expire time of service account impersonation response."));
return;
}
int expire_in = (t - absl::Now()) / absl::Seconds(1);
int expire_in = (int)( (t - absl::Now()) / absl::Seconds(1) );
std::string body = absl::StrFormat(
"{\"access_token\":\"%s\",\"expires_in\":%d,\"token_type\":\"Bearer\"}",
access_token, expire_in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ absl::StatusOr<bool> PrivateKeyAndCertificateMatch(
if (cert_chain.empty()) {
return absl::InvalidArgumentError("Certificate string is empty.");
}
BIO* cert_bio = BIO_new_mem_buf(cert_chain.data(), cert_chain.size());
BIO* cert_bio = BIO_new_mem_buf(cert_chain.data(), (int)(cert_chain.size()));
if (cert_bio == nullptr) {
return absl::InvalidArgumentError(
"Conversion from certificate string to BIO failed.");
Expand All @@ -393,7 +393,7 @@ absl::StatusOr<bool> PrivateKeyAndCertificateMatch(
"Extraction of public key from x.509 certificate failed.");
}
BIO* private_key_bio =
BIO_new_mem_buf(private_key.data(), private_key.size());
BIO_new_mem_buf(private_key.data(), (int)(private_key.size()));
if (private_key_bio == nullptr) {
EVP_PKEY_free(public_evp_pkey);
return absl::InvalidArgumentError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool VerifySubjectAlternativeName(absl::string_view subject_alternative_name,
return false;
}
if (!absl::EndsWith(normalized_matcher, suffix)) return false;
int suffix_start_index = normalized_matcher.length() - suffix.length();
int suffix_start_index = (int)(normalized_matcher.length() - suffix.length());
// Asterisk matching across domain labels is not permitted.
return suffix_start_index <= 0 /* should not happen */ ||
normalized_matcher.find_last_of('.', suffix_start_index - 1) ==
Expand Down
2 changes: 1 addition & 1 deletion native_src/src/core/lib/transport/metadata_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class ParseHelper {
return ParsedMetadata<Container>(
trait,
ParseValueToMemento<typename Trait::MementoType, Trait::ParseMemento>(),
transport_size_);
(uint32_t)transport_size_);
}

GPR_ATTRIBUTE_NOINLINE ParsedMetadata<Container> NotFound(
Expand Down
4 changes: 2 additions & 2 deletions native_src/src/core/lib/transport/parsed_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ParsedMetadata {
// Construct metadata from a string key, slice value pair.
ParsedMetadata(Slice key, Slice value)
: vtable_(ParsedMetadata::KeyValueVTable(key.as_string_view())),
transport_size_(key.size() + value.size() + 32) {
transport_size_((uint32_t)(key.size() + value.size() + 32)) {
value_.pointer =
new std::pair<Slice, Slice>(std::move(key), std::move(value));
}
Expand Down Expand Up @@ -178,7 +178,7 @@ class ParsedMetadata {
result.vtable_ = vtable_;
result.value_ = value_;
result.transport_size_ =
TransportSize(vtable_->key(value_).length(), value.length());
TransportSize((uint32_t)(vtable_->key(value_).length()), (uint32_t)(value.length()));
vtable_->with_new_value(&value, on_error, &result);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ struct pcg_xsl_rr_128_64 {
uint64_t rotate = h >> 58u;
uint64_t s = Uint128Low64(state) ^ h;
#endif
return rotr(s, rotate);
return rotr(s, (int)rotate);
}
};

Expand Down
10 changes: 5 additions & 5 deletions native_src/third_party/re2/util/rune.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum
Bit2 = 5,
Bit3 = 4,
Bit4 = 3,
Bit5 = 2,
Bit5 = 2,

T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
Expand Down Expand Up @@ -76,7 +76,7 @@ chartorune(Rune *rune, const char *str)
l = ((c << Bitx) | c1) & Rune2;
if(l <= Rune1)
goto bad;
*rune = l;
*rune = (Rune)l;
return 2;
}

Expand All @@ -91,7 +91,7 @@ chartorune(Rune *rune, const char *str)
l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
if(l <= Rune2)
goto bad;
*rune = l;
*rune = (Rune)l;
return 3;
}

Expand All @@ -106,7 +106,7 @@ chartorune(Rune *rune, const char *str)
l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
if (l <= Rune3)
goto bad;
*rune = l;
*rune = (Rune)l;
return 4;
}

Expand Down Expand Up @@ -220,7 +220,7 @@ utflen(const char *s)
c = *(unsigned char*)s;
if(c < Runeself) {
if(c == 0)
return n;
return (int)n;
s++;
} else
s += chartorune(&rune, s);
Expand Down
Loading