{"thread":{"id":"1461","subject":"[PATCH] -Werror fixes","startedAt":"2005-08-09T15:30:22Z","lastAt":"2005-08-09T18:11:27Z","messageCount":2,"participants":["Timo Sirainen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6993","messageId":"1123601422.21306.46.camel@hurina","threadId":"1461","inReplyTo":null,"subject":"[PATCH] -Werror fixes","fromName":"Timo Sirainen","fromEmail":"tss@iki.fi","sentAt":"2005-08-09T15:30:22Z","receivedAt":"2005-08-09T15:30:22Z","isPatch":true,"sender":{"key":"tss@iki.fi","avatar":null},"body":"GCC's format __attribute__ is good for checking errors, especially with\n-Werror=2 parameter. Patch below fixes most of the reported problems\nagainst 2005-08-09 snapshot.\n\nAlso how about trying to implement some kind of generically usable\nstring object? Now the code uses sprintf/snprintf/etc. in various\ndifferent ways with their own memory allocations, and it looks all messy\nand difficult to verify their correctness.\n\ndiff -ru git-current/apply.c git-modified/apply.c\n--- git-current/apply.c\t2005-08-09 18:00:06.000000000 +0300\n+++ git-modified/apply.c\t2005-08-09 17:50:13.712911497 +0300\n@@ -563,7 +563,7 @@\n \t\t\tstruct fragment dummy;\n \t\t\tif (parse_fragment_header(line, len, &dummy) < 0)\n \t\t\t\tcontinue;\n-\t\t\terror(\"patch fragment without header at line %d: %.*s\", linenr, len-1, line);\n+\t\t\terror(\"patch fragment without header at line %d: %.*s\", linenr, (int)len-1, line);\n \t\t}\n \n \t\tif (size < len + 6)\n@@ -968,7 +968,7 @@\n \n \twhile (frag) {\n \t\tif (apply_one_fragment(desc, frag) < 0)\n-\t\t\treturn error(\"patch failed: %s:%d\", patch->old_name, frag->oldpos);\n+\t\t\treturn error(\"patch failed: %s:%ld\", patch->old_name, frag->oldpos);\n \t\tfrag = frag->next;\n \t}\n \treturn 0;\ndiff -ru git-current/cache.h git-modified/cache.h\n--- git-current/cache.h\t2005-08-09 18:00:06.000000000 +0300\n+++ git-modified/cache.h\t2005-08-09 18:14:37.858158948 +0300\n@@ -40,6 +40,10 @@\n #define NORETURN\n #endif\n \n+#ifndef __attribute__\n+#define __attribute(x)\n+#endif\n+\n /*\n  * Intensive research over the course of many years has shown that\n  * port 9418 is totally unused by anything else. Or\n@@ -171,8 +175,8 @@\n #define TYPE_CHANGED    0x0040\n \n /* Return a statically allocated filename matching the sha1 signature */\n-extern char *mkpath(const char *fmt, ...);\n-extern char *git_path(const char *fmt, ...);\n+extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\n+extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\n extern char *sha1_file_name(const unsigned char *sha1);\n extern char *sha1_pack_name(const unsigned char *sha1);\n extern char *sha1_pack_index_name(const unsigned char *sha1);\n@@ -218,8 +222,8 @@\n \n /* General helper functions */\n extern void usage(const char *err) NORETURN;\n-extern void die(const char *err, ...) NORETURN;\n-extern int error(const char *err, ...);\n+extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));\n+extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n \n extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);\n extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2);\ndiff -ru git-current/clone-pack.c git-modified/clone-pack.c\n--- git-current/clone-pack.c\t2005-08-09 18:00:06.000000000 +0300\n+++ git-modified/clone-pack.c\t2005-08-09 17:53:32.295922222 +0300\n@@ -30,7 +30,7 @@\n \n static void write_one_ref(struct ref *ref)\n {\n-\tchar *path = git_path(ref->name);\n+\tchar *path = git_path(\"%s\", ref->name);\n \tint fd;\n \tchar *hex;\n \ndiff -ru git-current/connect.c git-modified/connect.c\n--- git-current/connect.c\t2005-08-09 18:00:06.000000000 +0300\n+++ git-modified/connect.c\t2005-08-09 17:46:35.187838763 +0300\n@@ -166,7 +166,8 @@\n \t\t\tif (matched_src)\n \t\t\t\tbreak;\n \t\t\terrs = 1;\n-\t\t\terror(\"src refspec %s does not match any.\");\n+\t\t\terror(\"src refspec %s does not match any.\",\n+\t\t\t      rs[i].src);\n \t\t\tbreak;\n \t\tdefault:\n \t\t\terrs = 1;\ndiff -ru git-current/csum-file.h git-modified/csum-file.h\n--- git-current/csum-file.h\t2005-08-09 18:00:06.000000000 +0300\n+++ git-modified/csum-file.h\t2005-08-09 18:02:33.825363592 +0300\n@@ -11,7 +11,7 @@\n };\n \n extern struct sha1file *sha1fd(int fd, const char *name);\n-extern struct sha1file *sha1create(const char *fmt, ...);\n+extern struct sha1file *sha1create(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\n extern int sha1close(struct sha1file *, unsigned char *, int);\n extern int sha1write(struct sha1file *, void *, unsigned int);\n extern int sha1write_compressed(struct sha1file *, void *, unsigned int);\ndiff -ru git-current/pack-check.c git-modified/pack-check.c\n--- git-current/pack-check.c\t2005-08-09 18:00:07.000000000 +0300\n+++ git-modified/pack-check.c\t2005-08-09 17:46:24.084918180 +0300\n@@ -15,7 +15,7 @@\n \t/* Header consistency check */\n \thdr = p->pack_base;\n \tif (hdr->hdr_signature != htonl(PACK_SIGNATURE))\n-\t\treturn error(\"Packfile signature mismatch\", p->pack_name);\n+\t\treturn error(\"Packfile %s signature mismatch\", p->pack_name);\n \tif (hdr->hdr_version != htonl(PACK_VERSION))\n \t\treturn error(\"Packfile version %d different from ours %d\",\n \t\t\t     ntohl(hdr->hdr_version), PACK_VERSION);\ndiff -ru git-current/pkt-line.h git-modified/pkt-line.h\n--- git-current/pkt-line.h\t2005-08-09 18:00:07.000000000 +0300\n+++ git-modified/pkt-line.h\t2005-08-09 18:02:56.637125022 +0300\n@@ -5,7 +5,7 @@\n  * Silly packetized line writing interface\n  */\n void packet_flush(int fd);\n-void packet_write(int fd, const char *fmt, ...);\n+void packet_write(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));\n \n int packet_read_line(int fd, char *buffer, unsigned size);\n \ndiff -ru git-current/refs.c git-modified/refs.c\n--- git-current/refs.c\t2005-08-09 18:00:07.000000000 +0300\n+++ git-modified/refs.c\t2005-08-09 17:53:25.318217137 +0300\n@@ -6,7 +6,7 @@\n static int read_ref(const char *refname, unsigned char *sha1)\n {\n \tint ret = -1;\n-\tint fd = open(git_path(refname), O_RDONLY);\n+\tint fd = open(git_path(\"%s\", refname), O_RDONLY);\n \n \tif (fd >= 0) {\n \t\tchar buffer[60];\n@@ -20,7 +20,7 @@\n static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1))\n {\n \tint retval = 0;\n-\tDIR *dir = opendir(git_path(base));\n+\tDIR *dir = opendir(git_path(\"%s\", base));\n \n \tif (dir) {\n \t\tstruct dirent *de;\n@@ -46,7 +46,7 @@\n \t\t\tif (namelen > 255)\n \t\t\t\tcontinue;\n \t\t\tmemcpy(path + baselen, de->d_name, namelen+1);\n-\t\t\tif (lstat(git_path(path), &st) < 0)\n+\t\t\tif (lstat(git_path(\"%s\", path), &st) < 0)\n \t\t\t\tcontinue;\n \t\t\tif (S_ISDIR(st.st_mode)) {\n \t\t\t\tretval = do_for_each_ref(path, fn);\ndiff -ru git-current/tar-tree.c git-modified/tar-tree.c\n--- git-current/tar-tree.c\t2005-08-09 18:00:07.000000000 +0300\n+++ git-modified/tar-tree.c\t2005-08-09 17:49:27.512564400 +0300\n@@ -325,8 +325,8 @@\n \tmemcpy(&header[257], \"ustar\", 6);\n \tmemcpy(&header[263], \"00\", 2);\n \n-\tprintf(&header[329], \"%07o\", 0);\t/* devmajor */\n-\tprintf(&header[337], \"%07o\", 0);\t/* devminor */\n+\tsprintf(&header[329], \"%07o\", 0);\t/* devmajor */\n+\tsprintf(&header[337], \"%07o\", 0);\t/* devminor */\n \n \tmemset(&header[148], ' ', 8);\n \tfor (i = 0; i < RECORDSIZE; i++)\n\n"},{"id":"6997","messageId":"1123611087.21306.48.camel@hurina","threadId":"1461","inReplyTo":"1123601422.21306.46.camel@hurina","subject":"Re: [PATCH] -Werror fixes","fromName":"Timo Sirainen","fromEmail":"tss@iki.fi","sentAt":"2005-08-09T18:11:27Z","receivedAt":"2005-08-09T18:11:27Z","isPatch":true,"sender":{"key":"tss@iki.fi","avatar":null},"body":"On Tue, 2005-08-09 at 18:30 +0300, Timo Sirainen wrote:\n> GCC's format __attribute__ is good for checking errors, especially with\n> -Werror=2 parameter. Patch below fixes most of the reported problems\n> against 2005-08-09 snapshot.\n\nEh. -Wformat=2 of course. What was I thinking..\n\n"}]}