-
Notifications
You must be signed in to change notification settings - Fork 27.2k
refs: dereference the value of the required pointer #2130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AZero13
wants to merge
1
commit into
git:master
Choose a base branch
from
AZero13:ref-cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Currently, this always prints yes because required is non-null. This is the wrong behavior. The boolean must be dereferenced. Signed-off-by: Greg Funni <[email protected]>
Contributor
Author
|
/submit |
|
Submitted as [email protected] To fetch this version into To fetch this version to local tag |
|
On the Git mailing list, Junio C Hamano wrote (reply to this): "AZero13 via GitGitGadget" <[email protected]> writes:
> From: Greg Funni <[email protected]>
>
> Currently, this always prints yes because required is non-null.
>
> This is the wrong behavior. The boolean must be
> dereferenced.
The line is blamed to f6c5ca38 (refs: add a `optimize_required`
field to `struct ref_storage_be`, 2025-11-08); the author CC'ed for
an Ack.
Thanks.
>
> Signed-off-by: Greg Funni <[email protected]>
> ---
> refs: dereference the value of the required pointer
>
> Currently, this always prints yes because required is non-null.
>
> This is the wrong behavior. The boolean must be dereferenced.
>
> Signed-off-by: Greg Funni [email protected]
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2130%2FAZero13%2Fref-cache-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2130/AZero13/ref-cache-v1
> Pull-Request: https://github.com/git/git/pull/2130
>
> refs/debug.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/refs/debug.c b/refs/debug.c
> index 3e31228c9a..639db0f26e 100644
> --- a/refs/debug.c
> +++ b/refs/debug.c
> @@ -139,7 +139,7 @@ static int debug_optimize_required(struct ref_store *ref_store,
> struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
> int res = drefs->refs->be->optimize_required(drefs->refs, opts, required);
> trace_printf_key(&trace_refs, "optimize_required: %s, res: %d\n",
> - required ? "yes" : "no", res);
> + *required ? "yes" : "no", res);
> return res;
> }
>
>
> base-commit: c4a0c8845e2426375ad257b6c221a3a7d92ecfda |
|
On the Git mailing list, Patrick Steinhardt wrote (reply to this): On Thu, Dec 18, 2025 at 04:10:49PM +0000, AZero13 via GitGitGadget wrote:
> diff --git a/refs/debug.c b/refs/debug.c
> index 3e31228c9a..639db0f26e 100644
> --- a/refs/debug.c
> +++ b/refs/debug.c
> @@ -139,7 +139,7 @@ static int debug_optimize_required(struct ref_store *ref_store,
> struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
> int res = drefs->refs->be->optimize_required(drefs->refs, opts, required);
> trace_printf_key(&trace_refs, "optimize_required: %s, res: %d\n",
> - required ? "yes" : "no", res);
> + *required ? "yes" : "no", res);
> return res;
> }
Makes sense. One question is whether `required` will always be non-NULL
so that we can unconditionally dereference the pointer like this. But
from going through the implementations I can see that the pointer
already does get dereferenced unconditionally, so this fix is safe.
Thanks!
Patrick |
|
User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, this always prints yes because required is non-null.
This is the wrong behavior. The boolean must be
dereferenced.
Signed-off-by: Greg Funni [email protected]
cc: Patrick Steinhardt [email protected]