Merge branch 'jk/squelch-false-warning-from-gcc-o3' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 19 Sep 2016 20:51:41 +0000 (13:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Sep 2016 20:51:41 +0000 (13:51 -0700)
Compilation fix.

* jk/squelch-false-warning-from-gcc-o3:
color_parse_mem: initialize "struct color" temporary
error_errno: use constant return similar to error()

1  2 
color.c
git-compat-util.h
diff --combined color.c
index 81c26767239f9e028057c1843f57b77640db6c26,c809548991d3b247e7e5476030edb0d88d9179f9..1b95e6b2a7bb1601fa5862de8989775e197c7b41
+++ b/color.c
@@@ -123,34 -123,19 +123,34 @@@ static int parse_color(struct color *ou
        return -1;
  }
  
 -static int parse_attr(const char *name, int len)
 +static int parse_attr(const char *name, size_t len)
  {
 -      static const int attr_values[] = { 1, 2, 4, 5, 7,
 -                                         22, 22, 24, 25, 27 };
 -      static const char * const attr_names[] = {
 -              "bold", "dim", "ul", "blink", "reverse",
 -              "nobold", "nodim", "noul", "noblink", "noreverse"
 +      static const struct {
 +              const char *name;
 +              size_t len;
 +              int val, neg;
 +      } attrs[] = {
 +#define ATTR(x, val, neg) { (x), sizeof(x)-1, (val), (neg) }
 +              ATTR("bold",      1, 22),
 +              ATTR("dim",       2, 22),
 +              ATTR("italic",    3, 23),
 +              ATTR("ul",        4, 24),
 +              ATTR("blink",     5, 25),
 +              ATTR("reverse",   7, 27),
 +              ATTR("strike",    9, 29)
 +#undef ATTR
        };
 +      int negate = 0;
        int i;
 -      for (i = 0; i < ARRAY_SIZE(attr_names); i++) {
 -              const char *str = attr_names[i];
 -              if (!strncasecmp(name, str, len) && !str[len])
 -                      return attr_values[i];
 +
 +      if (skip_prefix_mem(name, len, "no", &name, &len)) {
 +              skip_prefix_mem(name, len, "-", &name, &len);
 +              negate = 1;
 +      }
 +
 +      for (i = 0; i < ARRAY_SIZE(attrs); i++) {
 +              if (attrs[i].len == len && !memcmp(attrs[i].name, name, len))
 +                      return negate ? attrs[i].neg : attrs[i].val;
        }
        return -1;
  }
@@@ -215,7 -200,7 +215,7 @@@ int color_parse_mem(const char *value, 
        /* [fg [bg]] [attr]... */
        while (len > 0) {
                const char *word = ptr;
-               struct color c;
+               struct color c = { COLOR_UNSPECIFIED };
                int val, wordlen = 0;
  
                while (len > 0 && !isspace(word[wordlen])) {
diff --combined git-compat-util.h
index db89ba774891a9608531e52252de19d552cbf535,24f0ec9986896e180974e7212c22378bcd1630c6..2ad45b3f759336acbca40499e737eb2d68a44669
@@@ -436,6 -436,7 +436,7 @@@ static inline int const_error(void
        return -1;
  }
  #define error(...) (error(__VA_ARGS__), const_error())
+ #define error_errno(...) (error_errno(__VA_ARGS__), const_error())
  #endif
  
  extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
@@@ -473,23 -474,6 +474,23 @@@ static inline int skip_prefix(const cha
        return 0;
  }
  
 +/*
 + * Like skip_prefix, but promises never to read past "len" bytes of the input
 + * buffer, and returns the remaining number of bytes in "out" via "outlen".
 + */
 +static inline int skip_prefix_mem(const char *buf, size_t len,
 +                                const char *prefix,
 +                                const char **out, size_t *outlen)
 +{
 +      size_t prefix_len = strlen(prefix);
 +      if (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {
 +              *out = buf + prefix_len;
 +              *outlen = len - prefix_len;
 +              return 1;
 +      }
 +      return 0;
 +}
 +
  /*
   * If buf ends with suffix, return 1 and subtract the length of the suffix
   * from *len. Otherwise, return 0 and leave *len untouched.
@@@ -667,10 -651,6 +668,10 @@@ void *gitmemmem(const void *haystack, s
  #define getpagesize() sysconf(_SC_PAGESIZE)
  #endif
  
 +#ifndef O_CLOEXEC
 +#define O_CLOEXEC 0
 +#endif
 +
  #ifdef FREAD_READS_DIRECTORIES
  #ifdef fopen
  #undef fopen
@@@ -819,7 -799,7 +820,7 @@@ extern FILE *fopen_for_writing(const ch
   * you can do:
   *
   *   struct foo *f;
 - *   FLEX_ALLOC_STR(f, name, src);
 + *   FLEXPTR_ALLOC_STR(f, name, src);
   *
   * and "name" will point to a block of memory after the struct, which will be
   * freed along with the struct (but the pointer can be repointed anywhere).
@@@ -1066,5 -1046,3 +1067,5 @@@ struct tm *git_gmtime_r(const time_t *
  #endif
  
  #endif
 +
 +extern int cmd_main(int, const char **);