diff options
author | Ian C <ianc@noddybox.co.uk> | 2020-05-20 20:34:56 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2020-05-20 20:34:56 +0000 |
commit | d71fef04f16e0d3fa901a0201d0b1b538a12ec1b (patch) | |
tree | 36e2a970e5726acbb41148217642aa15d330517f | |
parent | 44eec17db0d83b99ccaeb39c3dcdcc0825a7a04c (diff) |
Fixed warnings.
-rw-r--r-- | Xbit.c | 40 | ||||
-rw-r--r-- | ledit.c | 17 | ||||
-rw-r--r-- | lunar.c | 31 |
3 files changed, 66 insertions, 22 deletions
@@ -42,6 +42,7 @@ static char rcs_id[]="$Id$"; #include <fcntl.h> #include <string.h> #include <stdarg.h> +#include <errno.h> #include <netinet/in.h> @@ -151,6 +152,12 @@ static XPoint points[MAX_PUTPLOTS]; /* ------------- FUNCTIONS ------------- */ +static void Exit(const char *p) +{ + perror(p); + exit(EXIT_FAILURE); +} + static void CreateWEntry(Window w, GC g, int ww, int wh) { WEntry *new; @@ -1524,7 +1531,8 @@ void LoadSprite(const char *fn, XSprite *spr, const XColor xc[256]) return; } - read(fd,magic,11); + if (read(fd,magic,11) != 11) + Exit("read"); if (strncmp(magic,"XbitSprite",10)) { @@ -1535,9 +1543,11 @@ void LoadSprite(const char *fn, XSprite *spr, const XColor xc[256]) spr->x=spr->y=0; - read(fd,&us,sizeof(unsigned short)); + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); spr->w=ntohs(us); - read(fd,&us,sizeof(unsigned short)); + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); spr->h=ntohs(us); if (!(data=malloc(spr->w*spr->h))) @@ -1680,11 +1690,14 @@ void LoadColormap(const char *fn, XColor xc[256]) { xc[f].pixel=f; xc[f].flags=DoRed|DoGreen|DoBlue; - read(fd,&us,sizeof(unsigned short)); + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); xc[f].red=ntohs(us); - read(fd,&us,sizeof(unsigned short)); + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); xc[f].green=ntohs(us); - read(fd,&us,sizeof(unsigned short)); + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); xc[f].blue=ntohs(us); } } @@ -1816,7 +1829,8 @@ void LoadSpriteDataSet (const char *cmapfn, return; } - read(fd,magic,11); + if (read(fd,magic,11) != 11) + Exit("read"); if (strncmp(magic,"XbitSprite",10)) { @@ -1825,9 +1839,14 @@ void LoadSpriteDataSet (const char *cmapfn, return; } - read(fd,&us,sizeof(unsigned short)); + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); + spr[f].w=ntohs(us); - read(fd,&us,sizeof(unsigned short)); + + if (read(fd,&us,sizeof(unsigned short)) == -1) + Exit("read"); + spr[f].h=ntohs(us); if (!(spr[f].data=malloc(spr[f].w*spr[f].h))) @@ -1840,7 +1859,8 @@ void LoadSpriteDataSet (const char *cmapfn, */ for(r=0;r<(spr[f].w*spr[f].h);r++) { - read(fd,&byte,1); + if (read(fd,&byte,1) != 1) + Exit("read"); if (used[byte]==-1) { @@ -169,7 +169,7 @@ XFuncControl Key(Window w,XPressRelease m, XEvent *e) KeySym k; if (m==XPRESS) - return; + return XFUNCCONT; switch(k=XLookupKeysym((XKeyEvent*)e,ShiftMapIndex)) { @@ -264,7 +264,7 @@ XFuncControl Mouse(Window w, XPressRelease m, int b, int x, int y) int mapx,mapy; if ((m==XPRESS)||(cur==-1)) - return (XFUNCCONT); + return XFUNCCONT; switch(b) { @@ -400,10 +400,15 @@ char *GetLine(FILE *fp) { static char s[1204]; - fgets(s,1024,fp); - - if (s[strlen(s)-1]=='\n') - s[strlen(s)-1]='\0'; + if (fgets(s,1024,fp)) + { + if (s[strlen(s)-1]=='\n') + s[strlen(s)-1]='\0'; + } + else + { + s[0] = 0; + } return(s); } @@ -36,6 +36,11 @@ static char rcs_id[]="$Id$"; #include <math.h> #include <fcntl.h> #include <string.h> +#include <errno.h> + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> #include "Xbit.h" @@ -1184,7 +1189,7 @@ static XFuncControl ProcessTitle(void) { Centre(100,RED,"PRESENTED BY"); Centre(115,RED,"NODDYBOX '95 - '05"); - Centre(130,RED,"www.noddybox.demon.co.uk"); + Centre(130,RED,"noddybox.co.uk"); } if ((ctr/10)%2) @@ -1574,7 +1579,11 @@ static void ReadScores(void) return; for(f=0;f<NOHI;f++) - read(fd,hisc+f,sizeof(HiSc)); + if (read(fd,hisc+f,sizeof(HiSc)) == -1) + { + perror("read"); + exit(EXIT_FAILURE); + } close(fd); } @@ -1591,7 +1600,11 @@ static void WriteScores(void) } for(f=0;f<NOHI;f++) - write(fd,hisc+f,sizeof(HiSc)); + if (write(fd,hisc+f,sizeof(HiSc)) == -1) + { + perror("write"); + exit(EXIT_FAILURE); + } close(fd); } @@ -1711,10 +1724,16 @@ static char *GetLine(FILE *fp) { static char s[1204]; - fgets(s,1024,fp); + if (fgets(s,1024,fp)) + { + if (s[strlen(s)-1]=='\n') + s[strlen(s)-1]='\0'; - if (s[strlen(s)-1]=='\n') - s[strlen(s)-1]='\0'; + } + else + { + s[0] = 0; + } return s; } |