Commit c21f772f11fb3c25f6ba4c389be3a126e43734d0

Authored by Jim Plank
1 parent 8a85c829
Exists in master and in 1 other branch v2

Fixed some compiler warnings.

Showing 2 changed files with 24 additions and 9 deletions   Show diff stats
Examples/decoder.c
... ... @@ -61,6 +61,7 @@ same arguments, and encoder.c does error check.
61 61 #include <stdio.h>
62 62 #include <stdlib.h>
63 63 #include <string.h>
  64 +#include <time.h>
64 65 #include <sys/time.h>
65 66 #include <sys/stat.h>
66 67 #include <signal.h>
... ... @@ -99,12 +100,13 @@ int main (int argc, char **argv) {
99 100 int tech;
100 101 char *c_tech;
101 102  
102   - int i, j; // loop control variables
  103 + int i, j; // loop control variable, s
103 104 int blocksize; // size of individual files
104 105 int origsize; // size of file before padding
105 106 int total; // used to write data, not padding to file
106 107 struct stat status; // used to find size of individual files
107 108 int numerased; // number of erased files
  109 + int dummy;
108 110  
109 111 /* Used to recreate file names */
110 112 char *temp;
... ... @@ -165,7 +167,10 @@ int main (int argc, char **argv) {
165 167 exit(1);
166 168 }
167 169 temp = (char *)malloc(sizeof(char)*(strlen(argv[1])+20));
168   - fscanf(fp, "%s", temp);
  170 + if (fscanf(fp, "%s", temp) != 1) {
  171 + fprintf(stderr, "Metadata file - bad format\n");
  172 + exit(0);
  173 + }
169 174  
170 175 if (fscanf(fp, "%d", &origsize) != 1) {
171 176 fprintf(stderr, "Original size is not valid\n");
... ... @@ -176,10 +181,19 @@ int main (int argc, char **argv) {
176 181 exit(0);
177 182 }
178 183 c_tech = (char *)malloc(sizeof(char)*(strlen(argv[1])+20));
179   - fscanf(fp, "%s", c_tech);
180   - fscanf(fp, "%d", &tech);
  184 + if (fscanf(fp, "%s", c_tech) != 1) {
  185 + fprintf(stderr, "Metadata file - bad format\n");
  186 + exit(0);
  187 + }
  188 + if (fscanf(fp, "%d", &tech) != 1) {
  189 + fprintf(stderr, "Metadata file - bad format\n");
  190 + exit(0);
  191 + }
181 192 method = tech;
182   - fscanf(fp, "%d", &readins);
  193 + if (fscanf(fp, "%d", &readins) != 1) {
  194 + fprintf(stderr, "Metadata file - bad format\n");
  195 + exit(0);
  196 + }
183 197 fclose(fp);
184 198  
185 199 /* Allocate memory */
... ... @@ -260,11 +274,11 @@ int main (int argc, char **argv) {
260 274 stat(fname, &status);
261 275 blocksize = status.st_size;
262 276 data[i-1] = (char *)malloc(sizeof(char)*blocksize);
263   - fread(data[i-1], sizeof(char), blocksize, fp);
  277 + dummy = fread(data[i-1], sizeof(char), blocksize, fp);
264 278 }
265 279 else {
266 280 fseek(fp, blocksize*(n-1), SEEK_SET);
267   - fread(data[i-1], sizeof(char), buffersize/k, fp);
  281 + dummy = fread(data[i-1], sizeof(char), buffersize/k, fp);
268 282 }
269 283 fclose(fp);
270 284 }
... ... @@ -283,11 +297,11 @@ int main (int argc, char **argv) {
283 297 stat(fname, &status);
284 298 blocksize = status.st_size;
285 299 coding[i-1] = (char *)malloc(sizeof(char)*blocksize);
286   - fread(coding[i-1], sizeof(char), blocksize, fp);
  300 + dummy = fread(coding[i-1], sizeof(char), blocksize, fp);
287 301 }
288 302 else {
289 303 fseek(fp, blocksize*(n-1), SEEK_SET);
290   - fread(coding[i-1], sizeof(char), blocksize, fp);
  304 + dummy = fread(coding[i-1], sizeof(char), blocksize, fp);
291 305 }
292 306 fclose(fp);
293 307 }
... ...
Examples/encoder.c
... ... @@ -55,6 +55,7 @@ is the file name with &quot;_k#&quot; or &quot;_m#&quot; and then the extension.
55 55 (For example, inputfile test.txt would yield file "test_k1.txt".)
56 56 */
57 57  
  58 +#include <time.h>
58 59 #include <sys/time.h>
59 60 #include <sys/stat.h>
60 61 #include <string.h>
... ...