From: Martin Koegler <martin.koegler@chello.at>
To: git@vger.kernel.org, gitster@pobox.com, Johannes.Schindelin@gmx.de
Cc: Martin Koegler <martin.koegler@chello.at>
Subject: [PATCH 6/9] Use size_t for config parsing
Date: Sat, 12 Aug 2017 10:47:20 +0200 [thread overview]
Message-ID: <1502527643-21944-6-git-send-email-martin@mail.zuhause> (raw)
In-Reply-To: <1502527643-21944-1-git-send-email-martin@mail.zuhause>
From: Martin Koegler <martin.koegler@chello.at>
Signed-off-by: Martin Koegler <martin.koegler@chello.at>
---
builtin/pack-objects.c | 6 +++---
config.c | 27 ++++++++++++++++++++++-----
config.h | 1 +
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f8db283..0086da7 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2450,7 +2450,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
return 0;
}
if (!strcmp(k, "pack.windowmemory")) {
- window_memory_limit = git_config_ulong(k, v);
+ window_memory_limit = git_config_size_t(k, v);
return 0;
}
if (!strcmp(k, "pack.depth")) {
@@ -2458,11 +2458,11 @@ static int git_pack_config(const char *k, const char *v, void *cb)
return 0;
}
if (!strcmp(k, "pack.deltacachesize")) {
- max_delta_cache_size = git_config_int(k, v);
+ max_delta_cache_size = git_config_size_t(k, v);
return 0;
}
if (!strcmp(k, "pack.deltacachelimit")) {
- cache_max_small_delta_size = git_config_int(k, v);
+ cache_max_small_delta_size = git_config_size_t(k, v);
return 0;
}
if (!strcmp(k, "pack.writebitmaphashcache")) {
diff --git a/config.c b/config.c
index 831cf8b..444b1d1 100644
--- a/config.c
+++ b/config.c
@@ -863,6 +863,15 @@ static int git_parse_ssize_t(const char *value, ssize_t *ret)
return 1;
}
+static int git_parse_size_t(const char *value, size_t *ret)
+{
+ uintmax_t tmp;
+ if (!git_parse_unsigned(value, &tmp, maximum_signed_value_of_type(size_t)))
+ return 0;
+ *ret = tmp;
+ return 1;
+}
+
NORETURN
static void die_bad_number(const char *name, const char *value)
{
@@ -929,6 +938,14 @@ ssize_t git_config_ssize_t(const char *name, const char *value)
return ret;
}
+size_t git_config_size_t(const char *name, const char *value)
+{
+ size_t ret;
+ if (!git_parse_size_t(value, &ret))
+ die_bad_number(name, value);
+ return ret;
+}
+
int git_parse_maybe_bool(const char *value)
{
if (!value)
@@ -1105,7 +1122,7 @@ static int git_default_core_config(const char *var, const char *value)
if (!strcmp(var, "core.packedgitwindowsize")) {
int pgsz_x2 = getpagesize() * 2;
- packed_git_window_size = git_config_ulong(var, value);
+ packed_git_window_size = git_config_size_t(var, value);
/* This value must be multiple of (pagesize * 2) */
packed_git_window_size /= pgsz_x2;
@@ -1116,17 +1133,17 @@ static int git_default_core_config(const char *var, const char *value)
}
if (!strcmp(var, "core.bigfilethreshold")) {
- big_file_threshold = git_config_ulong(var, value);
+ big_file_threshold = git_config_size_t(var, value);
return 0;
}
if (!strcmp(var, "core.packedgitlimit")) {
- packed_git_limit = git_config_ulong(var, value);
+ packed_git_limit = git_config_size_t(var, value);
return 0;
}
if (!strcmp(var, "core.deltabasecachelimit")) {
- delta_base_cache_limit = git_config_ulong(var, value);
+ delta_base_cache_limit = git_config_size_t(var, value);
return 0;
}
@@ -1360,7 +1377,7 @@ int git_default_config(const char *var, const char *value, void *dummy)
}
if (!strcmp(var, "pack.packsizelimit")) {
- pack_size_limit_cfg = git_config_ulong(var, value);
+ pack_size_limit_cfg = git_config_size_t(var, value);
return 0;
}
diff --git a/config.h b/config.h
index fb76729..c264ee8 100644
--- a/config.h
+++ b/config.h
@@ -54,6 +54,7 @@ extern int git_config_int(const char *, const char *);
extern int64_t git_config_int64(const char *, const char *);
extern unsigned long git_config_ulong(const char *, const char *);
extern ssize_t git_config_ssize_t(const char *, const char *);
+extern size_t git_config_size_t(const char *, const char *);
extern int git_config_bool_or_int(const char *, const char *, int *);
extern int git_config_bool(const char *, const char *);
extern int git_config_maybe_bool(const char *, const char *);
--
2.1.4
next prev parent reply other threads:[~2017-08-12 8:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-12 8:47 [PATCH 1/9] Convert pack-objects to size_t Martin Koegler
2017-08-12 8:47 ` [PATCH 2/9] Convert index-pack " Martin Koegler
2017-08-12 13:51 ` Ramsay Jones
2017-08-12 8:47 ` [PATCH 3/9] Convert unpack-objects " Martin Koegler
2017-08-12 14:07 ` Martin Ågren
2017-08-13 18:25 ` Martin Koegler
2017-08-12 8:47 ` [PATCH 4/9] Convert archive functions " Martin Koegler
2017-08-12 8:47 ` [PATCH 5/9] Convert various things " Martin Koegler
2017-08-12 13:27 ` Martin Ågren
2017-08-13 17:48 ` Martin Koegler
2017-08-12 8:47 ` Martin Koegler [this message]
2017-08-12 8:47 ` [PATCH 7/9] Convert ref-filter " Martin Koegler
2017-08-12 8:47 ` [PATCH 8/9] Convert tree-walk " Martin Koegler
2017-08-12 8:47 ` [PATCH 9/9] Convert xdiff-interface " Martin Koegler
2017-08-12 9:59 ` [PATCH 1/9] Convert pack-objects " Torsten Bögershausen
2017-08-13 18:27 ` Martin Koegler
2017-08-12 13:47 ` Ramsay Jones
2017-08-13 18:30 ` Martin Koegler
2017-08-13 19:45 ` Ramsay Jones
2017-08-13 22:15 ` Junio C Hamano
2017-08-14 17:08 ` Junio C Hamano
2017-08-14 19:31 ` Ramsay Jones
2017-08-14 19:58 ` Junio C Hamano
2017-08-14 20:32 ` Torsten Bögershausen
2017-08-15 0:30 ` Ramsay Jones
2017-08-16 20:22 ` Martin Koegler
2017-08-17 10:38 ` Torsten Bögershausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1502527643-21944-6-git-send-email-martin@mail.zuhause \
--to=martin.koegler@chello.at \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).