X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gold%2Fattributes.cc;h=d31aac306be00225a5eedfda7bb4cd8e7520ec7b;hb=196535a69c8568342e62fdf5e3f5ade04470fd6a;hp=7d82979d148ddde19ba4df7de271e62feec6942e;hpb=b0eec2ccdafc32f2d0d82d8582fe28d91ea5a679;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/attributes.cc b/gold/attributes.cc index 7d82979d14..d31aac306b 100644 --- a/gold/attributes.cc +++ b/gold/attributes.cc @@ -1,6 +1,6 @@ // attributes.cc -- object attributes for gold -// Copyright 2009 Free Software Foundation, Inc. +// Copyright (C) 2009-2020 Free Software Foundation, Inc. // Written by Doug Kwan . // This file contains code adapted from BFD. @@ -45,12 +45,12 @@ Object_attribute::size(int tag) const if (this->is_default_attribute()) return 0; - size_t uleb128_size = get_length_as_unsigned_LEB_128(tag); + size_t size = get_length_as_unsigned_LEB_128(tag); if (Object_attribute::attribute_type_has_int_value(this->type_)) - uleb128_size += get_length_as_unsigned_LEB_128(this->int_value_); + size += get_length_as_unsigned_LEB_128(this->int_value_); if (Object_attribute::attribute_type_has_string_value(this->type_)) - uleb128_size += this->string_value_.size() + 1; - return uleb128_size; + size += this->string_value_.size() + 1; + return size; } // Whether this has the default value (0/""). @@ -266,37 +266,37 @@ Attributes_section_data::size() const } // Construct an Attributes_section_data object by parsing section contents -// specified by VIEW and VIEW_SIZE. +// specified by VIEW and SIZE. Attributes_section_data::Attributes_section_data( const unsigned char* view, - section_size_type view_size) + section_size_type size) { for (int vendor = OBJ_ATTR_FIRST; vendor <= OBJ_ATTR_LAST; ++vendor) this->vendor_object_attributes_[vendor] = new Vendor_object_attributes(vendor); - const unsigned char *p = view; + const unsigned char* p = view; p = view; - if (*(p++) == 'A') + if (size > 0 && p != NULL && *(p++) == 'A') { - view_size--; - while (view_size > 0) + size--; + while (size > 0) { // Size of vendor attributes section. section_size_type section_size = convert_to_section_size_type(read_from_pointer<32>(&p)); - if (section_size > view_size) - section_size = view_size; - view_size -= section_size; + if (section_size > size) + section_size = size; + size -= section_size; const char* section_name = reinterpret_cast(p); section_size_type section_name_size = strlen(section_name) + 1; section_size -= section_name_size + 4; int vendor; - const char *std_section = parameters->target().attributes_vendor(); + const char* std_section = parameters->target().attributes_vendor(); if (std_section != NULL && strcmp(section_name, std_section) == 0) vendor = Object_attribute::OBJ_ATTR_PROC; else if (strcmp(section_name, "gnu") == 0) @@ -443,14 +443,15 @@ Attributes_section_data::write(std::vector* buffer) const void Output_attributes_section_data::do_write(Output_file* of) { + off_t offset = this->offset(); const section_size_type oview_size = convert_to_section_size_type(this->data_size()); - unsigned char* const oview = of->get_output_view(this->offset(), oview_size); + unsigned char* const oview = of->get_output_view(offset, oview_size); std::vector buffer; this->attributes_section_data_.write(&buffer); gold_assert(convert_to_section_size_type(buffer.size()) == oview_size); - memcpy(oview, buffer.data(), buffer.size()); + memcpy(oview, &buffer.front(), buffer.size()); of->write_output_view(this->offset(), oview_size, oview); }