diff options
author | Jeff King <peff@peff.net> | 2020-04-10 15:44:28 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-04-10 14:44:29 -0700 |
commit | f5914f4b6bcdb517733c761fe5ba9d94471eb01d (patch) | |
tree | 12b2a92eecd00075ad0bc04100ebb22d2a0f9e5b /config.c | |
parent | remote: drop auto-strlen behavior of make_branch() and make_rewrite() (diff) | |
download | tgif-f5914f4b6bcdb517733c761fe5ba9d94471eb01d.tar.xz |
parse_config_key(): return subsection len as size_t
We return the length to a subset of a string using an "int *"
out-parameter. This is fine most of the time, as we'd expect config keys
to be relatively short, but it could behave oddly if we had a gigantic
config key. A more appropriate type is size_t.
Let's switch over, which lets our callers use size_t as appropriate
(they are bound by our type because they must pass the out-parameter as
a pointer). This is mostly just a cleanup to make it clear this code
handles long strings correctly. In practice, our config parser already
chokes on long key names (because of a similar int/size_t mixup!).
When doing an int/size_t conversion, we have to be careful that nobody
was trying to assign a negative value to the variable. I manually
confirmed that for each case here. They tend to just feed the result to
xmemdupz() or similar; in a few cases I adjusted the parameter types for
helper functions to make sure the size_t is preserved.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -309,7 +309,7 @@ int git_config_include(const char *var, const char *value, void *data) { struct config_include_data *inc = data; const char *cond, *key; - int cond_len; + size_t cond_len; int ret; /* @@ -3238,7 +3238,7 @@ int config_error_nonbool(const char *var) int parse_config_key(const char *var, const char *section, - const char **subsection, int *subsection_len, + const char **subsection, size_t *subsection_len, const char **key) { const char *dot; |