From f62ebdc98272c778e3c92884e43bac0967e4e13a Mon Sep 17 00:00:00 2001 From: Michael Hampton Date: Thu, 17 Oct 2002 12:56:44 +0000 Subject: [PATCH] * Bug fixes: Fix numerous char array size mismatches, signed/unsigned mismatches, and const correctness problems (though not nearly all) --- citadel/ChangeLog | 5 +++++ citadel/citadel.c | 4 ++-- citadel/citadel.h | 18 +++++----------- citadel/citadel_decls.h | 4 ++-- citadel/commands.c | 8 +++---- citadel/commands.h | 4 ++-- citadel/file_ops.c | 2 +- citadel/md5.h | 1 + citadel/messages.c | 8 +++---- citadel/msgbase.c | 8 +++---- citadel/rooms.c | 13 +++++------ citadel/routines.c | 6 +++--- citadel/routines.h | 2 +- citadel/routines2.c | 2 +- citadel/routines2.h | 2 +- citadel/serv_upgrade.c | 6 +++--- citadel/serv_upgrade.h | 4 ++-- citadel/tools.c | 34 +++++++++++++++++++---------- citadel/tools.h | 15 +++++++------ citadel/typesize.h | 48 ++++++++++++++++++----------------------- citadel/user_ops.c | 6 +++--- 21 files changed, 103 insertions(+), 97 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 8fad209e2..2aae852e2 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,8 @@ $Log$ + Revision 601.33 2002/10/17 12:56:44 error + * Bug fixes: Fix numerous char array size mismatches, signed/unsigned + mismatches, and const correctness problems (though not nearly all) + Revision 601.32 2002/10/17 11:13:27 error * Convert room listings and some aide functions to new IPC code @@ -4093,3 +4097,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citadel.c b/citadel/citadel.c index 8e68bd10a..2c9230801 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -68,7 +68,7 @@ char tempdir[PATH_MAX]; /* Name of general temp dir */ char editor_path[SIZ]; /* path to external editor */ char printcmd[SIZ]; /* print command */ int editor_pid = (-1); -char fullname[32]; +char fullname[USERNAME_SIZE]; jmp_buf nextbuf; struct CtdlServInfo serv_info; /* Info on the server connected */ int screenwidth; @@ -91,7 +91,7 @@ long highest_msg_read; /* used for bandon room cmd */ long maxmsgnum; /* used for oto */ char sigcaught = 0; char have_xterm = 0; /* are we running on an xterm? */ -char rc_username[32]; +char rc_username[USERNAME_SIZE]; char rc_password[32]; char hostbuf[SIZ]; char portbuf[SIZ]; diff --git a/citadel/citadel.h b/citadel/citadel.h index a9f09d724..693d1cf47 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -13,6 +13,7 @@ #include "sysdep.h" #include #include "sysconfig.h" +#include "typesize.h" #include "ipcdef.h" #ifdef __cplusplus @@ -48,15 +49,6 @@ extern "C" { #define tolower(x) ( ((x>='A')&&(x<='Z')) ? (x+'a'-'A') : x ) #define NEW_CONFIG -/* - * The only typedef we do is an 8-bit unsigned, for screen dimensions. - * All other defs are done using standard C types. The code assumes that - * 'int' 'unsigned' and 'short' are at least 16 bits, and that 'long' is at - * least 32 bits. There are no endian dependencies in any of the Citadel - * programs. - */ -typedef unsigned char CIT_UBYTE; - /* Various length constants */ #define UGLISTLEN 100 /* you get a ungoto list of this size */ @@ -66,7 +58,7 @@ typedef unsigned char CIT_UBYTE; * in the nonce, as per the APOP RFC. */ -#define USERNAME_SIZE 32 /* The size of a username string */ +#define USERNAME_SIZE 64 /* The size of a username string */ /* * Message expiration policy stuff @@ -156,13 +148,13 @@ struct usersupp { /* User record */ unsigned flags; /* See US_ flags below */ long timescalled; /* Total number of logins */ long posted; /* Number of messages posted (ever) */ - CIT_UBYTE axlevel; /* Access level */ + cit_uint8_t axlevel; /* Access level */ long usernum; /* User number (never recycled) */ time_t lastcall; /* Last time the user called */ int USuserpurge; /* Purge time (in days) for user */ char fullname[64]; /* Name for Citadel messages & mail */ - CIT_UBYTE USscreenwidth; /* Screen width (for textmode users)*/ - CIT_UBYTE USscreenheight; /* Screen height(for textmode users)*/ + cit_uint8_t USscreenwidth; /* Screen width (for textmode users)*/ + cit_uint8_t USscreenheight; /* Screen height(for textmode users)*/ }; diff --git a/citadel/citadel_decls.h b/citadel/citadel_decls.h index 371aa5de6..dc36d7509 100644 --- a/citadel/citadel_decls.h +++ b/citadel/citadel_decls.h @@ -1,5 +1,5 @@ /* $Id$ */ -extern char fullname[32]; +extern char fullname[USERNAME_SIZE]; extern unsigned room_flags; extern char room_name[ROOMNAMELEN]; extern struct CtdlServInfo serv_info; @@ -10,7 +10,7 @@ extern char sigcaught; extern char editor_path[SIZ]; extern char printcmd[SIZ]; extern char have_xterm; -extern char rc_username[32]; +extern char rc_username[USERNAME_SIZE]; extern char rc_password[32]; extern char rc_floor_mode; extern time_t rc_idle_threshold; diff --git a/citadel/commands.c b/citadel/commands.c index 49c0710c4..4ae380c94 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -142,7 +142,7 @@ char was_a_key_pressed(void) { * we are probably in the middle of a server operation and the NOOP command * would confuse everything. */ -int checkpagin(int lp, int pagin, int height) +int checkpagin(int lp, unsigned int pagin, unsigned int height) { int thekey; @@ -1192,8 +1192,8 @@ void sttybbs(int cmd) live.c_oflag = OPOST | ONLCR; live.c_lflag = ISIG | NOFLSH; - live.c_cc[VINTR] = (-1); - live.c_cc[VQUIT] = (-1); + live.c_cc[VINTR] = 0; + live.c_cc[VQUIT] = 0; #ifdef hpux live.c_cc[VMIN] = 0; @@ -1269,7 +1269,7 @@ int fmout( char pagin, /* nonzero if we should use the paginator */ int height, /* screen height to use */ int starting_lp,/* starting value for lines_printed, -1 for global */ - char subst) /* nonzero if we should use hypertext mode */ + int subst) /* nonzero if we should use hypertext mode */ { int a, b, c, old; int real = (-1); diff --git a/citadel/commands.h b/citadel/commands.h index 6b15ddab9..8a4180b84 100644 --- a/citadel/commands.h +++ b/citadel/commands.h @@ -38,7 +38,7 @@ void strprompt(char *prompt, char *str, int len); int boolprompt(char *prompt, int prev_val); int intprompt(char *prompt, int ival, int imin, int imax); int fmout(int width, FILE *fpin, char *text, FILE *fpout, char pagin, - int height, int starting_lp, char subst); + int height, int starting_lp, int subst); int getcmd(CtdlIPC *ipc, char *argbuf); void display_help(CtdlIPC *ipc, char *name); void color(int colornum); @@ -54,7 +54,7 @@ void keyopt(char *); char keymenu(char *menuprompt, char *menustring); void async_ka_start(void); void async_ka_end(void); -int checkpagin(int lp, int pagin, int height); +int checkpagin(int lp, unsigned int pagin, unsigned int height); char was_a_key_pressed(void); #ifdef __GNUC__ diff --git a/citadel/file_ops.c b/citadel/file_ops.c index a9de64ae6..b016cba47 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -393,7 +393,7 @@ void cmd_oimg(char *cmdbuf) char filename[SIZ]; char pathname[SIZ]; struct usersupp usbuf; - char which_user[32]; + char which_user[USERNAME_SIZE]; int which_floor; int a; diff --git a/citadel/md5.h b/citadel/md5.h index 553196c77..f77e141b7 100644 --- a/citadel/md5.h +++ b/citadel/md5.h @@ -1,6 +1,7 @@ #ifndef MD5_H #define MD5_H +#include "sysdep.h" #include "typesize.h" struct MD5Context { diff --git a/citadel/messages.c b/citadel/messages.c index b9655d3d3..347510044 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -60,9 +60,9 @@ int haschar(const char *st, int ch); void getline(char *string, int lim); int file_checksum(char *filename); void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd); -void progress(long int curr, long int cmax); +void progress(unsigned long curr, unsigned long cmax); -long *msg_arr = NULL; +unsigned long *msg_arr = NULL; int msg_arr_size = 0; int num_msgs; char rc_alt_semantics; @@ -352,7 +352,7 @@ void citedit(CtdlIPC *ipc, FILE * fp) */ int read_message(CtdlIPC *ipc, long num, /* message number */ - char pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */ + int pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */ FILE *dest) /* Destination file, NULL for screen */ { char buf[SIZ]; @@ -1550,7 +1550,7 @@ RMSGREAD: scr_flush(); scr_printf("%s\n", cmd); } else { save_buffer(attachment, - extract_long(cmd, 0), + extract_unsigned_long(cmd, 0), save_to); } if (attachment) free(attachment); diff --git a/citadel/msgbase.c b/citadel/msgbase.c index afa4d4554..98563d64e 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -624,7 +624,7 @@ void memfmout( int a, b, c; int real = 0; int old = 0; - CIT_UBYTE ch; + cit_uint8_t ch; char aaa[140]; char buffer[SIZ]; @@ -770,8 +770,8 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum) struct cdbdata *dmsgtext; struct CtdlMessage *ret = NULL; char *mptr; - CIT_UBYTE ch; - CIT_UBYTE field_header; + cit_uint8_t ch; + cit_uint8_t field_header; size_t field_length; dmsgtext = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long)); @@ -1089,7 +1089,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, ) { int i, k; char buf[1024]; - CIT_UBYTE ch; + cit_uint8_t ch; char allkeys[SIZ]; char display_name[SIZ]; char *mptr; diff --git a/citadel/rooms.c b/citadel/rooms.c index 51613ab37..84a4ee23e 100644 --- a/citadel/rooms.c +++ b/citadel/rooms.c @@ -37,7 +37,7 @@ void sttybbs(int cmd); void hit_any_key(void); void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto); -void progress(long int curr, long int cmax); +void progress(unsigned long curr, unsigned long cmax); int pattern(char *search, char *patn); int file_checksum(char *filename); int nukedir(char *dirname); @@ -305,7 +305,7 @@ void listzrooms(CtdlIPC *ipc) } -int set_room_attr(CtdlIPC *ipc, int ibuf, char *prompt, unsigned int sbit) +int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit) { int a; @@ -377,7 +377,7 @@ int select_floor(CtdlIPC *ipc, int rfloor) void editthisroom(CtdlIPC *ipc) { int rbump = 0; - char raide[32]; + char raide[USERNAME_SIZE]; char buf[SIZ]; struct quickroom *attr = NULL; struct ExpirePolicy *eptr = NULL; @@ -635,7 +635,7 @@ void download(CtdlIPC *ipc, int proto) int broken = 0; int r; void *file = NULL; /* The downloaded file */ - long filelen = 0L; /* The downloaded file length */ + size_t filelen = 0L; /* The downloaded file length */ if ((room_flags & QR_DOWNLOAD) == 0) { scr_printf("*** You cannot download from this room.\n"); @@ -652,7 +652,7 @@ void download(CtdlIPC *ipc, int proto) scr_printf("%s\n", buf); return; } - save_buffer(file, extract_long(buf, 0), tempname); + save_buffer(file, (size_t)extract_long(buf, 0), tempname); free(file); return; } @@ -662,7 +662,7 @@ void download(CtdlIPC *ipc, int proto) scr_printf("%s\n", buf); return; } - filelen = extract_long(buf, 0); + filelen = extract_unsigned_long(buf, 0); /* Meta-download for public clients */ /* scr_printf("Fetching file from Citadel server...\n"); */ @@ -670,6 +670,7 @@ void download(CtdlIPC *ipc, int proto) snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename); tpipe = fopen(tempname, "wb"); if (fwrite(file, filelen, 1, tpipe) < filelen) { + /* FIXME: restart syscall on EINTR */ broken = 1; } fclose(tpipe); diff --git a/citadel/routines.c b/citadel/routines.c index 89de17cbd..15f954d36 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -159,7 +159,7 @@ void edituser(CtdlIPC *ipc) * yes or no. Yes=1 and No=0, unless 'backwards' is set to a nonzero value * in which case No=1 and Yes=0. */ -int set_attr(CtdlIPC *ipc, int sval, char *prompt, unsigned int sbit, int backwards) +int set_attr(CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, int backwards) { int a; int temp; @@ -388,13 +388,13 @@ char *strerror(int e) #endif -void progress(long int curr, long int cmax) +void progress(unsigned long curr, unsigned long cmax) { static char dots[] = "**************************************************"; char dots_printed[51]; char fmt[42]; - long a; + unsigned long a; if (curr >= cmax) { sln_printf("\r%79s\r",""); diff --git a/citadel/routines.h b/citadel/routines.h index 10b49f412..986d928cd 100644 --- a/citadel/routines.h +++ b/citadel/routines.h @@ -10,4 +10,4 @@ int nukedir(char *dirname); int num_parms(char *source); void strproc(char *string); void back(int spaces); -void progress(long int curr, long int cmax); +void progress(unsigned long curr, unsigned long cmax); diff --git a/citadel/routines2.c b/citadel/routines2.c index f851e3df4..d8076dc21 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -69,7 +69,7 @@ int eopen(char *name, int mode) */ -int room_prompt(int qrflags) +int room_prompt(unsigned int qrflags) { /* return proper room prompt character */ int a; a = '>'; diff --git a/citadel/routines2.h b/citadel/routines2.h index adc217a6b..12204a526 100644 --- a/citadel/routines2.h +++ b/citadel/routines2.h @@ -11,7 +11,7 @@ void cli_upload(CtdlIPC *ipc); void validate(CtdlIPC *ipc); void read_bio(CtdlIPC *ipc); void cli_image_upload(CtdlIPC *ipc, char *keyname); -int room_prompt(int qrflags); +int room_prompt(unsigned int qrflags); void do_internet_configuration(CtdlIPC *ipc); void do_ignet_configuration(CtdlIPC *ipc); void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment); diff --git a/citadel/serv_upgrade.c b/citadel/serv_upgrade.c index 01e0e53f5..0f2686da3 100644 --- a/citadel/serv_upgrade.c +++ b/citadel/serv_upgrade.c @@ -83,13 +83,13 @@ void do_pre555_usersupp_upgrade(void) { newus.flags = usbuf.flags; newus.timescalled = (long) usbuf.timescalled; newus.posted = (long) usbuf.posted; - newus.axlevel = (CIT_UBYTE) usbuf.axlevel; + newus.axlevel = (cit_uint8_t) usbuf.axlevel; newus.usernum = (long) usbuf.usernum; newus.lastcall = (long) usbuf.lastcall; newus.USuserpurge = (int) usbuf.USuserpurge; strcpy(newus.fullname, usbuf.fullname); - newus.USscreenwidth = (CIT_UBYTE) usbuf.USscreenwidth; - newus.USscreenheight = (CIT_UBYTE) usbuf.USscreenheight; + newus.USscreenwidth = (cit_uint8_t) usbuf.USscreenwidth; + newus.USscreenheight = (cit_uint8_t) usbuf.USscreenheight; putuser(&newus); diff --git a/citadel/serv_upgrade.h b/citadel/serv_upgrade.h index 2895dbf73..ebac97e4e 100644 --- a/citadel/serv_upgrade.h +++ b/citadel/serv_upgrade.h @@ -14,8 +14,8 @@ struct pre555usersupp { /* User record */ int posted; /* Number of messages posted (ever) */ char fullname[26]; /* Name for Citadel messages & mail */ char axlevel; /* Access level */ - CIT_UBYTE USscreenwidth; /* Screen width (for textmode users)*/ - CIT_UBYTE USscreenheight; /* Screen height(for textmode users)*/ + cit_uint8_t USscreenwidth; /* Screen width (for textmode users)*/ + cit_uint8_t USscreenheight; /* Screen height(for textmode users)*/ long usernum; /* User number (never recycled) */ time_t lastcall; /* Last time the user called */ char USname[30]; /* */ diff --git a/citadel/tools.c b/citadel/tools.c index 64e790c88..c4a3ca430 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -74,7 +74,7 @@ int strncasecmp(char *lstr, char *rstr, int len) /* * num_tokens() - discover number of parameters/tokens in a string */ -int num_tokens(char *source, char tok) { +int num_tokens(const char *source, char tok) { int a; int count = 1; @@ -87,9 +87,10 @@ int num_tokens(char *source, char tok) { /* extract_token_fast() - a smarter string tokenizer */ -void extract_token(char *dest, char *source, int parmnum, char separator) +void extract_token(char *dest, const char *source, unsigned long parmnum, char separator) { - char *d, *s; /* dest, source */ + char *d; /* dest */ + const char *s; /* source */ int count = 0; strcpy(dest, ""); @@ -119,7 +120,7 @@ void extract_token(char *dest, char *source, int parmnum, char separator) /* * extract_token() - a smarter string tokenizer */ -void extract_token_old(char *dest, char *source, int parmnum, char separator) +void extract_token_old(char *dest, const char *source, unsigned long parmnum, char separator) { int i; int len; @@ -131,7 +132,7 @@ void extract_token_old(char *dest, char *source, int parmnum, char separator) if (strlen(source)==0) { return; - } + } for (i=0; ifullname); ++a) { @@ -621,7 +621,7 @@ int purge_user(char pname[]) { char filename[64]; struct usersupp usbuf; - char lowercase_name[32]; + char lowercase_name[USERNAME_SIZE]; int a; struct CitContext *ccptr; int user_is_logged_in = 0; -- 2.30.2