mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Fix integer overflow warnings
This commit is contained in:
@@ -93,7 +93,7 @@ struct Printer {
|
||||
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
|
||||
const char *template_string) = 0;
|
||||
virtual void Print(const char *string) = 0;
|
||||
virtual void SetIndentationSize(const int size) = 0;
|
||||
virtual void SetIndentationSize(const size_t size) = 0;
|
||||
virtual void Indent() = 0;
|
||||
virtual void Outdent() = 0;
|
||||
};
|
||||
|
||||
@@ -191,7 +191,7 @@ class FlatBufPrinter : public grpc_generator::Printer {
|
||||
}
|
||||
}
|
||||
|
||||
void SetIndentationSize(const int size) {
|
||||
void SetIndentationSize(const size_t size) {
|
||||
FLATBUFFERS_ASSERT(str_->empty());
|
||||
indentation_size_ = size;
|
||||
}
|
||||
@@ -199,15 +199,15 @@ class FlatBufPrinter : public grpc_generator::Printer {
|
||||
void Indent() { indent_++; }
|
||||
|
||||
void Outdent() {
|
||||
FLATBUFFERS_ASSERT(indent_ > 0);
|
||||
indent_--;
|
||||
FLATBUFFERS_ASSERT(indent_ >= 0);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string *str_;
|
||||
char escape_char_;
|
||||
int indent_;
|
||||
int indentation_size_;
|
||||
size_t indent_;
|
||||
size_t indentation_size_;
|
||||
char indentation_type_;
|
||||
};
|
||||
|
||||
|
||||
@@ -332,8 +332,9 @@ uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
|
||||
auto delta_bytes = delta_elem * static_cast<int>(elem_size);
|
||||
auto vec_start =
|
||||
reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
|
||||
auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
|
||||
elem_size * num_elems);
|
||||
auto start = static_cast<uoffset_t>(vec_start) +
|
||||
static_cast<uoffset_t>(sizeof(uoffset_t)) +
|
||||
elem_size * num_elems;
|
||||
if (delta_bytes) {
|
||||
if (delta_elem < 0) {
|
||||
// Clear elements we're throwing away, since some might remain in the
|
||||
@@ -345,7 +346,8 @@ uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
|
||||
WriteScalar(flatbuf->data() + vec_start, newsize); // Length field.
|
||||
// Set new elements to 0.. this can be overwritten by the caller.
|
||||
if (delta_elem > 0) {
|
||||
memset(flatbuf->data() + start, 0, delta_elem * elem_size);
|
||||
memset(flatbuf->data() + start, 0,
|
||||
static_cast<size_t>(delta_elem) * elem_size);
|
||||
}
|
||||
}
|
||||
return flatbuf->data() + start;
|
||||
|
||||
Reference in New Issue
Block a user