perror("dorade_read_comment_block");
return NULL;
}
- fread(cb->code, sizeof(cb->code), 1, in);
- fread(&cb->len, sizeof(cb->len), 1, in);
+ if (fread(cb->code, sizeof(cb->code), 1, in) != 1) {
+ perror("dorade_read_comment_block: fread");
+ return NULL;
+ }
+ if (fread(&cb->len, sizeof(cb->len), 1, in) != 1) {
+ perror("dorade_read_comment_block: fread");
+ return NULL;
+ }
/* Check for big endian data on little endian platform. The smallest value
* cb->len could have is 8 (length of cb->code + cb->len), so we put that in
perror("dorade_read_comment_block: cb->comment");
return cb;
}
- fread(cb->comment, sizeof(char), cb->len-8, in);
+ if (fread(cb->comment, sizeof(char), cb->len-8, in) != cb->len){
+ perror("dorade_read_comment_block: fread");
+ return NULL;
+ }
return cb;
}
return NULL;
}
- fread(vd, sizeof(Volume_desc), 1, in);
+ if (fread(vd, sizeof(Volume_desc), 1, in) != 1) {
+ perror("dorade_read_volume_desc: fread");
+ return NULL;
+ }
+
/* Now, convert from Big Endian. */
if (do_swap) {
vd->len = ntohl(vd->len);
return NULL;
}
- fread(rd, sizeof(Radar_desc), 1, in);
+ if (fread(rd, sizeof(Radar_desc), 1, in) != 1) {
+ perror("dorade_read_radar_desc: fread");
+ return NULL;
+ }
/* Now, convert from Big Endian. */
if (do_swap) {
swap_4_bytes(&rd->len);
return NULL;
}
- fread(pd, sizeof(Parameter_desc), 1, in);
+ if (fread(pd, sizeof(Parameter_desc), 1, in) != 1) {
+ perror("dorade_read_parameter_desc: fread");
+ return NULL;
+ }
/* Now, convert from Big Endian. */
if (do_swap) {
swap_4_bytes(&pd->len);
return NULL;
}
- fread(&cv->code, sizeof(cv->code), 1, in);
- fread(&cv->len, sizeof(cv->len), 1, in);
- fread(&cv->ncells, sizeof(cv->ncells), 1, in);
+ if (fread(&cv->code, sizeof(cv->code), 1, in) != 1 ||
+ fread(&cv->len, sizeof(cv->len), 1, in) != 1 ||
+ fread(&cv->ncells, sizeof(cv->ncells), 1, in) != 1) {
+ perror("dorade_read_cell_range_vector: fread");
+ return NULL;
+ }
if (do_swap) {
swap_4_bytes(&cv->len);
swap_4_bytes(&cv->ncells);
perror("dorade_read_cell_range_vector: cv->range_cell");
return cv;
}
- fread(cv->range_cell, sizeof(float), cv->ncells, in);
+ if (fread(cv->range_cell, sizeof(float), cv->ncells, in) != cv->ncells) {
+ perror("dorade_read_cell_range_vector: fread");
+ return NULL;
+ }
if (do_swap) {
for (i=0; i<cv->ncells; i++)
- cv->ncells*4;
buff = (char *)malloc(i);
if (!buff) return cv;
- fread(buff, sizeof(char), i, in);
+ if (fread(buff, sizeof(char), i, in) != i) {
+ perror("dorade_read_cell_range_vector: fread");
+ return NULL;
+ }
free(buff);
return cv;
}
/* Make sure we have Correction Factor Descriptor. */
while (!is_cfac) {
- fread(cf->code, sizeof(cf->code), 1, in);
+ if (fread(cf->code, sizeof(cf->code), 1, in) != 1) {
+ perror("dorade_read_correction_factor_desc: fread");
+ return NULL;
+ }
if (strncmp(cf->code, "CFAC", 4) == 0)
is_cfac = 1;
else {
- fread(&cf->len, sizeof(cf->len), 1, in);
+ if (fread(&cf->len, sizeof(cf->len), 1, in) != 1) {
+ perror("dorade_read_correction_factor_desc: fread");
+ return NULL;
+ }
if (do_swap) swap_4_bytes(&cf->len);
remaining = (char *) malloc(cf->len-8);
if (!remaining) {
fprintf(stderr,"cf->len = %d\n\n", cf->len);
return NULL;
}
- fread(remaining, sizeof(char), cf->len-8, in);
+ if (fread(remaining, sizeof(char), cf->len-8, in) != 1) {
+ perror("dorade_read_correction_factor_desc: fread");
+ return NULL;
+ }
free(remaining);
}
}
- fread(&cf->len, sizeof(Correction_factor_desc)-4, 1, in);
+ if (fread(&cf->len, sizeof(Correction_factor_desc)-4, 1, in) != 1) {
+ perror("dorade_read_correction_factor_desc: fread");
+ return NULL;
+ }
/* Now, convert from Big Endian. */
if (do_swap) {
swap_4_bytes(&cf->len);
return NULL;
}
- fread(si, sizeof(Sweep_info), 1, in);
+ if (fread(si, sizeof(Sweep_info), 1, in) != 1) {
+ perror("dorade_read_sweep_info: fread");
+ return NULL;
+ }
/* FIXME: ?? For now, VOLD is what we expect when there
* are no more SWIB. This is a data driven EOF.
* Returning NULL should suffice.
return NULL;
}
- fread(ri, sizeof(Ray_info), 1, in);
+ if (fread(ri, sizeof(Ray_info), 1, in) != 1) {
+ perror("dorade_read_ray_info: fread");
+ return NULL;
+ }
/* Now, convert from Big Endian. */
if (do_swap) {
swap_4_bytes(&ri->len);
* the place of ASIB when radar is grounded.
*/
- fread(pi->code, sizeof(pi->code), 1, in);
- fread(&pi->len, sizeof(pi->len), 1, in);
+ if (fread(pi->code, sizeof(pi->code), 1, in) != 1 ||
+ fread(&pi->len, sizeof(pi->len), 1, in) != 1) {
+ perror("dorade_read_platform_info: fread");
+ return NULL;
+ }
if (do_swap) swap_4_bytes(&pi->len);
len_first_two = sizeof(pi->code) + sizeof(pi->len);
if (strncmp(pi->code, "ASIB", 4) == 0) {
- fread(&pi->longitude, sizeof(Platform_info)-len_first_two, 1, in);
+ if (fread(&pi->longitude, sizeof(Platform_info)-len_first_two, 1, in) != 1) {
+ perror("dorade_read_platform_info: fread");
+ return NULL;
+ }
/* Read past any extra bytes. */
if (pi->len > sizeof(Platform_info)) {
if (read_extra_bytes(pi->len - sizeof(Platform_info), in) <= 0)
return NULL;
}
- fread(&pd->code, sizeof(pd->code), 1, in);
- fread(&pd->len, sizeof(pd->len), 1, in);
- fread(&pd->name, sizeof(pd->name), 1, in);
+ if (fread(&pd->code, sizeof(pd->code), 1, in) != 1 ||
+ fread(&pd->len, sizeof(pd->len), 1, in) != 1 ||
+ fread(&pd->name, sizeof(pd->name), 1, in) != 1) {
+ perror("dorade_read_parameter_data: fread");
+ return NULL;
+ }
if (do_swap) swap_4_bytes(&pd->len);
/* Length is in parameter data block? or calculate if from pd->len. */
perror("dorade_read_parameter_data: pd->data");
return pd;
}
- fread(pd->data, sizeof(char), len, in);
+ if (fread(pd->data, sizeof(char), len, in) != len) {
+ perror("dorade_read_parameter_data: fread");
+ return NULL;
+ }
/* FIXME: Big endian conversion in caller? Is that the right place? */
if (no_command("gzip --version > /dev/null 2>&1")) return fp;
save_fd = dup(0);
close(0); /* Redirect stdin for gzip. */
- dup(fileno(fp));
+ if (dup(fileno(fp)) < 0) {
+ perror("decompress_pipe");
+ return NULL;
+ }
fpipe = popen("gzip -q -d -f --stdout", "r");
if (fpipe == NULL) perror("uncompress_pipe");
close(0);
- dup(save_fd);
+ if (dup(save_fd) < 0) {
+ perror("decompress_pipe");
+ return NULL;
+ }
return fpipe;
}
fflush(NULL); /* Flush all buffered output before opening this pipe. */
save_fd = dup(1);
close(1); /* Redirect stdout for gzip. */
- dup(fileno(fp));
+ if (dup(fileno(fp)) < 0) {
+ perror("compress_pipe");
+ return NULL;
+ }
fpipe = popen("gzip -q -1 -c", "w");
if (fpipe == NULL) perror("compress_pipe");
close(1);
- dup(save_fd);
+ if (dup(save_fd) < 0) {
+ perror("compress_pipe");
+ return NULL;
+ }
return fpipe;
}
outvect[i] = (unsigned char) (255 + f(r->range[i]));
for(i=0; i<r->h.nbins; i++)
- (void)fwrite(color_table[outvect[i]], sizeof(char), 3, fp);
+ if (fwrite(color_table[outvect[i]], sizeof(char), 3, fp) != 3)
+ fprintf(stderr, "RSL_bscan_ray: short write\n");
}
void RSL_bscan_sweep(Sweep *s, char *outfile)
else {
memset(outvect, 0, nbins);
for(i=0; i<nbins; i++)
- (void)fwrite(color_table[outvect[i]], sizeof(char), 3, fp);
+ if (fwrite(color_table[outvect[i]], sizeof(char), 3, fp) != 3)
+ fprintf(stderr, "RSL_bscan_sweep: short write\n");
}
}
(void)sprintf(pipecmd, "ppmtopict > %s 2>/dev/null", outfile);
fpipe = popen(pipecmd, "w"); /* Global FILE * */
fprintf(fpipe, "P6\n# %s\n%d %d\n255\n",outfile, xdim, ydim);
- for (i=0; i<nbytes; i++) (void)fwrite(c_table[image[i]], sizeof(char), 3, fpipe);
+ for (i=0; i<nbytes; i++)
+ if (fwrite(c_table[image[i]], sizeof(char), 3, fpipe) != 3)
+ fprintf(stderr, "RSL_write_pict: short write\n");
(void)pclose(fpipe);
}
/**********************************************************************/
nbytes = xdim*ydim;
fpipe = fopen(outfile, "w"); /* Global FILE * */
fprintf(fpipe, "P6\n# %s\n%d %d\n255\n",outfile, xdim, ydim);
- for (i=0; i<nbytes; i++) (void)fwrite(c_table[image[i]], sizeof(char), 3, fpipe);
+ for (i=0; i<nbytes; i++)
+ if (fwrite(c_table[image[i]], sizeof(char), 3, fpipe) != 3)
+ fprintf(stderr, "RSL_write_ppm: short write\n");
(void)fclose(fpipe);
}
/**********************************************************************/
(void)sprintf(pipecmd, "gzip > %s.gz 2>/dev/null", outfile);
fpipe = popen(pipecmd, "w"); /* Global FILE * */
fprintf(fpipe, "P5\n# %s\n%d %d\n255\n",outfile, xdim, ydim);
- (void)fwrite(image, sizeof(char), nbytes, fpipe);
+ if (fwrite(image, sizeof(char), nbytes, fpipe) != nbytes)
+ fprintf(stderr, "RSL_write_pgm: short write\n");
(void)pclose(fpipe);
/* The following is commented and is for non compressed. */
rec_len =(int)uf_ma[1]*2;
save_rec_len = rec_len; /* We destroy 'rec_len' when making it
big endian on a little endian machine. */
- if (little_endian()) swap_4_bytes(&rec_len);
- (void)fwrite(&rec_len, sizeof(int), 1, fp);
- if (little_endian()) swap_uf_buffer(uf);
- (void)fwrite(uf, sizeof(char), save_rec_len, fp);
- (void)fwrite(&rec_len, sizeof(int), 1, fp);
+ if (little_endian())
+ swap_4_bytes(&rec_len);
+ if (fwrite(&rec_len, sizeof(int), 1, fp) != 1)
+ perror("RSL_radar_to_uf_fp: short write");
+ if (little_endian())
+ swap_uf_buffer(uf);
+ if (fwrite(uf, sizeof(char), save_rec_len, fp) != 1)
+ perror("RSL_radar_to_uf_fp: short write");
+ if (fwrite(&rec_len, sizeof(int), 1, fp) != 1)
+ perror("RSL_radar_to_uf_fp: short write");
} /* if (ray) */
}
}
if (nrays != 360) {
fprintf(stderr,"WARNING: number of rays computed is not the number "
"expected.\n");
- fprintf(stderr,"Computed = nrays: azstart = %d, az_stop = %d, "
- "az_step = %f\n");
+ fprintf(stderr,"Computed = nrays: "
+ "azstart = %d, az_stop = %d, az_step = %%f\n",
+ rainbow_hdr.az_start, rainbow_hdr.az_stop, rainbow_hdr.az_step);
fprintf(stderr,"Expected 360\n");
}
radar->v[vol_index] = RSL_new_volume(nsweeps);
}
}
fp = uncompress_pipe(fp); /* Transparently gunzip. */
- close(0); dup(fileno(fp)); /* Redirect stdin. */
+ close(0);
+ if (dup(fileno(fp)) < 0) /* Redirect stdin. */
+ return NULL;
rapicparse();
radar = rapic_radar;
Ray *r;
int nbins;
- (void)fread(header_buf, sizeof(char), sizeof(header_buf), fp);
- (void)fread(&nbins, sizeof(int), 1, fp);
+ if (fread(header_buf, sizeof(header_buf), 1, fp) != 1 ||
+ fread(&nbins, sizeof(int), 1, fp) != 1) {
+ perror("RSL_read_ray: fread");
+ return NULL;
+ }
if (nbins == 0) return NULL;
memcpy(&ray_h, header_buf, sizeof(Ray_header));
r = RSL_new_ray(ray_h.nbins);
r->h = ray_h;
- (void)fread(r->range, sizeof(Range), r->h.nbins, fp);
+ if (fread(r->range, sizeof(Range), r->h.nbins, fp) != r->h.nbins) {
+ perror("RSL_read_ray: fread");
+ return NULL;
+ }
return r;
}
Sweep *RSL_read_sweep(FILE *fp)
Sweep *s;
int nrays;
- (void)fread(header_buf, sizeof(char), sizeof(header_buf), fp);
-
- (void)fread(&nrays, sizeof(int), 1, fp);
+ if (fread(header_buf, sizeof(header_buf), 1, fp) != 1 ||
+ fread(&nrays, sizeof(int), 1, fp) != 1) {
+ perror("RSL_read_sweep: fread");
+ return NULL;
+ }
if (nrays == 0) return NULL;
if (radar_verbose_flag)
Volume *v;
int nsweeps;
-
-
- (void)fread(header_buf, sizeof(char), sizeof(header_buf), fp);
- (void)fread(&nsweeps, sizeof(int), 1, fp);
+ if (fread(header_buf, sizeof(header_buf), 1, fp) != 1 ||
+ fread(&nsweeps, sizeof(int), 1, fp) != 1) {
+ perror("RSL_read_volume: fread");
+ return NULL;
+ }
if (nsweeps == 0) return NULL;
if (radar_verbose_flag)
return NULL;
}
fp = uncompress_pipe(fp);
- (void)fread(title, sizeof(char), sizeof(title), fp);
+ if (fread(title, sizeof(title), 1, fp) != 1) {
+ perror("RSL_read_radar: fread");
+ return NULL;
+ }
if (strncmp(title, "RSL", 3) != 0) return NULL;
- (void)fread(header_buf, sizeof(char), sizeof(header_buf), fp);
+ if (fread(header_buf, sizeof(header_buf), 1, fp) != 1) {
+ perror("RSL_read_radar: fread");
+ return NULL;
+ }
memcpy(&radar_h, header_buf, sizeof(Radar_header));
radar = RSL_new_radar(MAX_RADAR_VOLUMES);
radar->h = radar_h;
- (void)fread(&nradar, sizeof(int), 1, fp);
+ if (fread(&nradar, sizeof(int), 1, fp) != 1) {
+ perror("RSL_read_radar: fread");
+ return NULL;
+ }
if (radar_verbose_flag)
fprintf(stderr,"Reading %d volumes.\n", nradar);
nbytes = magic.word;
if (little_endian()) swap_4_bytes(&nbytes);
memcpy(uf, &magic.buf[4], 2);
- (void)fread(&uf[1], sizeof(char), nbytes-2, fp);
+ if (fread(&uf[1], sizeof(char), nbytes-2, fp) != nbytes-2)
+ perror("RSL_uf_to_radar_fp: short read");
if (little_endian()) swap_uf_buffer(uf);
- (void)fread(&nbytes, sizeof(int), 1, fp);
+ if (fread(&nbytes, sizeof(int), 1, fp) != 1)
+ perror("RSL_uf_to_radar_fp: short read");
if (uf_into_radar(uf, &radar) == UF_DONE) break;
/* Now the rest of the file. */
while(fread(&nbytes, sizeof(int), 1, fp) > 0) {
if (little_endian()) swap_4_bytes(&nbytes);
- (void)fread(uf, sizeof(char), nbytes, fp);
+ if (fread(uf, sizeof(char), nbytes, fp) != nbytes)
+ perror("RSL_uf_to_radar_fp: short read");
if (little_endian()) swap_uf_buffer(uf);
- (void)fread(&nbytes, sizeof(int), 1, fp);
+ if (fread(&nbytes, sizeof(int), 1, fp) != 1)
+ perror("RSL_uf_to_radar_fp: short read");
if (uf_into_radar(uf, &radar) == UF_DONE) break;
}
sbytes = magic.sword;
if (little_endian()) swap_2_bytes(&sbytes);
memcpy(uf, &magic.buf[2], 4);
- (void)fread(&uf[2], sizeof(char), sbytes-4, fp);
+ if (fread(&uf[2], sizeof(char), sbytes-4, fp) != sbytes-4)
+ perror("RSL_uf_to_radar_fp: short read");
if (little_endian()) swap_uf_buffer(uf);
- (void)fread(&sbytes, sizeof(short), 1, fp);
+ if (fread(&sbytes, sizeof(short), 1, fp) != 1)
+ perror("RSL_uf_to_radar_fp: short read");
uf_into_radar(uf, &radar);
/* Now the rest of the file. */
while(fread(&sbytes, sizeof(short), 1, fp) > 0) {
if (little_endian()) swap_2_bytes(&sbytes);
- (void)fread(uf, sizeof(char), sbytes, fp);
+ if (fread(uf, sizeof(char), sbytes, fp) != sbytes)
+ perror("RSL_uf_to_radar_fp: short read");
if (little_endian()) swap_uf_buffer(uf);
- (void)fread(&sbytes, sizeof(short), 1, fp);
+ if (fread(&sbytes, sizeof(short), 1, fp) != 1)
+ perror("RSL_uf_to_radar_fp: short read");
if (uf_into_radar(uf, &radar) == UF_DONE) break;
}
if (little_endian()) swap_2_bytes(&sbytes); /* # of 2 byte words. */
memcpy(uf, &magic.buf[0], 6);
- (void)fread(&uf[3], sizeof(short), sbytes-3, fp);
+ if (fread(&uf[3], sizeof(short), sbytes-3, fp) != sbytes-3)
+ perror("RSL_uf_to_radar_fp: short read");
if (little_endian()) swap_uf_buffer(uf);
uf_into_radar(uf, &radar);
/* Now the rest of the file. */
memcpy(&sbytes, &uf[1], 2); /* Record length is in word #2. */
if (little_endian()) swap_2_bytes(&sbytes);
- (void)fread(&uf[2], sizeof(short), sbytes-2, fp); /* Have words 1,2. */
+ if (fread(&uf[2], sizeof(short), sbytes-2, fp) != sbytes-2)
+ perror("RSL_uf_to_radar_fp: short read"); /* Have words 1,2. */
if (little_endian()) swap_uf_buffer(uf);
if (uf_into_radar(uf, &radar) == UF_DONE) break;