Commit 1bbec26d by Patrick Steinhardt

attr_file: completely initialize attribute sessions

The function `git_attr_session__init` is currently only initializing
setting up the attribute's session key by incrementing the repo-global
key by one. Most notably, all other members of the `git_attr_session`
struct are not getting initialized at all. So if one is to allocate a
session on the stack and then calls `git_attr_session__init`, the
session will still not be fully initialized. We have fared just fine
with that until now as all users of the function have allocated the
session structure as part of bigger structs with `calloc`, and thus its
contents have been zero-initialized implicitly already.

Fix this by explicitly zeroing out the session to enable allocation of
sessions on the stack.
parent 18a6d9f3
...@@ -919,6 +919,7 @@ int git_attr_session__init(git_attr_session *session, git_repository *repo) ...@@ -919,6 +919,7 @@ int git_attr_session__init(git_attr_session *session, git_repository *repo)
{ {
assert(repo); assert(repo);
memset(session, 0, sizeof(*session));
session->key = git_atomic_inc(&repo->attr_session_key); session->key = git_atomic_inc(&repo->attr_session_key);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment