From e2bfb6322ce9f4323b83469dc06dd1ce1b0f4cf6 Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Sat, 2 Feb 2013 02:09:25 -0500 Subject: Clean up warnings Eliminate compiler warnings due to various issues (listed below). This allows Zephyr to build cleanly under GCC versions ranging from 4.1.0 to 4.7.2 with all of the options shown below: -g -O2 -Wall -Werror -Wno-deprecated-declarations -Wmissing-declarations -Wpointer-arith -Wstrict-prototypes -Wshadow -Wextra -Wno-missing-field-initializers -Wno-unused-parameter and, on recent versions, -Wunreachable-code Test builds were done - On Ubuntu 12.10 (Quantal Quetzal) using both MIT Kerberos 1.10.1 and Heimdal 1.6, without krb4 and both with and without C-Ares and Hesiod - On Fedora 14 using Heimdal 0.6, without C-Ares or Hesiod and both with and without krb4 (KTH Kerberos 1.3rc2) - On Fedora Core 3, Fedora Core 5, Fedora 7, and Fedora 10, using Heimdal 0.6 and without C-Ares, Hesiod, or krb4 It also allows clean builds on Solaris 10 under the Sun Studio 12 (9/07) C compiler with the following options: -g -fd -v -errfmt -errhdr=%user -errtags=yes -errwarn=%all -erroff=E_OLD_STYLE_FUNC_DECL,E_ENUM_TYPE_MISMATCH_ARG,E_ARG_INCOMPATIBLE_WITH_ARG ... and under Solaris 9 with the Sun Forte 7 (3/02) C compiler with the above options and -erroff=E_FUNC_HAS_NO_RETURN_STMT. Solaris builds were done with Heimdal 0.6 and without C-Ares, Hesiod, or krb4. The following types of issues are addressed in this change: - Parameters and local variables with the same names as library functions - Parameters and local variables with the same names as globals - Declarations for exported global variables missing from headers - Prototypes for exported functions missing from headers - Missing 'static' on functions that shouldn't be exported - Old-style function declarations - Duplicate declarations - Type mismatches - Unused variables and functions - Uninitialized variables - Forward references to enums - Necessary header files not included - Violations of the aliasing rules, where GCC was able to detect them - Missing braces on if blocks that might be empty - Attempts to do pointer arithmetic on pointers of type void *, which is not permitted in standard C. - An attempt to pass a function pointer via a void * parameter, which is not permitted in standard C. Instead, we now pass a pointer to a structure, which then contains the required function pointer. - Unnecessary inclusion of , which is already included by when the former exists, and might not be protected against double inclusion, depending on which com_err was used. - Missing include of , which was masked by the fact that it is included by headers generated by e2fsprogs compile_et - Use of com_err() with a non-constant value in place of the format string, which in every case was a fixed-size buffer in which a message was built using sprintf(!). Both the calls to sprintf and the fixed-size buffers have been removed, in favor of just letting com_err() do the formatting. - Various cases where X library functions expecting a parameter of type wchar_t * were instead passed a parameter of type XChar2b *. The two types look similar, but are not the same and are _not_ interchangeable. - An overly-simplistic configure test which failed to detect existence of on Solaris, due to not including . - Using the wrong type for the flags output of krb5_auth_con_getflags() when building against Heimdal. A configure test is added to detect the correct type. --- clients/zaway/zaway.c | 5 +- clients/zctl/zctl.c | 118 +++++++++++++++------------- clients/zlocate/zlocate.c | 6 +- clients/zshutdown_notify/zshutdown_notify.c | 2 +- clients/zstat/zstat.c | 6 +- clients/zwrite/zwrite.c | 8 +- 6 files changed, 74 insertions(+), 71 deletions(-) (limited to 'clients') diff --git a/clients/zaway/zaway.c b/clients/zaway/zaway.c index 684609c..cb72c34 100644 --- a/clients/zaway/zaway.c +++ b/clients/zaway/zaway.c @@ -23,10 +23,12 @@ static const char rcsid_zaway_c[] = "$Id$"; #define DEFAULT_MSG "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n" #define RESPONSE_OPCODE "" +static char *find_message(ZNotice_t *, FILE *); + RETSIGTYPE cleanup(int); u_short port; -void +static void usage(char *name) { printf("Usage: %s [OPTIONS] [FILE]\n" @@ -51,7 +53,6 @@ main(int argc, int optchar, watch_location; char *cmdline_msg; int nlocs; - char *find_message(ZNotice_t *, FILE *); char *charset = NULL; unsigned short zcharset; diff --git a/clients/zctl/zctl.c b/clients/zctl/zctl.c index 599e146..706f3cd 100644 --- a/clients/zctl/zctl.c +++ b/clients/zctl/zctl.c @@ -66,6 +66,27 @@ static void run_command(int, char *[]); static void show_commands(int, char *[]); #endif +/* Prototype all of the commands. + * These really should be in a header also visible to zctl_cmds.c, + * but mk_cmds doesn't make that easy. + */ +void cancel_subs(int argc, char *argv[]); +void current(int argc, char *argv[]); +void do_hide(int argc, char *argv[]); +void do_punt(int argc, char *argv[]); +void flush_locations(int argc, char *argv[]); +void hm_control(int argc, char *argv[]); +void list_punts(int argc, char *argv[]); +void load_subs(int argc, char *argv[]); +void set_file(int argc, char *argv[]); +void set_var(int argc, char *argv[]); +void show_var(int argc, char *argv[]); +void sub_file(int argc, char *argv[]); +void subscribe(int argc, char *argv[]); +void unset_var(int argc, char *argv[]); +void wgc_control(int argc, char *argv[]); + + int main(int argc, char *argv[]) @@ -547,22 +568,19 @@ add_file(short wgport, int unsub) { FILE *fp; - char errbuf[BUFSIZ]; ZSubscription_t sub2; Code_t retval; (void) purge_subs(subs,ALL); /* remove copies in the subs file */ if (!(fp = fopen(subsname,"a"))) { - (void) sprintf(errbuf,"while opening %s for append",subsname); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while opening %s for append", subsname); return; } fprintf(fp,"%s%s,%s,%s\n", unsub ? "!" : "", subs->zsub_class, subs->zsub_classinst, subs->zsub_recipient); if (fclose(fp) == EOF) { - (void) sprintf(errbuf, "while closing %s", subsname); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while closing %s", subsname); return; } fix_macros(subs,&sub2,1); @@ -605,7 +623,7 @@ purge_subs(register ZSubscription_t *subs, int which) { FILE *fp,*fpout; - char errbuf[BUFSIZ],subline[BUFSIZ]; + char subline[BUFSIZ]; char backup[BUFSIZ],ourline[BUFSIZ]; int delflag = NOT_REMOVED; int keep = 0; @@ -626,16 +644,14 @@ purge_subs(register ZSubscription_t *subs, subs->zsub_recipient); if (!(fp = fopen(subsname,"r"))) { - (void) sprintf(errbuf,"while opening %s for read",subsname); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while opening %s for read", subsname); return(ERR); } (void) strcpy(backup, subsname); (void) strcat(backup, ".temp"); (void) unlink(backup); if (!(fpout = fopen(backup,"w"))) { - (void) sprintf(errbuf,"while opening %s for writing",backup); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while opening %s for writing", backup); (void) fclose(fp); return(ERR); } @@ -660,23 +676,20 @@ purge_subs(register ZSubscription_t *subs, if (keep) { fputs(subline, fpout); if (ferror(fpout) || (fputc('\n', fpout) == EOF)) { - (void) sprintf(errbuf, "while writing to %s", - backup); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while writing to %s", + backup); } } else delflag = REMOVED; } (void) fclose(fp); /* open read-only, ignore errs */ if (fclose(fpout) == EOF) { - (void) sprintf(errbuf, "while closing %s",backup); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while closing %s", backup); return(ERR); } if (rename(backup,subsname) == -1) { - (void) sprintf(errbuf,"while renaming %s to %s\n", - backup,subsname); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while renaming %s to %s\n", + backup, subsname); return(ERR); } return(delflag); @@ -823,8 +836,8 @@ load_subs(int argc, #ifdef CMU_ZCTL_PUNT if (pind == SUBSATONCE) { fix_macros(punts,subs2,pind); - if (retval = ZPunt(subs2,pind,(u_short)wgport) != - ZERR_NONE) + if ((retval = ZPunt(subs2,pind,(u_short)wgport) != + ZERR_NONE)) { com_err(whoami, retval, "while punting"); @@ -895,8 +908,8 @@ load_subs(int argc, #ifdef CMU_ZCTL_PUNT if (pind) { fix_macros(punts,subs2,pind); - if (retval = ZPunt(subs2,pind,(u_short)wgport) != - ZERR_NONE) + if ((retval = ZPunt(subs2,pind,(u_short)wgport) != + ZERR_NONE)) { com_err(whoami,retval, "while punting"); @@ -933,7 +946,6 @@ current(int argc, char *argv[]) { FILE *fp = NULL; - char errbuf[BUFSIZ]; ZSubscription_t subs; int i,nsubs,retval,save,one,defs; short wgport; @@ -983,9 +995,8 @@ current(int argc, (void) strcpy(backup,file); (void) strcat(backup,".temp"); if (!(fp = fopen(backup,"w"))) { - (void) sprintf(errbuf,"while opening %s for write", - backup); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while opening %s for write", + backup); return; } } @@ -1012,14 +1023,12 @@ current(int argc, if (save) { if (fclose(fp) == EOF) { - (void) sprintf(errbuf, "while closing %s", backup); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while closing %s", backup); return; } if (rename(backup,file) == -1) { - (void) sprintf(errbuf,"while renaming %s to %s", - backup,file); - com_err(whoami, retval, errbuf); + com_err(whoami, retval, "while renaming %s to %s", + backup, file); (void) unlink(backup); } } @@ -1028,21 +1037,18 @@ current(int argc, int make_exist(char *filename) { - char errbuf[BUFSIZ]; FILE *fpout; if (!access(filename,F_OK)) return (0); if (!(fpout = fopen(filename,"w"))) { - (void) sprintf(errbuf,"while opening %s for write",filename); - com_err(whoami, errno, errbuf); + com_err(whoami, errno,"while opening %s for write", filename); return (1); } if (fclose(fpout) == EOF) { - (void) sprintf(errbuf, "while closing %s", filename); - com_err(whoami, errno, errbuf); + com_err(whoami, errno, "while closing %s", filename); return(1); } return (0); @@ -1078,17 +1084,17 @@ fix_macros2(char *src, char **dest) *dest = ZGetSender(); } -int -do_punt(int argc, char **argv) +void +do_punt(int argc, char *argv[]) { #ifdef CMU_ZCTL_PUNT - char *class, *inst, *recip, *msg, *whoami = argv[0]; + char *class, *inst, *recip, *msg, *cmd = argv[0]; int retval, punt; short newport; struct sockaddr_in newsin; ZNotice_t notice; - if (! strcmp(whoami, "punt")) punt = 1; + if (! strcmp(cmd, "punt")) punt = 1; else punt = 0; switch (argc) { @@ -1114,28 +1120,28 @@ do_punt(int argc, char **argv) break; default: fprintf(stderr, "Usages:\n"); - fprintf(stderr, "\t%s instance\n", whoami); - fprintf(stderr, "\t%s class instance\n", whoami); - fprintf(stderr, "\t%s class instance recipient\n", whoami); - return 1; + fprintf(stderr, "\t%s instance\n", cmd); + fprintf(stderr, "\t%s class instance\n", cmd); + fprintf(stderr, "\t%s class instance recipient\n", cmd); + return; } retval = ZOpenPort((u_short *) 0); if(retval != ZERR_NONE) { com_err(whoami, retval, "while opening Zephyr port."); - return 1; + return; } newsin = ZGetDestAddr(); if ((newport = ZGetWGPort()) == -1) { fprintf(stderr, "%s: Can't find windowgram port\n", whoami); - return 1; + return; } newsin.sin_port = (unsigned short) newport; if ((retval = ZSetDestAddr(&newsin)) != ZERR_NONE) { com_err(whoami,retval,"while setting destination address"); - return 1; + return; } msg = (char *) malloc(strlen(class) + strlen(inst) + strlen(recip) + 4); @@ -1167,15 +1173,15 @@ do_punt(int argc, char **argv) ZClosePort(); #endif - return 0; + return; } -int -list_punts(int argc, char **argv) +void +list_punts(int argc, char *argv[]) { #ifdef CMU_ZCTL_PUNT ZNotice_t notice; - int retval, lensofar; + int retval; struct sockaddr_in old, to, from; u_short ourport, zwgcport; char *msg; @@ -1184,20 +1190,20 @@ list_punts(int argc, char **argv) retval = ZOpenPort(&ourport); if(retval != ZERR_NONE) { com_err("zctl", retval, "while opening Zephyr port."); - return 1; + return; } old = ZGetDestAddr(); to = old; if ((zwgcport = ZGetWGPort()) == (u_short)-1) { fprintf(stderr, "zctl: Can't find windowgram port\n"); - return 1; + return; } to.sin_port = (u_short) zwgcport; if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { com_err("zctl",retval,"while setting destination address"); - return 1; + return; } memset((char *) ¬ice, 0, sizeof(ZNotice_t)); @@ -1226,7 +1232,7 @@ list_punts(int argc, char **argv) if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { com_err("zctl",retval,"while resetting destination address"); - return 1; + return; } msg = (char *) malloc((notice.z_message_len+1) * sizeof(char)); @@ -1238,7 +1244,7 @@ list_punts(int argc, char **argv) (void) ZClosePort(); #endif /* CMU_ZCTL_PUNT */ - return 0; + return; } #ifndef HAVE_SS diff --git a/clients/zlocate/zlocate.c b/clients/zlocate/zlocate.c index 9f048f3..0ade6a0 100644 --- a/clients/zlocate/zlocate.c +++ b/clients/zlocate/zlocate.c @@ -21,21 +21,21 @@ static const char rcsid_zlocate_c[] = "$Id$"; int numusers=0, numleft=0, parallel=0, oneline=0; char *whoami; -RETSIGTYPE +static RETSIGTYPE timeout(int sig) { fprintf (stderr, "%s: no response from server\n", whoami); exit(1); } -void +static void usage(void) { printf("Usage: %s [ -a | -d ] [ -p ] [ -1 ] user ... \n",whoami); exit(1); } -void +static void print_locs(char *user, int nlocs) { diff --git a/clients/zshutdown_notify/zshutdown_notify.c b/clients/zshutdown_notify/zshutdown_notify.c index a682abf..2f51cc0 100644 --- a/clients/zshutdown_notify/zshutdown_notify.c +++ b/clients/zshutdown_notify/zshutdown_notify.c @@ -92,7 +92,7 @@ main(int argc, } retval = krb_get_svc_in_tkt(SVC_NAME, hn2, rlm, SERVER_SERVICE, SERVER_INSTANCE, 1, - KEYFILE); + (char *)KEYFILE); if (retval) { fprintf(stderr, "%s: can't get tickets: %s\n", argv[0], krb_get_err_text(retval)); diff --git a/clients/zstat/zstat.c b/clients/zstat/zstat.c index c18bb60..7ae5954 100644 --- a/clients/zstat/zstat.c +++ b/clients/zstat/zstat.c @@ -55,7 +55,7 @@ void do_stat(char *); int srv_stat(char *); int hm_stat(char *, char *); -RETSIGTYPE +static RETSIGTYPE timeout(int ignored) { outoftime = 1; @@ -69,8 +69,6 @@ main(int argc, char hostname[NS_MAXDNAME]; int optchar; struct servent *sp; - extern char *optarg; - extern int optind; if ((ret = ZInitialize()) != ZERR_NONE) { com_err("zstat", ret, "initializing"); @@ -145,7 +143,7 @@ hm_stat(char *host, Code_t code; char *line[20],*mp; - int i,nf; + unsigned int i,nf; struct hostent *hp; time_t runtime; struct tm *tim; diff --git a/clients/zwrite/zwrite.c b/clients/zwrite/zwrite.c index 41d2bf3..49dd06a 100644 --- a/clients/zwrite/zwrite.c +++ b/clients/zwrite/zwrite.c @@ -344,7 +344,7 @@ void send_off(ZNotice_t *notice, int real) { int i, success, retval; - char bfr[BUFSIZ], realm_recip[BUFSIZ], dest[3 * BUFSIZ]; + char realm_recip[BUFSIZ], dest[3 * BUFSIZ]; ZNotice_t retnotice; success = 0; @@ -370,8 +370,7 @@ send_off(ZNotice_t *notice, int real) class, inst, nrecips?notice->z_recipient:"everyone"); if ((retval = ZSendNotice(notice, auth)) != ZERR_NONE) { - (void) sprintf(bfr, "while sending notice to %s", dest); - com_err(whoami, retval, bfr); + com_err(whoami, retval, "while sending notice to %s", dest); break; } if (real && !quiet) { @@ -384,9 +383,8 @@ send_off(ZNotice_t *notice, int real) if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *) 0, ZCompareUIDPred, (char *)¬ice->z_uid)) != ZERR_NONE) { - (void) sprintf(bfr, "while waiting for acknowledgement for %s", + com_err(whoami, retval, "while waiting for acknowledgement for %s", dest); - com_err(whoami, retval, bfr); continue; } if (retnotice.z_kind == SERVNAK) { -- cgit v1.2.3