[Patch size_t V3 11/19] Use size_t for config parsing

2017-08-16 Thread Martin Koegler
From: Martin Koegler 

Signed-off-by: Martin Koegler 
---
 builtin/pack-objects.c |  6 +++---
 config.c   | 27 ++-
 config.h   |  2 ++
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 9067803..fbb07a8 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 bf4e2e4..50f0077 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;
 }
 
+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 18b6f3f..cbaa3e3 100644
--- a/config.h
+++ b/config.h
@@ -49,11 +49,13 @@ extern int config_with_options(config_fn_t fn, void *,
   struct git_config_source *config_source,
   const struct config_options *opts);
 extern int git_parse_ulong(const char *, unsigned long *);
+extern int git_parse_size_t(const char *, size_t *);
 extern int git_parse_maybe_bool(const char *);
 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



Re: [Patch size_t V3 11/19] Use size_t for config parsing

2017-08-24 Thread Johannes Sixt
Am 16.08.2017 um 22:16 schrieb Martin Koegler:
> +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;
> +}
> +

I think this requires the following on top:

diff --git a/config.c b/config.c
index 81d46602f9..b3075aa1c4 100644
--- a/config.c
+++ b/config.c
@@ -866,7 +866,7 @@ static int git_parse_ssize_t(const char *value, ssize_t 
*ret)
 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)))
+   if (!git_parse_unsigned(value, &tmp, 
maximum_unsigned_value_of_type(size_t)))
return 0;
*ret = tmp;
return 1;