From c327c727cf633192e64bf90405f581454de770b3 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 20 Nov 2015 18:33:24 -0500 Subject: [svn-r28431] Misc warning and cleanup fixes. Tested on Ubuntu 15.10 (Linux 4.2.0 x86_64) gcc 5.2.1 serial only --- src/H5FDmulti.c | 5 +- test/swmr_sparse_writer.c | 8 +- tools/h5format_convert/h5fc_gentest.c | 2 +- tools/h5jam/getub.c | 213 ++++++++++++++++------------------ tools/h5jam/h5jam.c | 173 ++++++++++++--------------- tools/misc/h5clear_gentest.c | 3 - tools/misc/h5repart.c | 63 +++++----- tools/misc/talign.c | 6 +- 8 files changed, 224 insertions(+), 249 deletions(-) diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index 53e152b..5026e60 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -1807,7 +1807,8 @@ H5FD_multi_lock(H5FD_t *_file, hbool_t rw) { H5FD_multi_t *file = (H5FD_multi_t*)_file; int nerrors = 0; - H5FD_mem_t out_mt, k; + H5FD_mem_t out_mt; + int k; static const char *func="H5FD_multi_unlock"; /* Function Name for error reporting */ /* Clear the error stack */ @@ -1828,7 +1829,7 @@ H5FD_multi_lock(H5FD_t *_file, hbool_t rw) /* Try to unlock the member files that are locked before error is encountered */ if(nerrors) { - for(k = H5FD_MEM_DEFAULT; k < out_mt; k = k + (H5FD_mem_t)1) { + for(k = (int)H5FD_MEM_DEFAULT; k < (int)out_mt; k++) { H5E_BEGIN_TRY { if(H5FDunlock(file->memb[k]) < 0) nerrors++; diff --git a/test/swmr_sparse_writer.c b/test/swmr_sparse_writer.c index 3c20c9c..e752cb3 100644 --- a/test/swmr_sparse_writer.c +++ b/test/swmr_sparse_writer.c @@ -38,7 +38,9 @@ /* Local Macros */ /****************/ +#ifdef OUT #define BUSY_WAIT 100000 +#endif /* OUT */ /********************/ /* Local Prototypes */ @@ -295,12 +297,16 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f #ifdef OUT /* Busy wait, to let readers catch up */ + /* If this is removed, also remove the BUSY_WAIT symbol + * at the top of the file. + */ dummy = 0; for(v=0; v -#include - -#ifdef H5_HAVE_UNISTD_H -#include -#endif - #include "H5private.h" #include "h5tools.h" #include "h5tools_utils.h" -void parse_command_line (int argc, const char *argv[]); +void parse_command_line(int argc, const char *argv[]); /* Name of tool */ -#define PROGRAMNAME "getub" +#define PROGRAM_NAME "getub" char *nbytes = NULL; static const char *s_opts = "c:"; /* add more later ? */ @@ -42,19 +35,14 @@ static struct long_options l_opts[] = { * Purpose: Print the usage message * * Return: void - * - * Programmer: - * - * Modifications: - * *------------------------------------------------------------------------- */ static void usage (const char *prog) { - fflush (stdout); - fprintf (stdout, "usage: %s -c nb file] \n", prog); - fprintf (stdout, " print first 'nb' byts of file to stdoug.\n"); + HDfflush(stdout); + HDfprintf(stdout, "usage: %s -c nb file] \n", prog); + HDfprintf(stdout, " print first 'nb' byts of file to stdoug.\n"); } /*------------------------------------------------------------------------- @@ -65,112 +53,105 @@ usage (const char *prog) * Return: Success: * * Failure: Exits program with EXIT_FAILURE value. - * - * Programmer: - * - * Modifications: - * *------------------------------------------------------------------------- */ - void -parse_command_line (int argc, const char *argv[]) +parse_command_line(int argc, const char *argv[]) { - int opt; - - /* parse command line options */ - while ((opt = get_option (argc, argv, s_opts, l_opts)) != EOF) - { - switch ((char) opt) - { - case 'c': - nbytes = HDstrdup (opt_arg); - break; - case '?': - default: - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); - } - } - - if (argc <= opt_ind) - { + int opt; + + /* parse command line options */ + while((opt = get_option (argc, argv, s_opts, l_opts)) != EOF) { + switch((char) opt) { + case 'c': + nbytes = HDstrdup(opt_arg); + break; + case '?': + default: + usage(h5tools_getprogname()); + HDexit(EXIT_FAILURE); + } /* end switch */ + } /* end while */ + + if(argc <= opt_ind) { error_msg("missing file name\n"); - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); - } -} + usage(h5tools_getprogname()); + HDexit(EXIT_FAILURE); + } /* end if */ +} /* end parse_command_line() */ int -main (int argc, const char *argv[]) +main(int argc, const char *argv[]) { - int fd; - unsigned int size; - char *filename; - long res; - char *buf; - - h5tools_setprogname(PROGRAMNAME); - h5tools_setstatus(EXIT_SUCCESS); - - /* Initialize h5tools lib */ - h5tools_init(); - - parse_command_line (argc, argv); - - if (nbytes == NULL) - { - /* missing arg */ - error_msg("missing size\n"); - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); - } - if (argc <= (opt_ind)) - { - error_msg("missing file name\n"); - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); - } - filename = HDstrdup (argv[opt_ind]); - - size = 0; - res = sscanf (nbytes, "%u", &size); - if (res == EOF) - { + int fd = -1; + unsigned size; + char *filename = NULL; + long res; + char *buf = NULL; + + h5tools_setprogname(PROGRAM_NAME); + h5tools_setstatus(EXIT_SUCCESS); + + /* Initialize h5tools lib */ + h5tools_init(); + + parse_command_line(argc, argv); + + if(NULL == nbytes) { + /* missing arg */ + error_msg("missing size\n"); + usage(h5tools_getprogname()); + goto error; + } /* end if */ + + if(argc <= (opt_ind)) { + error_msg("missing file name\n"); + usage(h5tools_getprogname()); + goto error; + } /* end if */ + + filename = HDstrdup(argv[opt_ind]); + + size = 0; + if(EOF == (res = sscanf(nbytes, "%u", &size))) { /* fail */ error_msg("missing file name\n"); - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); - } - - fd = HDopen (filename, O_RDONLY, 0); - if (fd < 0) - { - error_msg("can't open file %s\n", filename); - exit (EXIT_FAILURE); - } - - buf = (char *)HDmalloc ((unsigned)(size + 1)); - if (buf == NULL) - { - HDclose (fd); - exit (EXIT_FAILURE); - } - - res = HDread (fd, buf, (unsigned)size); - - if (res < (long)size) - { - if (buf) - HDfree (buf); - HDclose (fd); - exit (EXIT_FAILURE); - } - - HDwrite (1, buf, (unsigned)size); - - if (buf) - HDfree (buf); - HDclose (fd); - return (EXIT_SUCCESS); -} + usage(h5tools_getprogname()); + goto error; + } /* end if */ + + if((fd = HDopen(filename, O_RDONLY, 0)) < 0) { + error_msg("can't open file %s\n", filename); + goto error; + } /* end if */ + + if(NULL == (buf = (char *)HDmalloc((unsigned)(size + 1)))) { + error_msg("can't allocate buffer \n"); + goto error; + } /* end if */ + + res = HDread(fd, buf, (unsigned)size); + if(res < (long)size) { + error_msg("Bad read \n"); + goto error; + } /* end if */ + + if(HDwrite(1, buf, (unsigned)size) < 0) { + error_msg("Bad write \n"); + goto error; + } /* end if */ + + /* close things and exit */ + HDfree(buf); + HDclose(fd); + + return EXIT_SUCCESS; + +error: + if(buf) + HDfree(buf); + if(fd > -1) + HDclose(fd); + return EXIT_FAILURE; +} /* end main() */ + diff --git a/tools/h5jam/h5jam.c b/tools/h5jam/h5jam.c index 1df5496..f70947c 100644 --- a/tools/h5jam/h5jam.c +++ b/tools/h5jam/h5jam.c @@ -418,109 +418,88 @@ main (int argc, const char *argv[]) * Return: Success: last byte written in the output. * Failure: Exits program with EXIT_FAILURE value. * - * Programmer: - * - * Modifications: - * *------------------------------------------------------------------------- */ hsize_t -copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, +copy_some_to_file(int infid, int outfid, hsize_t startin, hsize_t startout, ssize_t limit) { - char buf[1024]; - h5_stat_t sbuf; - int res; - ssize_t tot = 0; - ssize_t howmuch = 0; - ssize_t nchars = -1; -/* used in assertion check - ssize_t ncw = -1; -*/ - ssize_t to; - ssize_t from; - ssize_t toend; - ssize_t fromend; - - if(startin > startout) { - /* this case is prohibited */ - error_msg("copy_some_to_file: panic: startin > startout?\n"); - exit (EXIT_FAILURE); - } - - if(limit < 0) { - res = HDfstat(infid, &sbuf); - if(res < 0) { - error_msg("Can't stat file \n"); - exit (EXIT_FAILURE); - } - - howmuch = (ssize_t)sbuf.st_size; - } - else - howmuch = limit; - - if(howmuch == 0) - return 0; - - /* assert (howmuch > 0) */ - - toend = (ssize_t) startout + howmuch; - fromend = (ssize_t) startin + howmuch; - - if (howmuch > 512) - { - to = toend - 512; - from = fromend - 512; - } - else - { - to = toend - howmuch; - from = fromend - howmuch; - } - - while (howmuch > 0) - { - HDlseek (outfid, (off_t) to, SEEK_SET); - HDlseek (infid, (off_t) from, SEEK_SET); - - if (howmuch > 512) - { - nchars = HDread (infid, buf, (unsigned) 512); - } - else - { - nchars = HDread (infid, buf, (unsigned)howmuch); - } - - if (nchars <= 0) - { - printf ("huh? \n"); - exit (EXIT_FAILURE); - } - /*ncw = */ HDwrite (outfid, buf, (unsigned) nchars); - - /* assert (ncw == nchars) */ - - tot += nchars; - howmuch -= nchars; - if (howmuch > 512) - { - to -= nchars; - from -= nchars; - } - else - { - to -= howmuch; - from -= howmuch; - } - } - - /* assert howmuch == 0 */ - /* assert tot == limit */ + char buf[1024]; + h5_stat_t sbuf; + int res; + ssize_t tot = 0; + ssize_t howmuch = 0; + ssize_t nchars = -1; + ssize_t to; + ssize_t from; + ssize_t toend; + ssize_t fromend; + + if(startin > startout) { + /* this case is prohibited */ + error_msg("copy_some_to_file: panic: startin > startout?\n"); + exit (EXIT_FAILURE); + } /* end if */ + + if(limit < 0) { + res = HDfstat(infid, &sbuf); + if(res < 0) { + error_msg("Can't stat file \n"); + HDexit(EXIT_FAILURE); + } /* end if */ + + howmuch = (ssize_t)sbuf.st_size; + } else { + howmuch = limit; + } /* end if */ + + if(0 == howmuch) + return 0; + + toend = (ssize_t) startout + howmuch; + fromend = (ssize_t) startin + howmuch; + + if (howmuch > 512) { + to = toend - 512; + from = fromend - 512; + } else { + to = toend - howmuch; + from = fromend - howmuch; + } /* end if */ + + while (howmuch > 0) { + HDlseek(outfid, (off_t) to, SEEK_SET); + HDlseek(infid, (off_t) from, SEEK_SET); + + if (howmuch > 512) { + nchars = HDread(infid, buf, (unsigned) 512); + } else { + nchars = HDread(infid, buf, (unsigned)howmuch); + } /* end if */ + + if (nchars <= 0) { + error_msg("Read error \n"); + HDexit(EXIT_FAILURE); + } /* end if */ + + if(HDwrite (outfid, buf, (unsigned) nchars) < 0) { + error_msg("Write error \n"); + HDexit(EXIT_FAILURE); + } - return ((hsize_t) tot + (hsize_t) startout); -} + tot += nchars; + howmuch -= nchars; + if(howmuch > 512) { + to -= nchars; + from -= nchars; + } else { + to -= howmuch; + from -= howmuch; + } /* end if */ + } /* end while */ + + return (hsize_t)tot + (hsize_t)startout; +} /* end copy_some_to_file() */ /*------------------------------------------------------------------------- diff --git a/tools/misc/h5clear_gentest.c b/tools/misc/h5clear_gentest.c index 062e938..0f20c35 100644 --- a/tools/misc/h5clear_gentest.c +++ b/tools/misc/h5clear_gentest.c @@ -59,9 +59,6 @@ main(void) hid_t fapl, new_fapl; /* File access property lists */ char fname[512]; /* File name */ unsigned new_format; /* To use latest library format or not */ - int fd; /* File descriptor */ - uint8_t super_vers; /* Superblock version */ - ssize_t bytes_written; /* The # of bytes written to the file */ /* Create a copy of the file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) diff --git a/tools/misc/h5repart.c b/tools/misc/h5repart.c index f58af3a..37d505a 100644 --- a/tools/misc/h5repart.c +++ b/tools/misc/h5repart.c @@ -200,21 +200,21 @@ main (int argc, char *argv[]) int verbose=FALSE; /*display file names? */ - const char *src_gen_name; /*general source name */ - char src_name[NAMELEN]; /*source member name */ + const char *src_gen_name; /*general source name */ + char *src_name=NULL; /*source member name */ int src_is_family; /*is source name a family name? */ int src_membno=0; /*source member number */ - const char *dst_gen_name; /*general destination name */ - char dst_name[NAMELEN]; /*destination member name */ + const char *dst_gen_name; /*general destination name */ + char *dst_name=NULL; /*destination member name */ int dst_is_family; /*is dst name a family name? */ int dst_membno=0; /*destination member number */ off_t left_overs=0; /*amount of zeros left over */ off_t src_offset=0; /*offset in source member */ off_t dst_offset=0; /*offset in destination member */ - off_t src_size; /*source logical member size */ + off_t src_size; /*source logical member size */ off_t src_act_size; /*source actual member size */ off_t dst_size=1 GB; /*destination logical memb size */ hid_t fapl; /*file access property list */ @@ -232,24 +232,30 @@ main (int argc, char *argv[]) * Parse switches. */ while (argno=0) { if(H5Fclose(file)<0) { perror ("H5Fclose"); exit (EXIT_FAILURE); - } - } + } /* end if */ + } /* end if */ if(H5Pclose(fapl)<0) { perror ("H5Pclose"); exit (EXIT_FAILURE); - } + } /* end if */ /* Free resources and return */ - HDfree (buf); + HDfree(src_name); + HDfree(dst_name); + HDfree(buf); return EXIT_SUCCESS; -} +} /* end main */ diff --git a/tools/misc/talign.c b/tools/misc/talign.c index 7eb4c50..194364e 100644 --- a/tools/misc/talign.c +++ b/tools/misc/talign.c @@ -143,8 +143,10 @@ out: if(error < 0) { result = 1; puts("*FAILED - HDF5 library error*"); - } else if(fok[0] != fptr[0] || fok[1] != fptr[1] - || fnok[0] != fptr[2] || fnok[1] != fptr[3]) { + } else if(!(H5_FLT_ABS_EQUAL(fok[0], fptr[0])) + || !(H5_FLT_ABS_EQUAL(fok[1], fptr[1])) + || !(H5_FLT_ABS_EQUAL(fnok[0], fptr[2])) + || !(H5_FLT_ABS_EQUAL(fnok[1], fptr[3]))) { char *mname; result = 1; -- cgit v0.12