@@ -41,8 +41,6 @@ typedef size_t fortran_charlen_t;
4141typedef int fortran_charlen_t ;
4242#endif
4343
44- #define Splice (a , b ) a##b
45-
4644// Fortran strings are generally unterminated and the length is passed as an
4745// extra argument after all the normal arguments. Some compilers (I only know
4846// of Windows) place the length argument immediately after the string parameter
@@ -51,11 +49,13 @@ typedef int fortran_charlen_t;
5149// We can't just NULL-terminate the string in-place because that could overwrite
5250// other strings or attempt to write to read-only memory. This macro allocates
5351// a string to hold the null-terminated version of the string that C expects.
54- #define FIX_STRING (stringname ) \
55- char Splice(stringname, _c)[1024]; \
56- if (Splice(stringname, _len) > 1023) *err = CeedError(NULL, 1, "Fortran string length too long %zd", (size_t)Splice(stringname, _len)); \
57- strncpy(Splice(stringname, _c), stringname, Splice(stringname, _len)); \
58- Splice(stringname, _c)[Splice(stringname, _len)] = 0;
52+ #define CEED_MAX_FORTRAN_STRING_LEN 1024
53+ #define FIX_STRING (stringname ) \
54+ char stringname##_c[CEED_MAX_FORTRAN_STRING_LEN] = {'\0'}; \
55+ if (stringname##_len > CEED_MAX_FORTRAN_STRING_LEN - 1) { \
56+ *err = CeedError(NULL, 1, "Fortran string too long: %zd", (size_t)(stringname##_len)); \
57+ } \
58+ strncpy(stringname##_c, stringname, CeedIntMin(stringname##_len, CEED_MAX_FORTRAN_STRING_LEN - 1));
5959
6060// -----------------------------------------------------------------------------
6161// Ceed
0 commit comments