1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
Description: remove some GCC warnings from C code.
Author: Nicolas Boulenguez <nicolas.boulenguez@free.fr>
Index: b/util/rot.c
===================================================================
--- a/util/rot.c 2012-07-07 04:21:08.000000000 +0200
+++ b/util/rot.c 2012-07-07 04:21:12.000000000 +0200
@@ -3,6 +3,7 @@
* rot13 them, and put them on stdout. Totally unnecessary, of course.
*/
+#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
Index: b/util/unstr.c
===================================================================
--- a/util/unstr.c 2012-07-07 04:21:08.000000000 +0200
+++ b/util/unstr.c 2012-07-07 04:24:40.000000000 +0200
@@ -88,6 +88,7 @@
* get a fortune that contains nothing but a newline. Karo syrup, syrup.
* For the gory details, and lots of cussing, see strfile.c
*/
+#include <stdlib.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/param.h>
@@ -181,7 +182,12 @@
for (i = 0; i <= tbl->str_numstr; i++)
{
- fread((char *) &pos, 1, sizeof pos, Dataf);
+ if (fread((char *) &pos, 1, sizeof pos, Dataf) != sizeof pos)
+ {
+ fprintf(stderr,
+ "unstr: data file corrupted\n");
+ exit(1);
+ }
fseek(Inf, ntohl(pos), 0);
printedsome = 0;
for (;;)
@@ -224,12 +230,18 @@
perror(Outfile);
exit(1);
}
- fread(&tbl.str_version, sizeof(tbl.str_version), 1, Dataf);
- fread(&tbl.str_numstr, sizeof(tbl.str_numstr), 1, Dataf);
- fread(&tbl.str_longlen, sizeof(tbl.str_longlen), 1, Dataf);
- fread(&tbl.str_shortlen, sizeof(tbl.str_shortlen), 1, Dataf);
- fread(&tbl.str_flags, sizeof(tbl.str_flags), 1, Dataf);
- fread( tbl.stuff, sizeof(tbl.stuff), 1, Dataf);
+#define checked_fread(item, size) \
+ if (fread(item, size, 1, Dataf) != size) \
+ { \
+ fprintf(stderr, "unstr: data file corrupted\n"); \
+ exit(1); \
+ }
+ checked_fread(&tbl.str_version, sizeof(tbl.str_version));
+ checked_fread(&tbl.str_numstr, sizeof(tbl.str_numstr));
+ checked_fread(&tbl.str_longlen, sizeof(tbl.str_longlen));
+ checked_fread(&tbl.str_shortlen, sizeof(tbl.str_shortlen));
+ checked_fread(&tbl.str_flags, sizeof(tbl.str_flags));
+ checked_fread( tbl.stuff, sizeof(tbl.stuff));
if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM)) && (!NewDelch))
{
fprintf(stderr, "nothing to do -- table in file order\n");
Index: b/fortune/fortune.c
===================================================================
--- a/fortune/fortune.c 2012-07-07 04:21:12.000000000 +0200
+++ b/fortune/fortune.c 2012-07-07 04:21:12.000000000 +0200
@@ -1469,8 +1469,13 @@
open_dat(fp);
lseek(fp->datfd,
(off_t) (sizeof fp->tbl + fp->pos * sizeof Seekpts[0]), 0);
- read(fp->datfd, &Seekpts[0], sizeof Seekpts[0]);
- read(fp->datfd, &Seekpts[1], sizeof Seekpts[1]);
+ if ((read(fp->datfd, &Seekpts[0], sizeof Seekpts[0]) == -1)
+ || (read(fp->datfd, &Seekpts[1], sizeof Seekpts[1]) == -1))
+ {
+ fprintf(stderr,
+ "fortune: %s corrupted\n", fp->path);
+ exit(1);
+ }
Seekpts[0] = ntohl(Seekpts[0]);
Seekpts[1] = ntohl(Seekpts[1]);
}
Index: b/util/strfile.c
===================================================================
--- a/util/strfile.c 2012-07-07 04:21:08.000000000 +0200
+++ b/util/strfile.c 2012-07-07 04:21:12.000000000 +0200
@@ -513,9 +513,9 @@
puts("There was 1 string");
else
printf("There were %ld strings\n", Num_pts - 1);
- printf("Longest string: %lu byte%s\n", Tbl.str_longlen,
+ printf("Longest string: %lu byte%s\n", (long unsigned int)Tbl.str_longlen,
Tbl.str_longlen == 1 ? "" : "s");
- printf("Shortest string: %lu byte%s\n", Tbl.str_shortlen,
+ printf("Shortest string: %lu byte%s\n", (long unsigned int)Tbl.str_shortlen,
Tbl.str_shortlen == 1 ? "" : "s");
}
}
|