Merge branch 'js/gcc-8-and-9'
authorJunio C Hamano <gitster@pobox.com>
Tue, 9 Jul 2019 22:25:41 +0000 (15:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Jul 2019 22:25:41 +0000 (15:25 -0700)
Code clean-up for new compilers.

* js/gcc-8-and-9:
config: avoid calling `labs()` on too-large data type
winansi: simplify loading the GetCurrentConsoleFontEx() function
kwset: allow building with GCC 8
poll (mingw): allow compiling with GCC 8 and DEVELOPER=1

1  2 
config.c
kwset.c
diff --combined config.c
index ad4166e24312b869f1add698b100d3991e42859d,01c6e9df23c6a8f35fc70dcfc1275d4f3f9a1f2b..972d3c10335bcf918e8393099031769b263e5b77
+++ b/config.c
@@@ -19,7 -19,6 +19,7 @@@
  #include "utf8.h"
  #include "dir.h"
  #include "color.h"
 +#include "refs.h"
  
  struct config_source {
        struct config_source *prev;
@@@ -171,12 -170,6 +171,12 @@@ static int handle_path_include(const ch
        return ret;
  }
  
 +static void add_trailing_starstar_for_dir(struct strbuf *pat)
 +{
 +      if (pat->len && is_dir_sep(pat->buf[pat->len - 1]))
 +              strbuf_addstr(pat, "**");
 +}
 +
  static int prepare_include_condition_pattern(struct strbuf *pat)
  {
        struct strbuf path = STRBUF_INIT;
        } else if (!is_absolute_path(pat->buf))
                strbuf_insert(pat, 0, "**/", 3);
  
 -      if (pat->len && is_dir_sep(pat->buf[pat->len - 1]))
 -              strbuf_addstr(pat, "**");
 +      add_trailing_starstar_for_dir(pat);
  
        strbuf_release(&path);
        return prefix;
@@@ -270,25 -264,6 +270,25 @@@ done
        return ret;
  }
  
 +static int include_by_branch(const char *cond, size_t cond_len)
 +{
 +      int flags;
 +      int ret;
 +      struct strbuf pattern = STRBUF_INIT;
 +      const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
 +      const char *shortname;
 +
 +      if (!refname || !(flags & REF_ISSYMREF) ||
 +                      !skip_prefix(refname, "refs/heads/", &shortname))
 +              return 0;
 +
 +      strbuf_add(&pattern, cond, cond_len);
 +      add_trailing_starstar_for_dir(&pattern);
 +      ret = !wildmatch(pattern.buf, shortname, WM_PATHNAME);
 +      strbuf_release(&pattern);
 +      return ret;
 +}
 +
  static int include_condition_is_true(const struct config_options *opts,
                                     const char *cond, size_t cond_len)
  {
                return include_by_gitdir(opts, cond, cond_len, 0);
        else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
                return include_by_gitdir(opts, cond, cond_len, 1);
 +      else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
 +              return include_by_branch(cond, cond_len);
  
        /* unknown conditionals are always false */
        return 0;
@@@ -896,9 -869,9 +896,9 @@@ static int git_parse_signed(const char 
                        errno = EINVAL;
                        return 0;
                }
-               uval = labs(val);
+               uval = val < 0 ? -val : val;
                uval *= factor;
-               if (uval > max || labs(val) > uval) {
+               if (uval > max || (val < 0 ? -val : val) > uval) {
                        errno = ERANGE;
                        return 0;
                }
diff --combined kwset.c
index 090ffcafa2bd0eeff8bbc08ea15867fe8f5b7890,efc2ff41bc361a7a3bf940b04642ccba8538cb3b..fc439e0667f137f3449635a37a32f8418d5041f0
+++ b/kwset.c
  #include "compat/obstack.h"
  
  #define NCHAR (UCHAR_MAX + 1)
- #define obstack_chunk_alloc xmalloc
+ /* adapter for `xmalloc()`, which takes `size_t`, not `long` */
+ static void *obstack_chunk_alloc(long size)
+ {
+       if (size < 0)
+               BUG("Cannot allocate a negative amount: %ld", size);
+       return xmalloc(size);
+ }
  #define obstack_chunk_free free
  
  #define U(c) ((unsigned char) (c))
@@@ -475,7 -481,7 +481,7 @@@ kwsprep (kwset_t kws
        for (i = 0; i < NCHAR; ++i)
          kwset->next[i] = next[U(trans[i])];
        else
 -      memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
 +      COPY_ARRAY(kwset->next, next, NCHAR);
      }
  
    /* Fix things up for any translation table. */