diff options
Diffstat (limited to 'fortran/src/H5match_types.c')
-rw-r--r-- | fortran/src/H5match_types.c | 47 |
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; - } } } |