diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2014-02-20 21:29:26 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2014-02-20 21:29:26 (GMT) |
commit | 1e36b5a348415501aa8eb992fd57c09d834900cd (patch) | |
tree | 9a423be6cbe38eed62268779703258972fb94191 /fortran | |
parent | b30e37ea78a85c9a2e3abda7fddaabb636935b1c (diff) | |
download | hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.zip hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.tar.gz hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.tar.bz2 |
[svn-r24726] Description:
Revert some earlier usage of strncpy, which was incorrect.
Bring Coverity changes from branch back to trunk:
r20821:
Use HDstrncpy. --gh
(Fixed already, with strdup)
r20822:
(Not merged, incorrect use of HDstrncpy())
r20823:
(Not merged, incorrect use of HDstrncpy())
r20824:
Maintenance: Bug fix: addressed CID 666.
Value stored at *expression_len should be used in the call to
HD5packFstring to avoid overflow (and unnecessary arithmetic
calculation and casting)
r20825:
Issue 642: Added check for error and handler with print to stderr and exit.
r20826:
Undo revision 20818, as that issue has already been fixed in the 1.8 branch
and trunk (but not coverity branch)
r20827:
(Not merged, incorrect use of HDstrncpy())
r20828:
Use HDstrncpy. --gh
(Corrected use of strncpy())
r20829:
Check return of H5Lget_val(print_udata->fid, path, targbuf,
linfo->u.val_size + 1, H5P_DEFAULT) and if error set trgbuf[0] to 0.
Check if H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL,
&filename, &objname) was successful and allow print. Otherwise filename
and objname are not created. (init those to NULL)
r20830:
resolved coverity issues 939, 940, 941, 944, and 947.
all were complaints about use of sprintf, and in all cases, the
buffers used were large enough for all eventualities.
Resolved issue by replacing calls to sprintf with calls
to snprintf.
r20831:
Maintenance: Addressed CID 852
Replaced sprintf with snprintf
r20832:
Purpose: Fix valgrind issues with hl/examples/ex_image2
Description:
Modified hl/examples/ex_image2 to free global "gbuf" before exit.
Tested on:
Mac OSX/64 10.9.1 (amaon) w/C++, FORTRAN & Threadsafety
(too minor to require h5committest)
Diffstat (limited to 'fortran')
-rw-r--r-- | fortran/src/H5Pf.c | 77 | ||||
-rw-r--r-- | fortran/src/H5match_types.c | 47 |
2 files changed, 47 insertions, 77 deletions
diff --git a/fortran/src/H5Pf.c b/fortran/src/H5Pf.c index 262ce55..cf10efc 100644 --- a/fortran/src/H5Pf.c +++ b/fortran/src/H5Pf.c @@ -324,30 +324,23 @@ nh5pset_chunk_c ( hid_t_f *prp_id, int_f *rank, hsize_t_f *dims ) /******/ { int ret_value = -1; - hid_t c_prp_id; - int c_rank; - hsize_t *c_dims; + hid_t c_prp_id = (hid_t)*prp_id; + int c_rank = (int)*rank; + hsize_t c_dims[H5S_MAX_RANK]; herr_t status; int i; - c_dims = (hsize_t *)HDmalloc(sizeof(hsize_t) * (*rank )); - if (!c_dims) return ret_value; - /* * Transpose dimension arrays because of C-FORTRAN storage order */ - for (i = 0; i < *rank ; i++) { - c_dims[i] = dims[*rank - i - 1]; - } + for (i = 0; i < c_rank ; i++) + c_dims[i] = (hsize_t)dims[c_rank - i - 1]; - c_prp_id = (hid_t)*prp_id; - c_rank = (int)*rank; status = H5Pset_chunk(c_prp_id, c_rank, c_dims); if (status < 0) goto DONE; ret_value = 0; DONE: - HDfree (c_dims); return ret_value; } @@ -375,26 +368,19 @@ nh5pget_chunk_c ( hid_t_f *prp_id, int_f *max_rank, hsize_t_f *dims ) /******/ { int ret_value = -1; - hid_t c_prp_id; - hsize_t *c_dims; + hid_t c_prp_id = (hid_t)*prp_id; + hsize_t c_dims[H5S_MAX_RANK]; int rank; - int c_max_rank; + int c_max_rank = (int)*max_rank; int i; - c_dims = (hsize_t *)HDmalloc(sizeof(hsize_t) * (*max_rank )); - if (!c_dims) return ret_value; - - c_prp_id = (hid_t)*prp_id; - c_max_rank = (int)*max_rank; rank = H5Pget_chunk(c_prp_id, c_max_rank, c_dims); /* * Transpose dimension arrays because of C-FORTRAN storage order */ - for (i = 0; i < *max_rank ; i++) { - dims[*max_rank - i - 1] = (hsize_t_f)c_dims[i]; - } - HDfree (c_dims); + for (i = 0; i < c_max_rank ; i++) + dims[c_max_rank - i - 1] = (hsize_t_f)c_dims[i]; if (rank < 0) return ret_value; ret_value = (int_f)rank; return ret_value; @@ -1801,18 +1787,15 @@ nh5pset_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_nel /******/ { int ret_value = -1; - hid_t c_prp_id; + hid_t c_prp_id = (hid_t)*prp_id; herr_t ret; - size_t c_cd_nelmts; - unsigned int c_flags; - H5Z_filter_t c_filter; + size_t c_cd_nelmts = (size_t)*cd_nelmts; + unsigned int c_flags = (unsigned)*flags; + H5Z_filter_t c_filter = (H5Z_filter_t)*filter; unsigned int * c_cd_values; unsigned i; - c_filter = (H5Z_filter_t)*filter; - c_flags = (unsigned)*flags; - c_cd_nelmts = (size_t)*cd_nelmts; - c_cd_values = (unsigned int*)HDmalloc(sizeof(unsigned int) * ((int)c_cd_nelmts)); + c_cd_values = (unsigned int*)HDmalloc(sizeof(unsigned int) * c_cd_nelmts); if (!c_cd_values) return ret_value; for (i = 0; i < c_cd_nelmts; i++) c_cd_values[i] = (unsigned int)cd_values[i]; @@ -1820,7 +1803,6 @@ nh5pset_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_nel /* * Call H5Pset_filter function. */ - c_prp_id = (hid_t)*prp_id; ret = H5Pset_filter(c_prp_id, c_filter, c_flags, c_cd_nelmts,c_cd_values ); if (ret < 0) goto DONE; @@ -1967,13 +1949,12 @@ nh5pset_external_c (hid_t_f *prp_id, _fcd name, int_f* namelen, off_t_f* offset, herr_t ret; hsize_t c_bytes; char* c_name; - size_t c_namelen; + size_t c_namelen = (size_t)*namelen; off_t c_offset; c_bytes = (hsize_t) *bytes; c_offset = (off_t) *offset; - c_namelen = (int)*namelen; c_name = (char *)HD5f2cstring(name, c_namelen); if (c_name == NULL) return ret_value; @@ -3819,7 +3800,7 @@ nh5pset_fapl_multi_c ( hid_t_f *prp_id , int_f *memb_map, hid_t_f *memb_fapl, _f * Check that we got correct values from Fortran for memb_addr array */ for (i=0; i < H5FD_MEM_NTYPES; i++) { - if(memb_addr[i] >= 1.) return ret_value; + if(memb_addr[i] >= 1.0f) return ret_value; } /* * Take care of names array @@ -3971,7 +3952,7 @@ HD5packFstring(tmp, _fcdtocp(memb_name), (size_t)(c_lenmax*H5FD_MEM_NTYPES)); memb_map[i] = (int_f)c_memb_map[i]; memb_fapl[i] = (hid_t_f)c_memb_fapl[i]; if(c_memb_addr[i] == HADDR_UNDEF) memb_addr[i] = -1; - else memb_addr[i] = (real_f) ((long)c_memb_addr[i]/HADDR_MAX); + else memb_addr[i] = (real_f) (c_memb_addr[i]/HADDR_MAX); } *flag = (int_f)relax; *maxlen_out = (int_f)length; @@ -4104,7 +4085,7 @@ nh5pget_filter_by_id_c(hid_t_f *prp_id, int_f* filter_id, int_f* flags, size_t_f if(NULL == (c_name = (char *)HDmalloc((size_t)*namelen + 1))) goto DONE; - if(NULL == (c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * ((int)c_cd_nelmts_in)))) + if(NULL == (c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * c_cd_nelmts_in))) goto DONE; /* @@ -4157,18 +4138,15 @@ nh5pmodify_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_ /******/ { int_f ret_value = -1; - hid_t c_prp_id; + hid_t c_prp_id = (hid_t)*prp_id; herr_t ret; - size_t c_cd_nelmts; - unsigned int c_flags; - H5Z_filter_t c_filter; + size_t c_cd_nelmts = (size_t)*cd_nelmts; + unsigned int c_flags = (unsigned)*flags; + H5Z_filter_t c_filter = (H5Z_filter_t)*filter; unsigned int * c_cd_values; unsigned i; - c_filter = (H5Z_filter_t)*filter; - c_flags = (unsigned)*flags; - c_cd_nelmts = (size_t)*cd_nelmts; - c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * ((int)c_cd_nelmts)); + c_cd_values = (unsigned int *)HDmalloc(sizeof(unsigned int) * c_cd_nelmts); if (!c_cd_values) return ret_value; for (i = 0; i < c_cd_nelmts; i++) c_cd_values[i] = (unsigned int)cd_values[i]; @@ -4176,7 +4154,6 @@ nh5pmodify_filter_c (hid_t_f *prp_id, int_f* filter, int_f* flags, size_t_f* cd_ /* * Call H5Pmodify_filter function. */ - c_prp_id = (hid_t)*prp_id; ret = H5Pmodify_filter(c_prp_id, c_filter, c_flags, c_cd_nelmts,c_cd_values ); if (ret < 0) goto DONE; @@ -4905,12 +4882,10 @@ nh5pget_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_l /******/ { char *c_expression = NULL; /* Buffer to hold C string */ - size_t c_expression_len; + size_t c_expression_len = (size_t)*expression_len + 1; ssize_t ret; int_f ret_value = 0; - c_expression_len = (size_t)*expression_len + 1; - /* * Allocate memory to store the expression. */ @@ -4928,7 +4903,7 @@ nh5pget_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_l HGOTO_DONE(FAIL) /* or strlen ? */ - HD5packFstring(c_expression, _fcdtocp(expression), c_expression_len - 1); + HD5packFstring(c_expression, _fcdtocp(expression), (size_t)*expression_len); *size = (size_t_f)ret; diff --git a/fortran/src/H5match_types.c b/fortran/src/H5match_types.c index eb30775..3ae4bdb 100644 --- a/fortran/src/H5match_types.c +++ b/fortran/src/H5match_types.c @@ -51,8 +51,8 @@ FILE * fort_header; void writeTypedef(const char* c_type, unsigned int size); void writeFloatTypedef(const char* c_type, unsigned int size); void writeTypedefDefault(unsigned int size); -void writeToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind); -void writeFloatToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind); +void writeToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind); +void writeFloatToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind); static void initCfile(void) @@ -141,26 +141,26 @@ void writeTypedefDefault(unsigned int size) } /* Create matching Fortran and C types by writing to both files */ -void writeToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind) +void writeToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind) { fprintf(fort_header, " INTEGER, PARAMETER :: %s = %u\n", fortran_type, kind); - fprintf(c_header, "typedef c_int_%u %s;\n", size, c_type); + fprintf(c_header, "typedef c_int_%d %s;\n", size, c_type); } /* Create matching Fortran and C floating types by writing to both files */ -void writeFloatToFiles(const char* fortran_type, const char* c_type, unsigned int size, unsigned int kind) +void writeFloatToFiles(const char* fortran_type, const char* c_type, int size, unsigned int kind) { fprintf(fort_header, " INTEGER, PARAMETER :: %s = %u\n", fortran_type, kind); - fprintf(c_header, "typedef c_float_%u %s;\n", size, c_type); + fprintf(c_header, "typedef c_float_%d %s;\n", size, c_type); } int main(void) { int FoundIntSize[4]; - int FoundIntSizeKind[4]; + unsigned FoundIntSizeKind[4]; int FoundRealSize[3]; - int FoundRealSizeKind[3]; + unsigned FoundRealSizeKind[3]; int i,j,flag; char chrA[20],chrB[20]; int H5_C_HAS_REAL_NATIVE_16; @@ -395,8 +395,8 @@ int main(void) for(i=0;i<4;i++) { if( FoundIntSize[i] > 0) /* Found the integer type */ { - sprintf(chrA, "Fortran_INTEGER_%d", FoundIntSize[i]); - sprintf(chrB, "int_%d_f", FoundIntSize[i]); + snprintf(chrA, sizeof(chrA), "Fortran_INTEGER_%d", FoundIntSize[i]); + snprintf(chrB, sizeof(chrB), "int_%d_f", FoundIntSize[i]); writeToFiles(chrA, chrB, FoundIntSize[i], FoundIntSizeKind[i]); } else /* Did not find the integer type */ @@ -406,8 +406,8 @@ int main(void) { if( FoundIntSize[j] > 0) /* Found the next highest */ { - sprintf(chrA, "Fortran_INTEGER_%d", (-1)*FoundIntSize[i]); - sprintf(chrB, "int_%d_f", (-1)*FoundIntSize[i]); + snprintf(chrA, sizeof(chrA), "Fortran_INTEGER_%d", (-1)*FoundIntSize[i]); + snprintf(chrB, sizeof(chrB), "int_%d_f", (-1)*FoundIntSize[i]); writeToFiles(chrA, chrB, FoundIntSize[j], FoundIntSizeKind[j]); flag = 1; break; @@ -419,8 +419,8 @@ int main(void) { if( FoundIntSize[j] > 0) /* Found the next lowest */ { - sprintf(chrA, "Fortran_INTEGER_%d", (-1)*FoundIntSize[i]); - sprintf(chrB, "int_%d_f", (-1)*FoundIntSize[i]); + snprintf(chrA, sizeof(chrA), "Fortran_INTEGER_%d", (-1)*FoundIntSize[i]); + snprintf(chrB, sizeof(chrB), "int_%d_f", (-1)*FoundIntSize[i]); writeToFiles(chrA, chrB, FoundIntSize[j], FoundIntSizeKind[j]); flag = 1; break; @@ -428,9 +428,7 @@ int main(void) } } if(flag == 0) /* No higher or lower one found, indicating an error */ - { return -1; - } } } @@ -464,8 +462,8 @@ int main(void) for(i=0;i<3;i++) { if( FoundRealSize[i] > 0) /* Found the real type */ { - sprintf(chrA, "Fortran_REAL_%d", FoundRealSize[i]); - sprintf(chrB, "real_%d_f", FoundRealSize[i]); + snprintf(chrA, sizeof(chrA), "Fortran_REAL_%d", FoundRealSize[i]); + snprintf(chrB, sizeof(chrB), "real_%d_f", FoundRealSize[i]); writeFloatToFiles(chrA, chrB, FoundRealSize[i], FoundRealSizeKind[i]); } else /* Did not find the real type */ @@ -475,8 +473,8 @@ int main(void) { if( FoundRealSize[j] > 0) /* Found the next highest */ { - sprintf(chrA, "Fortran_REAL_%d", (-1)*FoundRealSize[i]); - sprintf(chrB, "real_%d_f", (-1)*FoundRealSize[i]); + snprintf(chrA, sizeof(chrA), "Fortran_REAL_%d", (-1)*FoundRealSize[i]); + snprintf(chrB, sizeof(chrB), "real_%d_f", (-1)*FoundRealSize[i]); if(FoundRealSize[j]>4) { writeFloatToFiles(chrA, chrB, FoundRealSize[j], FoundRealSizeKind[j]); flag = 1; @@ -494,11 +492,10 @@ int main(void) { if( FoundRealSize[j] > 0) /* Found the next lowest */ { - sprintf(chrA, "Fortran_REAL_%d", (-1)*FoundRealSize[i]); - sprintf(chrB, "real_%d_f", (-1)*FoundRealSize[i]); - if(FoundRealSize[j]>4) { + snprintf(chrA, sizeof(chrA), "Fortran_REAL_%d", (-1)*FoundRealSize[i]); + snprintf(chrB, sizeof(chrB), "real_%d_f", (-1)*FoundRealSize[i]); + if(FoundRealSize[j]>4) writeFloatToFiles(chrA, chrB, FoundRealSize[j], FoundRealSizeKind[j]); - } /* else { */ /* writeFloatToFiles(chrA, chrB, FoundRealSize[j]); */ /* } */ @@ -508,9 +505,7 @@ int main(void) } } if(flag == 0) /* No higher or lower one found, indicating an error */ - { return -1; - } } } |