mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
Merge branch 'jn/maint-c99-format'
* jn/maint-c99-format: unbreak and eliminate NO_C99_FORMAT mktag: avoid %td in format string
This commit is contained in:
commit
3ed8868474
14
Makefile
14
Makefile
|
@ -45,11 +45,6 @@ all::
|
|||
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
|
||||
# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
|
||||
#
|
||||
# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
|
||||
# do not support the 'size specifiers' introduced by C99, namely ll, hh,
|
||||
# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
|
||||
# some C compilers supported these specifiers prior to C99 as an extension.
|
||||
#
|
||||
# Define NO_STRCASESTR if you don't have strcasestr.
|
||||
#
|
||||
# Define NO_MEMMEM if you don't have memmem.
|
||||
|
@ -878,7 +873,6 @@ ifeq ($(uname_S),SunOS)
|
|||
NO_UNSETENV = YesPlease
|
||||
NO_SETENV = YesPlease
|
||||
NO_STRLCPY = YesPlease
|
||||
NO_C99_FORMAT = YesPlease
|
||||
NO_STRTOUMAX = YesPlease
|
||||
GIT_TEST_CMP = cmp
|
||||
endif
|
||||
|
@ -889,21 +883,18 @@ ifeq ($(uname_S),SunOS)
|
|||
NO_UNSETENV = YesPlease
|
||||
NO_SETENV = YesPlease
|
||||
NO_STRLCPY = YesPlease
|
||||
NO_C99_FORMAT = YesPlease
|
||||
NO_STRTOUMAX = YesPlease
|
||||
GIT_TEST_CMP = cmp
|
||||
endif
|
||||
ifeq ($(uname_R),5.8)
|
||||
NO_UNSETENV = YesPlease
|
||||
NO_SETENV = YesPlease
|
||||
NO_C99_FORMAT = YesPlease
|
||||
NO_STRTOUMAX = YesPlease
|
||||
GIT_TEST_CMP = cmp
|
||||
endif
|
||||
ifeq ($(uname_R),5.9)
|
||||
NO_UNSETENV = YesPlease
|
||||
NO_SETENV = YesPlease
|
||||
NO_C99_FORMAT = YesPlease
|
||||
NO_STRTOUMAX = YesPlease
|
||||
GIT_TEST_CMP = cmp
|
||||
endif
|
||||
|
@ -1083,7 +1074,6 @@ ifeq ($(uname_S),Windows)
|
|||
NO_MEMMEM = YesPlease
|
||||
# NEEDS_LIBICONV = YesPlease
|
||||
NO_ICONV = YesPlease
|
||||
NO_C99_FORMAT = YesPlease
|
||||
NO_STRTOUMAX = YesPlease
|
||||
NO_STRTOULL = YesPlease
|
||||
NO_MKDTEMP = YesPlease
|
||||
|
@ -1160,7 +1150,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
|
|||
NO_MEMMEM = YesPlease
|
||||
NEEDS_LIBICONV = YesPlease
|
||||
OLD_ICONV = YesPlease
|
||||
NO_C99_FORMAT = YesPlease
|
||||
NO_STRTOUMAX = YesPlease
|
||||
NO_MKDTEMP = YesPlease
|
||||
NO_MKSTEMPS = YesPlease
|
||||
|
@ -1363,9 +1352,6 @@ endif
|
|||
ifdef NO_NSEC
|
||||
BASIC_CFLAGS += -DNO_NSEC
|
||||
endif
|
||||
ifdef NO_C99_FORMAT
|
||||
BASIC_CFLAGS += -DNO_C99_FORMAT
|
||||
endif
|
||||
ifdef SNPRINTF_RETURNS_BOGUS
|
||||
COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS
|
||||
COMPAT_OBJS += compat/snprintf.o
|
||||
|
|
11
alloc.c
11
alloc.c
|
@ -51,19 +51,12 @@ DEFINE_ALLOCATOR(commit, struct commit)
|
|||
DEFINE_ALLOCATOR(tag, struct tag)
|
||||
DEFINE_ALLOCATOR(object, union any_object)
|
||||
|
||||
#ifdef NO_C99_FORMAT
|
||||
#define SZ_FMT "%u"
|
||||
#else
|
||||
#define SZ_FMT "%zu"
|
||||
#endif
|
||||
|
||||
static void report(const char *name, unsigned int count, size_t size)
|
||||
{
|
||||
fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size);
|
||||
fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
|
||||
name, count, (uintmax_t) size);
|
||||
}
|
||||
|
||||
#undef SZ_FMT
|
||||
|
||||
#define REPORT(name) \
|
||||
report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
|
||||
|
||||
|
|
|
@ -34,12 +34,6 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef NO_C99_FORMAT
|
||||
#define PD_FMT "%d"
|
||||
#else
|
||||
#define PD_FMT "%td"
|
||||
#endif
|
||||
|
||||
static int verify_tag(char *buffer, unsigned long size)
|
||||
{
|
||||
int typelen;
|
||||
|
@ -69,15 +63,18 @@ static int verify_tag(char *buffer, unsigned long size)
|
|||
/* Verify tag-line */
|
||||
tag_line = strchr(type_line, '\n');
|
||||
if (!tag_line)
|
||||
return error("char" PD_FMT ": could not find next \"\\n\"", type_line - buffer);
|
||||
return error("char%"PRIuMAX": could not find next \"\\n\"",
|
||||
(uintmax_t) (type_line - buffer));
|
||||
tag_line++;
|
||||
if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n')
|
||||
return error("char" PD_FMT ": no \"tag \" found", tag_line - buffer);
|
||||
return error("char%"PRIuMAX": no \"tag \" found",
|
||||
(uintmax_t) (tag_line - buffer));
|
||||
|
||||
/* Get the actual type */
|
||||
typelen = tag_line - type_line - strlen("type \n");
|
||||
if (typelen >= sizeof(type))
|
||||
return error("char" PD_FMT ": type too long", type_line+5 - buffer);
|
||||
return error("char%"PRIuMAX": type too long",
|
||||
(uintmax_t) (type_line+5 - buffer));
|
||||
|
||||
memcpy(type, type_line+5, typelen);
|
||||
type[typelen] = 0;
|
||||
|
@ -94,15 +91,16 @@ static int verify_tag(char *buffer, unsigned long size)
|
|||
break;
|
||||
if (c > ' ')
|
||||
continue;
|
||||
return error("char" PD_FMT ": could not verify tag name", tag_line - buffer);
|
||||
return error("char%"PRIuMAX": could not verify tag name",
|
||||
(uintmax_t) (tag_line - buffer));
|
||||
}
|
||||
|
||||
/* Verify the tagger line */
|
||||
tagger_line = tag_line;
|
||||
|
||||
if (memcmp(tagger_line, "tagger ", 7))
|
||||
return error("char" PD_FMT ": could not find \"tagger \"",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": could not find \"tagger \"",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
|
||||
/*
|
||||
* Check for correct form for name and email
|
||||
|
@ -114,44 +112,42 @@ static int verify_tag(char *buffer, unsigned long size)
|
|||
if (!(lb = strstr(tagger_line, " <")) || !(rb = strstr(lb+2, "> ")) ||
|
||||
strpbrk(tagger_line, "<>\n") != lb+1 ||
|
||||
strpbrk(lb+2, "><\n ") != rb)
|
||||
return error("char" PD_FMT ": malformed tagger field",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": malformed tagger field",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
|
||||
/* Check for author name, at least one character, space is acceptable */
|
||||
if (lb == tagger_line)
|
||||
return error("char" PD_FMT ": missing tagger name",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": missing tagger name",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
|
||||
/* timestamp, 1 or more digits followed by space */
|
||||
tagger_line = rb + 2;
|
||||
if (!(len = strspn(tagger_line, "0123456789")))
|
||||
return error("char" PD_FMT ": missing tag timestamp",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": missing tag timestamp",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
tagger_line += len;
|
||||
if (*tagger_line != ' ')
|
||||
return error("char" PD_FMT ": malformed tag timestamp",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": malformed tag timestamp",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
tagger_line++;
|
||||
|
||||
/* timezone, 5 digits [+-]hhmm, max. 1400 */
|
||||
if (!((tagger_line[0] == '+' || tagger_line[0] == '-') &&
|
||||
strspn(tagger_line+1, "0123456789") == 4 &&
|
||||
tagger_line[5] == '\n' && atoi(tagger_line+1) <= 1400))
|
||||
return error("char" PD_FMT ": malformed tag timezone",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": malformed tag timezone",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
tagger_line += 6;
|
||||
|
||||
/* Verify the blank line separating the header from the body */
|
||||
if (*tagger_line != '\n')
|
||||
return error("char" PD_FMT ": trailing garbage in tag header",
|
||||
tagger_line - buffer);
|
||||
return error("char%"PRIuMAX": trailing garbage in tag header",
|
||||
(uintmax_t) (tagger_line - buffer));
|
||||
|
||||
/* The actual stuff afterwards we don't care about.. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef PD_FMT
|
||||
|
||||
int cmd_mktag(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
|
|
|
@ -43,7 +43,6 @@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
|
|||
NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@
|
||||
NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@
|
||||
NO_IPV6=@NO_IPV6@
|
||||
NO_C99_FORMAT=@NO_C99_FORMAT@
|
||||
NO_HSTRERROR=@NO_HSTRERROR@
|
||||
NO_STRCASESTR=@NO_STRCASESTR@
|
||||
NO_STRTOK_R=@NO_STRTOK_R@
|
||||
|
|
24
configure.ac
24
configure.ac
|
@ -686,30 +686,6 @@ AC_CHECK_TYPE([struct addrinfo],[
|
|||
])
|
||||
AC_SUBST(NO_IPV6)
|
||||
#
|
||||
# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
|
||||
# do not support the 'size specifiers' introduced by C99, namely ll, hh,
|
||||
# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
|
||||
# some C compilers supported these specifiers prior to C99 as an extension.
|
||||
AC_CACHE_CHECK([whether formatted IO functions support C99 size specifiers],
|
||||
[ac_cv_c_c99_format],
|
||||
[# Actually git uses only %z (%zu) in alloc.c, and %t (%td) in mktag.c
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
|
||||
[[char buf[64];
|
||||
if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5)
|
||||
return 1;
|
||||
else if (strcmp(buf, "12345"))
|
||||
return 2;]])],
|
||||
[ac_cv_c_c99_format=yes],
|
||||
[ac_cv_c_c99_format=no])
|
||||
])
|
||||
if test $ac_cv_c_c99_format = no; then
|
||||
NO_C99_FORMAT=YesPlease
|
||||
else
|
||||
NO_C99_FORMAT=
|
||||
fi
|
||||
AC_SUBST(NO_C99_FORMAT)
|
||||
#
|
||||
# Define NO_REGEX if you have no or inferior regex support in your C library.
|
||||
AC_CACHE_CHECK([whether the platform regex can handle null bytes],
|
||||
[ac_cv_c_excellent_regex], [
|
||||
|
|
|
@ -26,13 +26,8 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NO_C99_FORMAT
|
||||
#define SZ_FMT "lu"
|
||||
static unsigned long sz_fmt(size_t s) { return (unsigned long)s; }
|
||||
#else
|
||||
#define SZ_FMT "zu"
|
||||
static size_t sz_fmt(size_t s) { return s; }
|
||||
#endif
|
||||
#define SZ_FMT PRIuMAX
|
||||
static inline uintmax_t sz_fmt(size_t s) { return s; }
|
||||
|
||||
const unsigned char null_sha1[20];
|
||||
|
||||
|
|
Loading…
Reference in a new issue