Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

stringop-truncation and address-of-packed-member #309

Closed
wants to merge 1 commit into from

Conversation

NaruFGT
Copy link

@NaruFGT NaruFGT commented Dec 28, 2019

Fixed build errors related to passing address of packed car_key_format and replaced strncpy with memcpy to fix errors related to stringop-truncation.

…py with memcpy to fix errors related to stringop-truncation.
@facebook-github-bot
Copy link

Hi NaruFGT! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Contributor

@sas sas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change. It looks like there are some issues in your code that need to be fixed before landing.

Comment on lines +85 to +89
uint32_t *unpacked_identifiers = new uint32_t[sizeof(uint32_t)*keyfmt->num_identifiers];
for(size_t i = 0; i < keyfmt->num_identifiers; ++i) {
unpacked_identifiers[i] = keyfmt->identifier_list[i];
}
AttributeList attributes = AttributeList::Load(keyfmt->num_identifiers, unpacked_identifiers, rendition_key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an alignment problem here.

Comment on lines +271 to +275
uint32_t *unpacked_identifiers = new uint32_t[sizeof(uint32_t)*keyfmt->num_identifiers];
for(size_t i = 0; i < keyfmt->num_identifiers; ++i) {
unpacked_identifiers[i] = keyfmt->identifier_list[i];
}
AttributeList attributes = AttributeList::Load(keyfmt->num_identifiers, unpacked_identifiers, rendition_key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting.

Comment on lines +165 to +169
uint32_t *unpacked_identifiers = new uint32_t[sizeof(uint32_t)*keyfmt->num_identifiers];
for(size_t i = 0; i < keyfmt->num_identifiers; ++i) {
unpacked_identifiers[i] = keyfmt->identifier_list[i];
}
auto attributes_value = item.second.attributes().write(keyfmt->num_identifiers, unpacked_identifiers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting.

@@ -162,7 +162,11 @@ write() const
bom_tree_reserve(renditions_tree_context, rendition_count);
if (renditions_tree_context != NULL) {
for (auto const &item : _renditions) {
auto attributes_value = item.second.attributes().write(keyfmt->num_identifiers, keyfmt->identifier_list);
uint32_t *unpacked_identifiers = new uint32_t[sizeof(uint32_t)*keyfmt->num_identifiers];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leak + incorrect size specifier.

@@ -264,7 +268,11 @@ lookupRenditions(Facet const &facet) const
KeyValuePair value = (KeyValuePair)it->second;
car_rendition_key *rendition_key = (car_rendition_key *)value.key;
struct car_rendition_value *rendition_value = (struct car_rendition_value *)value.value;
AttributeList attributes = AttributeList::Load(keyfmt->num_identifiers, keyfmt->identifier_list, rendition_key);
uint32_t *unpacked_identifiers = new uint32_t[sizeof(uint32_t)*keyfmt->num_identifiers];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're never freeing the memory block you allocated here. Also, the size you allocate seems wrong to me; you're gonna end up allocating 4 entries in your array (sizeof(uint32_t)).

@NaruFGT
Copy link
Author

NaruFGT commented Dec 31, 2019

Thank you for the feedback, I’m wondering if a better approach would be to add
AttributeList AttributeList::
Load(struct car_key_format *keyfmt, uint16_t const *values) as this would not require allocating additional memory and could be implemented without referencing the address of identifier_list.

@NaruFGT NaruFGT closed this Dec 31, 2019
@sas
Copy link
Contributor

sas commented Jan 2, 2020 via email

@NaruFGT
Copy link
Author

NaruFGT commented Jan 3, 2020

Rather than unpacking, I think the ideal solution is to pass keyfmt rather than passing the addresses of it's members. If we pass the address of keyfmt, we don't have to ever take the address of keyfmt->identifier_list which is the root cause of the build errors in the first place.
I think you're correct that the loop is unnecessary and a memcpy call should be sufficient. I'll make the changes but I'd urge you to consider #310

@NaruFGT
Copy link
Author

NaruFGT commented Jan 3, 2020

I submitted #311 which preserves the behaviors in this PR while using std::vector which should call destructors once unpacked_identifiers is out of scope, also fixed formatting. I didn't realize my editor is using tabs rather than spaces.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants