summaryrefslogtreecommitdiffstats
path: root/fortran/src/H5match_types.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2014-02-20 21:29:26 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2014-02-20 21:29:26 (GMT)
commit1e36b5a348415501aa8eb992fd57c09d834900cd (patch)
tree9a423be6cbe38eed62268779703258972fb94191 /fortran/src/H5match_types.c
parentb30e37ea78a85c9a2e3abda7fddaabb636935b1c (diff)
downloadhdf5-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/src/H5match_types.c')
-rw-r--r--fortran/src/H5match_types.c47
1 files changed, 21 insertions, 26 deletions
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;
- }
}
}