-Werror fixes
PATCH 1/1 -Werror fixes
GCC's format __attribute__ is good for checking errors, especially with -Werror=2 parameter. Patch below fixes most of the reported problems against 2005-08-09 snapshot.
Also how about trying to implement some kind of generically usable string object? Now the code uses sprintf/snprintf/etc. in various different ways with their own memory allocations, and it looks all messy and difficult to verify their correctness.
apply.c +2 -2
@@ -563,7 +563,7 @@struct fragment dummy;if (parse_fragment_header (line, len, &dummy) <0 )continue ; -error ("patch fragment without header at line %d: %.*s" , linenr, len-1 , line); +error ("patch fragment without header at line %d: %.*s" , linenr, (int )len-1 , line); }if (size < len +6 )
@@ -968,7 +968,7 @@while (frag) {if (apply_one_fragment (desc, frag) <0 ) -return error ("patch failed: %s:%d" , patch->old_name, frag->oldpos); +return error ("patch failed: %s:%ld" , patch->old_name, frag->oldpos); frag = frag->next; }return 0 ;
cache.h +8 -4
@@ -40,6 +40,10 @@#define NORETURN #endif +#ifndef __attribute__ +#define __attribute (x) +#endif +/* * Intensive research over the course of many years has shown that * port 9418 is totally unused by anything else. Or
@@ -171,8 +175,8 @@#define TYPE_CHANGED 0x0040/* Return a statically allocated filename matching the sha1 signature */ -extern char *mkpath (const char *fmt, ...); -extern char *git_path (const char *fmt, ...); +extern char *mkpath (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +extern char *git_path (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));extern char *sha1_file_name (const unsigned char *sha1);extern char *sha1_pack_name (const unsigned char *sha1);extern char *sha1_pack_index_name (const unsigned char *sha1);
@@ -218,8 +222,8 @@/* General helper functions */ extern void usage(const char *err) NORETURN; -extern void die(const char *err, ...) NORETURN; -extern int error (const char *err, ...); +extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern int base_name_compare (const char *name1,int len1,int mode1,const char *name2,int len2,int mode2);extern int cache_name_compare (const char *name1,int len1,const char *name2,int len2);
clone-pack.c +1 -1
@@ -30,7 +30,7 @@static void write_one_ref (struct ref *ref) { -char *path =git_path (ref->name); +char *path =git_path ("%s" , ref->name);int fd;char *hex;
connect.c +2 -1
@@ -166,7 +166,8 @@if (matched_src)break ; errs =1 ; -error ("src refspec %s does not match any." ); +error ("src refspec %s does not match any." , + rs[i].src);break ;default : errs =1 ;
csum-file.h +1 -1
@@ -11,7 +11,7 @@ };extern struct sha1file *sha1fd (int fd,const char *name); -extern struct sha1file *sha1create (const char *fmt, ...); +extern struct sha1file *sha1create (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));extern int sha1close (struct sha1file *,unsigned char *,int );extern int sha1write (struct sha1file *,void *,unsigned int );extern int sha1write_compressed (struct sha1file *,void *,unsigned int );
pack-check.c +1 -1
@@ -15,7 +15,7 @@/* Header consistency check */ hdr = p->pack_base;if (hdr->hdr_signature !=htonl (PACK_SIGNATURE )) -return error ("Packfile signature mismatch" , p->pack_name); +return error ("Packfile %s signature mismatch" , p->pack_name);if (hdr->hdr_version !=htonl (PACK_VERSION ))return error ("Packfile version %d different from ours %d" ,ntohl (hdr->hdr_version),PACK_VERSION );
pkt-line.h +1 -1
@@ -5,7 +5,7 @@* Silly packetized line writing interface */ void packet_flush (int fd); -void packet_write (int fd,const char *fmt, ...); +void packet_write (int fd,const char *fmt, ...) __attribute__((format (printf,2 ,3 )));int packet_read_line (int fd,char *buffer,unsigned size);
refs.c +3 -3
@@ -6,7 +6,7 @@static int read_ref (const char *refname,unsigned char *sha1) {int ret =-1 ; -int fd =open (git_path (refname),O_RDONLY ); +int fd =open (git_path ("%s" , refname),O_RDONLY );if (fd >=0 ) {char buffer[60 ];
@@ -20,7 +20,7 @@static int do_for_each_ref (const char *base,int (*fn)(const char *path,const unsigned char *sha1)) {int retval =0 ; -DIR *dir =opendir (git_path (base)); +DIR *dir =opendir (git_path ("%s" , base));if (dir) {struct dirent *de;
@@ -46,7 +46,7 @@if (namelen >255 )continue ;memcpy (path + baselen, de->d_name, namelen+1 ); -if (lstat (git_path (path), &st) <0 ) +if (lstat (git_path ("%s" , path), &st) <0 )continue ;if (S_ISDIR (st.st_mode)) { retval =do_for_each_ref (path, fn);
tar-tree.c +2 -2
@@ -325,8 +325,8 @@memcpy (&header[257 ],"ustar" ,6 );memcpy (&header[263 ],"00" ,2 ); -printf (&header[329 ],"%07o" ,0 );/* devmajor */ -printf (&header[337 ],"%07o" ,0 );/* devminor */ +sprintf (&header[329 ],"%07o" ,0 );/* devmajor */ +sprintf (&header[337 ],"%07o" ,0 );/* devminor */ memset (&header[148 ],' ' ,8 );for (i =0 ; i <RECORDSIZE ; i++)
Quoted 3 lines · Timo Sirainen
GCC's format
__attribute__is good for checking errors, especially with -Werror=2 parameter. Patch below fixes most of the reported problems against 2005-08-09 snapshot.
Eh. -Wformat=2 of course. What was I thinking..