Re: [PATCH] Fix git to be (more) ANSI C99 compliant.
From: Timo Hirvonen <hidden>
Date: 2016-06-15 22:42:30
Florian Forster [off-list ref] wrote:
Using this patch I was able to build git with $ make CFLAGS="-Wall -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE" While most of this patch fixes void-pointer arithmetic and is therefore trivial, I had to change the use of a struct with FAMs in `diff-lib.c'. Since this is the first time I encountered FAMs it'd probably be a good idea if someone who knows would take a look at that.
Many of the void-pointer arithmetic warnings could be fixed by changing the variable types to char * instead of casting them in many places.
quoted hunk ↗ jump to hunk
--- a/diff-lib.c +++ b/diff-lib.c@@ -34,21 +34,23 @@ int run_diff_files(struct rev_info *revs continue; if (ce_stage(ce)) { - struct { - struct combine_diff_path p; - struct combine_diff_parent filler[5]; - } combine;
Yes this is somewhat ugly but avoids a malloc. You could use alloca but
the man-page says:
"The alloca() function is machine and compiler dependent. On many systems
its implementation is buggy. Its use is discouraged."
Leave the code as it is now unless it causes real problems.
static inline int needs_quote(int ch)
{
- switch (ch) {
- case '/': case '-': case '.':
- case 'A'...'Z': case 'a'...'z': case '0'...'9':
+ if (((ch >= 'A') && (ch <= 'Z'))
+ || ((ch >= 'a') && (ch <= 'z'))
+ || ((ch >= '0') && (ch <= '9'))
+ || (ch == '/')
+ || (ch == '-')
+ || (ch == '.'))'A'...'Z' is more readable. Does some compiler fail to compile it?
quoted hunk ↗ jump to hunk
+++ b/http-push.c
static inline int needs_quote(int ch)
Hmm.. same function in http-fetch.c. Lots of common code could be moved to http.h. -- http://onion.dynserv.net/~timo/