mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 20:31:11 +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,
|
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
|
||||||
const char *template_string) = 0;
|
const char *template_string) = 0;
|
||||||
virtual void Print(const char *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 Indent() = 0;
|
||||||
virtual void Outdent() = 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());
|
FLATBUFFERS_ASSERT(str_->empty());
|
||||||
indentation_size_ = size;
|
indentation_size_ = size;
|
||||||
}
|
}
|
||||||
@@ -199,15 +199,15 @@ class FlatBufPrinter : public grpc_generator::Printer {
|
|||||||
void Indent() { indent_++; }
|
void Indent() { indent_++; }
|
||||||
|
|
||||||
void Outdent() {
|
void Outdent() {
|
||||||
|
FLATBUFFERS_ASSERT(indent_ > 0);
|
||||||
indent_--;
|
indent_--;
|
||||||
FLATBUFFERS_ASSERT(indent_ >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string *str_;
|
std::string *str_;
|
||||||
char escape_char_;
|
char escape_char_;
|
||||||
int indent_;
|
size_t indent_;
|
||||||
int indentation_size_;
|
size_t indentation_size_;
|
||||||
char indentation_type_;
|
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 delta_bytes = delta_elem * static_cast<int>(elem_size);
|
||||||
auto vec_start =
|
auto vec_start =
|
||||||
reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
|
reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
|
||||||
auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
|
auto start = static_cast<uoffset_t>(vec_start) +
|
||||||
elem_size * num_elems);
|
static_cast<uoffset_t>(sizeof(uoffset_t)) +
|
||||||
|
elem_size * num_elems;
|
||||||
if (delta_bytes) {
|
if (delta_bytes) {
|
||||||
if (delta_elem < 0) {
|
if (delta_elem < 0) {
|
||||||
// Clear elements we're throwing away, since some might remain in the
|
// 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.
|
WriteScalar(flatbuf->data() + vec_start, newsize); // Length field.
|
||||||
// Set new elements to 0.. this can be overwritten by the caller.
|
// Set new elements to 0.. this can be overwritten by the caller.
|
||||||
if (delta_elem > 0) {
|
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;
|
return flatbuf->data() + start;
|
||||||
|
|||||||
Reference in New Issue
Block a user