From d71fef04f16e0d3fa901a0201d0b1b538a12ec1b Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 20 May 2020 20:34:56 +0000 Subject: Fixed warnings. --- Xbit.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'Xbit.c') diff --git a/Xbit.c b/Xbit.c index a354c63..1bba2a2 100644 --- a/Xbit.c +++ b/Xbit.c @@ -42,6 +42,7 @@ static char rcs_id[]="$Id$"; #include #include #include +#include #include @@ -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) { -- cgit v1.2.3