protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Initialize variables to address warning regarding possible use of uninitialized variables

Open tempoz opened this issue 1 year ago • 4 comments

tempoz avatar Sep 11 '24 13:09 tempoz

Which compiler is raising these warnings? What compiler version and what compilation flags?

haberman avatar Sep 17 '24 20:09 haberman

The compiler I am using is gcc (Debian 14.2.0-3) 14.2.0. I am not using any special flags, I just run bazel build //....

tempoz avatar Sep 18 '24 18:09 tempoz

Could you rebase? I suspect the failing tests were at head.

zhangskz avatar Oct 14 '24 16:10 zhangskz

yeah, no problem

tempoz avatar Oct 16 '24 22:10 tempoz

Rebased this again since it's been a bit; feel free to re-run tests and review whenever you find time!

tempoz avatar Nov 15 '24 17:11 tempoz

I don't think this is the correct fix.

The real issue here is that both upb_WireReader_ReadTag() and upb_WireReader_ReadSize() can return NULL to indicate error, and in that case the variables will not be initialized.

However, in this case the data is coming from the unknown fields of a upb_Message. We should be guaranteed that this is valid wire format.

I would suggest the following fix. This should make the warnings go away:

Add UPB_ASSUME(ptr != NULL) after the upb_WireReader_ReadTag() and upb_WireReader_ReadSize() calls. As a bonus, this will give us loud warnings in debug mode if these assumptions turn out not to be true.

We should probably do the same for every WireReader call in this function that returns ptr.

haberman avatar Nov 21 '24 22:11 haberman

It's possible that we may need to add UPB_ASSUME(ret != NULL) into the success paths of the WireReader functions also.

haberman avatar Nov 21 '24 22:11 haberman

We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please add a comment.

This PR is labeled inactive because the last activity was over 90 days ago. This PR will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Feb 26 '25 10:02 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active or becomes active again, please reopen it.

This PR was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Mar 13 '25 10:03 github-actions[bot]