From e29a2fd903c9de607d306ff7a6f10c64e32d3002 Mon Sep 17 00:00:00 2001 From: Ted Turocy Date: Tue, 7 Jun 2011 10:33:05 +0100 Subject: [PATCH 1/6] Correct printf output specifications. Corrected printf outputs specifiations: * Use %ld instead of %d or %u for (non-unsigned) long int * Explicitly cast size_t to unsigned long for display. --- alloc.c | 3 ++- leaves.c | 2 +- main.c | 8 ++++---- mp.c | 10 +++++----- mp.h | 2 +- treedef.c | 12 ++++++------ treegen.c | 2 +- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/alloc.c b/alloc.c index e6759ff..931ed07 100644 --- a/alloc.c +++ b/alloc.c @@ -15,7 +15,8 @@ void *tmp; tmp = calloc(n, s); if (tmp==NULL) { - fprintf(stderr, "Failure to allocate %d objects of %d bytes ", n, s); + fprintf(stderr, "Failure to allocate %lu objects of %lu bytes ", + (unsigned long) n, (unsigned long) s); fprintf(stderr, "on line %d of %s\n", l, f); fprintf(stderr, "Emergency stop.\n"); exit(1); diff --git a/leaves.c b/leaves.c index 0cbdb32..c50a9c0 100644 --- a/leaves.c +++ b/leaves.c @@ -104,7 +104,7 @@ void outleavesreached (int docuseed) if ( reachprob.num ) /* nonzero probability of reaching leaf */ { rattoa(reachprob, s); - printf(" %d~%s", o - outcomes, s) ; + printf(" %ld~%s", o - outcomes, s) ; } } printf("\n") ; diff --git a/main.c b/main.c index b28b688..71946cb 100644 --- a/main.c +++ b/main.c @@ -118,13 +118,13 @@ int stopwatch(Bool bprint) void infotree() { int pl; - printf("\nGame tree has %d nodes, ", lastnode - root); - printf("of which %d are terminal nodes.\n", lastoutcome - outcomes); + printf("\nGame tree has %ld nodes, ", lastnode - root); + printf("of which %ld are terminal nodes.\n", lastoutcome - outcomes); for (pl = 0; pl < PLAYERS; pl++) { printf(" Player %d has ", pl); - printf("%3d information sets, ", firstiset[pl+1] - firstiset[pl]); - printf("%3d moves in total\n", firstmove[pl+1] - firstmove[pl] - 1); + printf("%3ld information sets, ", firstiset[pl+1] - firstiset[pl]); + printf("%3ld moves in total\n", firstmove[pl+1] - firstmove[pl] - 1); } } diff --git a/mp.c b/mp.c index f344039..ec5b805 100644 --- a/mp.c +++ b/mp.c @@ -118,12 +118,12 @@ void prat(char name[],mp Nt,mp Dt) /*print the long precision rational Nt/Dt * long i; printf("%s",name); if (sign(Nt)==NEG) printf("-"); - printf("%u",Nt[length(Nt)-1]); + printf("%ld",Nt[length(Nt)-1]); for (i=length(Nt)-2;i>=1;i--) printf(FORMAT,Nt[i]); if( !(Dt[0]==2 && Dt[1]==1)) /* rational */ { printf("/"); if (sign(Dt)==NEG) printf("-"); - printf("%u",Dt[length(Dt)-1]); + printf("%ld",Dt[length(Dt)-1]); for (i=length(Dt)-2;i>=1;i--) printf(FORMAT,Dt[i]); } printf(" "); @@ -146,7 +146,7 @@ void pmp(char name[],mp a) /*print the long precision integer a*/ long i; printf("%s",name); if (sign(a)==NEG) printf("-"); - printf("%u",a[length(a)-1]); + printf("%ld",a[length(a)-1]); for (i=length(a)-2;i>=1;i--) printf(FORMAT,a[i]); } @@ -157,7 +157,7 @@ int mptoa(mp x, char s[]) int i, pos=0; if (sign(x)==NEG) pos = sprintf(s, "-"); -pos += sprintf(&s[pos], "%u", x[length(x)-1] ); +pos += sprintf(&s[pos], "%ld", x[length(x)-1] ); for (i=length(x)-2; i>=1; i--) pos += sprintf(&s[pos], FORMAT, x[i]); return pos; @@ -576,7 +576,7 @@ void divint(mp a, mp b, mp c ) void digits_overflow() { - printf("Overflow at digits=%d\n",DIG2DEC(digits)); + printf("Overflow at digits=%ld\n",DIG2DEC(digits)); exit(1); } diff --git a/mp.h b/mp.h index 98cfd28..6f092fd 100644 --- a/mp.h +++ b/mp.h @@ -16,7 +16,7 @@ /***********************************************/ #ifndef B64 /*32 bit machines */ -#define FORMAT "%4.4u" +#define FORMAT "%4.4ld" #define MAXD 2147483647L #define BASE 10000L #define BASE_DIG 4 diff --git a/treedef.c b/treedef.c index 4403b23..cc01305 100644 --- a/treedef.c +++ b/treedef.c @@ -91,9 +91,9 @@ Bool genseqin(void) /* tree is not topologically sorted */ { isnotok = 1; - printf("tree not topologically sorted: father %d ", + printf("tree not topologically sorted: father %ld ", u->father - nodes); - printf("is larger than node %d itself.\n", u - nodes); + printf("is larger than node %ld itself.\n", u - nodes); } /* update sequence triple, new only for move leading to u */ @@ -113,10 +113,10 @@ Bool genseqin(void) { isnotok = 1; /* need output routines for isets, moves, later */ - printf("imperfect recall in info set no. %d ", h-isets); + printf("imperfect recall in info set no. %ld ", h-isets); printf("named %s\n", h->name); - printf("different sequences no. %d,", seq-moves); - printf(" %d\n", h->seqin-moves); + printf("different sequences no. %ld,", seq-moves); + printf(" %ld\n", h->seqin-moves); } } /* end of "u decision node" */ } /* end of "for all nodes u" */ @@ -184,7 +184,7 @@ int movetoa (Move c, int pl, char *s) return sprintf(s, "*"); if (c == firstmove[pl]) return sprintf(s, "()"); - return sprintf(s, "%s%d", c->atiset->name, c - c->atiset->move0); + return sprintf(s, "%s%ld", c->atiset->name, c - c->atiset->move0); } /* end of int movetoa (c, pl, *s) */ int seqtoa (Move seq, int pl, char *s) diff --git a/treegen.c b/treegen.c index 3155305..9f71700 100644 --- a/treegen.c +++ b/treegen.c @@ -116,7 +116,7 @@ void createbintree (int levels, int seed) } /* consistency check */ if (currout != lastoutcome) - printf("wrong number %d of outcomes!!!\n", currout-outcomes ); + printf("wrong number %ld of outcomes!!!\n", currout-outcomes ); } /* end of createbintree(levels, seed) */ From 57d28a0656d5d3708e8718a081cb59954848ad96 Mon Sep 17 00:00:00 2001 From: Ted Turocy Date: Tue, 7 Jun 2011 10:36:23 +0100 Subject: [PATCH 2/6] Add void return specifications for functions returning void. --- mp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mp.c b/mp.c index ec5b805..4cdd4ce 100644 --- a/mp.c +++ b/mp.c @@ -588,7 +588,7 @@ void digits_overflow() /***************************************************************/ -linrat(Na,Da,ka,Nb,Db,kb,Nc,Dc) +void linrat(Na,Da,ka,Nb,Db,kb,Nc,Dc) /* computes Nc/Dc = ka*Na/Da +kb* Nb/Db and reduces answer by gcd(Nc,Dc) */ mp Na,Da,Nb,Db,Nc,Dc; @@ -603,7 +603,7 @@ reduce(Nc,Dc); } -divrat(Na,Da,Nb,Db,Nc,Dc) +void divrat(Na,Da,Nb,Db,Nc,Dc) /* computes Nc/Dc = (Na/Da) / ( Nb/Db ) and reduces answer by gcd(Nc,Dc) */ mp Na,Da,Nb,Db,Nc,Dc; @@ -614,7 +614,7 @@ reduce(Nc,Dc); } -mulrat(Na,Da,Nb,Db,Nc,Dc) +void mulrat(Na,Da,Nb,Db,Nc,Dc) /* computes Nc/Dc = Na/Da * Nb/Db and reduces answer by gcd(Nc,Dc) */ mp Na,Da,Nb,Db,Nc,Dc; From c7d165db8d6e32170a6c2e63c006a0dd808ea9fe Mon Sep 17 00:00:00 2001 From: Ted Turocy Date: Tue, 7 Jun 2011 10:37:36 +0100 Subject: [PATCH 3/6] Use parentheses to surround && when used with || to clarify order of ops. --- mp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mp.c b/mp.c index 4cdd4ce..3d0d0ab 100644 --- a/mp.c +++ b/mp.c @@ -197,7 +197,7 @@ void gcd(mp u, mp v) bigu: if(zero(v)) return; - if ((i=length(u)) Date: Tue, 7 Jun 2011 10:38:50 +0100 Subject: [PATCH 4/6] Surround unused function with #ifdef UNUSED. --- leaves.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/leaves.c b/leaves.c index c50a9c0..3cd2355 100644 --- a/leaves.c +++ b/leaves.c @@ -14,6 +14,7 @@ #include "leaves.h" /* test if input properly processed by generating what should be an echo */ +#ifdef UNUSED static void testreadequil (int docuseed) { printf("BEQ>%4d<1>", docuseed); @@ -21,6 +22,7 @@ static void testreadequil (int docuseed) printf(" <2>"); outbehavstrat(2, realplan[2], 1); } +#endif /* UNUSED */ void leavesfrominput (void) { From 6fe2370d556640ea97dc90409a8b8588dfa825a0 Mon Sep 17 00:00:00 2001 From: Ted Turocy Date: Tue, 7 Jun 2011 10:39:46 +0100 Subject: [PATCH 5/6] Add stdlib.h to properly declare exit() --- gambit.c | 1 + interface.c | 1 + 2 files changed, 2 insertions(+) diff --git a/gambit.c b/gambit.c index 2a8d231..3e3f1d5 100644 --- a/gambit.c +++ b/gambit.c @@ -4,6 +4,7 @@ */ #include +#include #include "rat.h" #include "treedef.h" diff --git a/interface.c b/interface.c index b55256b..b9ed8b8 100644 --- a/interface.c +++ b/interface.c @@ -4,6 +4,7 @@ */ #include +#include #include "rat.h" #include "treedef.h" /* PLAYERS */ From d3845111c8a64e2223b43e7592921d0dd56da7ca Mon Sep 17 00:00:00 2001 From: Ted Turocy Date: Tue, 7 Jun 2011 10:41:22 +0100 Subject: [PATCH 6/6] Explicit initialization of local variables where required. --- main.c | 2 +- rsf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 71946cb..d308b3d 100644 --- a/main.c +++ b/main.c @@ -324,7 +324,7 @@ int main(int argc, char *argv[]) int multipriors = 0; /* parameter for -M option */ int seed = 0; /* payoff seed for bintree (-s option) */ int newpayoffs = 0; /* number of payoffs to be replaced (-p)*/ - int *newp1, *newp2; /* arrays for entering new payoffs */ + int *newp1 = 0, *newp2 = 0; /* arrays for entering new payoffs */ /* whichform currently not used (later for RSF) */ int whichform = 0; /* 0: SF, 1: NF, 2: RSF */ diff --git a/rsf.c b/rsf.c index 9aca88f..36861e0 100644 --- a/rsf.c +++ b/rsf.c @@ -34,7 +34,7 @@ void genredsf(int pl) int i, j; /* row, column counters */ int cdim; /* dimension of c-matrix, = no. redundant vars */ int drow; /* last filled row of d-matrix for irredundant vars */ - Iset h, lasthinc; + Iset h = 0, lasthinc = 0; Move seq; /* inverse of matrix of dependent variables, local */ int ** depvarinv;