Message ID | 20181027173008.18852-11-pclouds@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Reduce #ifdef NO_PTHREADS | expand |
On Sat, Oct 27, 2018 at 07:30:08PM +0200, Nguyễn Thái Ngọc Duy wrote: > It was reported that when building with NO_PTHREADS=1, > -Wmaybe-uninitialized is triggered. Just initialize the variable from > the beginning to shut the compiler up (because this warning is enabled > in config.dev) > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> > --- > read-cache.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/read-cache.c b/read-cache.c > index ba870bc3fd..4307b9a7bf 100644 > --- a/read-cache.c > +++ b/read-cache.c > @@ -1746,7 +1746,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, > size_t len; > const char *name; > unsigned int flags; > - size_t copy_len; > + size_t copy_len = 0; > /* > * Adjacent cache entries tend to share the leading paths, so it makes > * sense to only store the differences in later entries. In the v4 > @@ -1786,8 +1786,6 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, > die(_("malformed name field in the index, near path '%s'"), > previous_ce->name); > copy_len = previous_len - strip_len; > - } else { > - copy_len = 0; > } > name = (const char *)cp; > } Yes, this silences the compiler warning I saw (and is exactly the same patch I wrote to get past it the other day ;) ). -Peff
diff --git a/read-cache.c b/read-cache.c index ba870bc3fd..4307b9a7bf 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1746,7 +1746,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, size_t len; const char *name; unsigned int flags; - size_t copy_len; + size_t copy_len = 0; /* * Adjacent cache entries tend to share the leading paths, so it makes * sense to only store the differences in later entries. In the v4 @@ -1786,8 +1786,6 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, die(_("malformed name field in the index, near path '%s'"), previous_ce->name); copy_len = previous_len - strip_len; - } else { - copy_len = 0; } name = (const char *)cp; }
It was reported that when building with NO_PTHREADS=1, -Wmaybe-uninitialized is triggered. Just initialize the variable from the beginning to shut the compiler up (because this warning is enabled in config.dev) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- read-cache.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)